diff options
author | Angelos Mouzakitis <a.mouzakitis@virtualopensystems.com> | 2023-10-10 14:33:42 +0000 |
---|---|---|
committer | Angelos Mouzakitis <a.mouzakitis@virtualopensystems.com> | 2023-10-10 14:33:42 +0000 |
commit | af1a266670d040d2f4083ff309d732d648afba2a (patch) | |
tree | 2fc46203448ddcc6f81546d379abfaeb323575e9 /meson/test cases/swift | |
parent | e02cda008591317b1625707ff8e115a4841aa889 (diff) |
Change-Id: Iaf8d18082d3991dec7c0ebbea540f092188eb4ec
Diffstat (limited to 'meson/test cases/swift')
31 files changed, 139 insertions, 0 deletions
diff --git a/meson/test cases/swift/1 exe/main.swift b/meson/test cases/swift/1 exe/main.swift new file mode 100644 index 000000000..1b489de72 --- /dev/null +++ b/meson/test cases/swift/1 exe/main.swift @@ -0,0 +1 @@ +print("Swift executable is working.") diff --git a/meson/test cases/swift/1 exe/meson.build b/meson/test cases/swift/1 exe/meson.build new file mode 100644 index 000000000..4436a8ed4 --- /dev/null +++ b/meson/test cases/swift/1 exe/meson.build @@ -0,0 +1,3 @@ +project('swift exe', 'swift') + +test('swifttest', executable('swifttest', 'main.swift')) diff --git a/meson/test cases/swift/2 multifile/libfile.swift b/meson/test cases/swift/2 multifile/libfile.swift new file mode 100644 index 000000000..45f941ca7 --- /dev/null +++ b/meson/test cases/swift/2 multifile/libfile.swift @@ -0,0 +1,3 @@ +func printSomething(text: String) { + print("Got this: \(text)") +} diff --git a/meson/test cases/swift/2 multifile/main.swift b/meson/test cases/swift/2 multifile/main.swift new file mode 100644 index 000000000..9867e850e --- /dev/null +++ b/meson/test cases/swift/2 multifile/main.swift @@ -0,0 +1,5 @@ +#if swift(>=3.0) +printSomething(text:"String from main") +#else +printSomething("String from main") +#endif diff --git a/meson/test cases/swift/2 multifile/meson.build b/meson/test cases/swift/2 multifile/meson.build new file mode 100644 index 000000000..9012f3d41 --- /dev/null +++ b/meson/test cases/swift/2 multifile/meson.build @@ -0,0 +1,3 @@ +project('2 files', 'swift') + +test('2files', executable('twofiles', 'main.swift', 'libfile.swift')) diff --git a/meson/test cases/swift/3 library/exe/main.swift b/meson/test cases/swift/3 library/exe/main.swift new file mode 100644 index 000000000..c5de3739b --- /dev/null +++ b/meson/test cases/swift/3 library/exe/main.swift @@ -0,0 +1,7 @@ +import DataSource + +let data = getData() +let data2 = getOther() + +print("String from module: \(data)") +print("Other string: \(data2)") diff --git a/meson/test cases/swift/3 library/exe/meson.build b/meson/test cases/swift/3 library/exe/meson.build new file mode 100644 index 000000000..6c13957e5 --- /dev/null +++ b/meson/test cases/swift/3 library/exe/meson.build @@ -0,0 +1,2 @@ +exe = executable('dataprog', 'main.swift', link_with : datasource) +test('dataprog', exe) diff --git a/meson/test cases/swift/3 library/lib/datasource.swift b/meson/test cases/swift/3 library/lib/datasource.swift new file mode 100644 index 000000000..4ac7c2ab8 --- /dev/null +++ b/meson/test cases/swift/3 library/lib/datasource.swift @@ -0,0 +1,3 @@ +public func getData() -> String { + return "String from module." +} diff --git a/meson/test cases/swift/3 library/lib/meson.build b/meson/test cases/swift/3 library/lib/meson.build new file mode 100644 index 000000000..fc65556d8 --- /dev/null +++ b/meson/test cases/swift/3 library/lib/meson.build @@ -0,0 +1 @@ +datasource = static_library('DataSource', 'datasource.swift', 'othersource.swift') diff --git a/meson/test cases/swift/3 library/lib/othersource.swift b/meson/test cases/swift/3 library/lib/othersource.swift new file mode 100644 index 000000000..fb668baa5 --- /dev/null +++ b/meson/test cases/swift/3 library/lib/othersource.swift @@ -0,0 +1,3 @@ +public func getOther() -> String { + return "String from other source." +} diff --git a/meson/test cases/swift/3 library/meson.build b/meson/test cases/swift/3 library/meson.build new file mode 100644 index 000000000..d601721f0 --- /dev/null +++ b/meson/test cases/swift/3 library/meson.build @@ -0,0 +1,4 @@ +project('linking', 'swift') + +subdir('lib') +subdir('exe') diff --git a/meson/test cases/swift/4 generate/gen/main.swift b/meson/test cases/swift/4 generate/gen/main.swift new file mode 100644 index 000000000..03acdbb08 --- /dev/null +++ b/meson/test cases/swift/4 generate/gen/main.swift @@ -0,0 +1,18 @@ +#if os(OSX) + import Darwin +#else + import Glibc +#endif + +#if swift(>=3.0) +let fname = CommandLine.arguments[1] +#else +let fname = Process.arguments[1] +#endif +let code = "public func getGenerated() -> Int {\n return 42\n}\n" + +let f = fopen(fname, "w") + +fwrite(code, 1, Int(strlen(code)), f) +print("Name: \(fname)") +fclose(f) diff --git a/meson/test cases/swift/4 generate/gen/meson.build b/meson/test cases/swift/4 generate/gen/meson.build new file mode 100644 index 000000000..8cd7e0463 --- /dev/null +++ b/meson/test cases/swift/4 generate/gen/meson.build @@ -0,0 +1,6 @@ +gen = executable('gen', 'main.swift') + +srcs = custom_target('gensrc', + output : 'gen.swift', + command : [gen, '@OUTPUT@'] +) diff --git a/meson/test cases/swift/4 generate/meson.build b/meson/test cases/swift/4 generate/meson.build new file mode 100644 index 000000000..ccc7d5c82 --- /dev/null +++ b/meson/test cases/swift/4 generate/meson.build @@ -0,0 +1,4 @@ +project('swift generator', 'swift') + +subdir('gen') +subdir('user') diff --git a/meson/test cases/swift/4 generate/user/main.swift b/meson/test cases/swift/4 generate/user/main.swift new file mode 100644 index 000000000..e6b46cd19 --- /dev/null +++ b/meson/test cases/swift/4 generate/user/main.swift @@ -0,0 +1,3 @@ +let generated = getGenerated() + +print("Generated number is: \(generated).") diff --git a/meson/test cases/swift/4 generate/user/meson.build b/meson/test cases/swift/4 generate/user/meson.build new file mode 100644 index 000000000..fc4722d4c --- /dev/null +++ b/meson/test cases/swift/4 generate/user/meson.build @@ -0,0 +1,2 @@ +user = executable('user', 'main.swift', srcs) +test('User test', user) diff --git a/meson/test cases/swift/5 mixed/main.swift b/meson/test cases/swift/5 mixed/main.swift new file mode 100644 index 000000000..557412687 --- /dev/null +++ b/meson/test cases/swift/5 mixed/main.swift @@ -0,0 +1,3 @@ +let num = getNumber() + +print("The number returned from C code is: \(num).") diff --git a/meson/test cases/swift/5 mixed/meson.build b/meson/test cases/swift/5 mixed/meson.build new file mode 100644 index 000000000..71cb99d52 --- /dev/null +++ b/meson/test cases/swift/5 mixed/meson.build @@ -0,0 +1,6 @@ +project('mixed', 'c', 'swift') + +lib = static_library('mylib', 'mylib.c') +exe = executable('prog', 'main.swift', 'mylib.h', + link_with : lib) +test('c interface', exe) diff --git a/meson/test cases/swift/5 mixed/mylib.c b/meson/test cases/swift/5 mixed/mylib.c new file mode 100644 index 000000000..e091836bc --- /dev/null +++ b/meson/test cases/swift/5 mixed/mylib.c @@ -0,0 +1,5 @@ +#include"mylib.h" + +int getNumber() { + return 42; +} diff --git a/meson/test cases/swift/5 mixed/mylib.h b/meson/test cases/swift/5 mixed/mylib.h new file mode 100644 index 000000000..21bd9eb0b --- /dev/null +++ b/meson/test cases/swift/5 mixed/mylib.h @@ -0,0 +1,3 @@ +#pragma once + +int getNumber(); diff --git a/meson/test cases/swift/6 modulemap/main.swift b/meson/test cases/swift/6 modulemap/main.swift new file mode 100644 index 000000000..1a38c2596 --- /dev/null +++ b/meson/test cases/swift/6 modulemap/main.swift @@ -0,0 +1,5 @@ +import mylib + +let num = getNumber() + +print("The number returned from C code is: \(num).") diff --git a/meson/test cases/swift/6 modulemap/meson.build b/meson/test cases/swift/6 modulemap/meson.build new file mode 100644 index 000000000..f1c90db97 --- /dev/null +++ b/meson/test cases/swift/6 modulemap/meson.build @@ -0,0 +1,8 @@ +project('mixed', 'c', 'swift') + +i = include_directories('.') +lib = static_library('mylib', 'mylib.c') +exe = executable('prog', 'main.swift', + include_directories : [i], + link_with : lib) +test('c module', exe) diff --git a/meson/test cases/swift/6 modulemap/module.modulemap b/meson/test cases/swift/6 modulemap/module.modulemap new file mode 100644 index 000000000..5aab62e97 --- /dev/null +++ b/meson/test cases/swift/6 modulemap/module.modulemap @@ -0,0 +1,5 @@ +module mylib [extern_c] { + header "mylib.h" + link "mylib" + export * +} diff --git a/meson/test cases/swift/6 modulemap/mylib.c b/meson/test cases/swift/6 modulemap/mylib.c new file mode 100644 index 000000000..e091836bc --- /dev/null +++ b/meson/test cases/swift/6 modulemap/mylib.c @@ -0,0 +1,5 @@ +#include"mylib.h" + +int getNumber() { + return 42; +} diff --git a/meson/test cases/swift/6 modulemap/mylib.h b/meson/test cases/swift/6 modulemap/mylib.h new file mode 100644 index 000000000..21bd9eb0b --- /dev/null +++ b/meson/test cases/swift/6 modulemap/mylib.h @@ -0,0 +1,3 @@ +#pragma once + +int getNumber(); diff --git a/meson/test cases/swift/7 modulemap subdir/main.swift b/meson/test cases/swift/7 modulemap subdir/main.swift new file mode 100644 index 000000000..1a38c2596 --- /dev/null +++ b/meson/test cases/swift/7 modulemap subdir/main.swift @@ -0,0 +1,5 @@ +import mylib + +let num = getNumber() + +print("The number returned from C code is: \(num).") diff --git a/meson/test cases/swift/7 modulemap subdir/meson.build b/meson/test cases/swift/7 modulemap subdir/meson.build new file mode 100644 index 000000000..cd769eb97 --- /dev/null +++ b/meson/test cases/swift/7 modulemap subdir/meson.build @@ -0,0 +1,6 @@ +project('mixed', 'c', 'swift') +add_project_arguments('-embed-bitcode', language : 'swift') +subdir('mylib') +exe = executable('prog', 'main.swift', + dependencies : dep) +test('c module', exe) diff --git a/meson/test cases/swift/7 modulemap subdir/mylib/meson.build b/meson/test cases/swift/7 modulemap subdir/mylib/meson.build new file mode 100644 index 000000000..2549e2b4d --- /dev/null +++ b/meson/test cases/swift/7 modulemap subdir/mylib/meson.build @@ -0,0 +1,4 @@ + +i = include_directories('.') +lib = static_library('mylib', 'mylib.c') +dep = declare_dependency(include_directories : i, link_with : lib) diff --git a/meson/test cases/swift/7 modulemap subdir/mylib/module.modulemap b/meson/test cases/swift/7 modulemap subdir/mylib/module.modulemap new file mode 100644 index 000000000..5aab62e97 --- /dev/null +++ b/meson/test cases/swift/7 modulemap subdir/mylib/module.modulemap @@ -0,0 +1,5 @@ +module mylib [extern_c] { + header "mylib.h" + link "mylib" + export * +} diff --git a/meson/test cases/swift/7 modulemap subdir/mylib/mylib.c b/meson/test cases/swift/7 modulemap subdir/mylib/mylib.c new file mode 100644 index 000000000..e091836bc --- /dev/null +++ b/meson/test cases/swift/7 modulemap subdir/mylib/mylib.c @@ -0,0 +1,5 @@ +#include"mylib.h" + +int getNumber() { + return 42; +} diff --git a/meson/test cases/swift/7 modulemap subdir/mylib/mylib.h b/meson/test cases/swift/7 modulemap subdir/mylib/mylib.h new file mode 100644 index 000000000..21bd9eb0b --- /dev/null +++ b/meson/test cases/swift/7 modulemap subdir/mylib/mylib.h @@ -0,0 +1,3 @@ +#pragma once + +int getNumber(); |