From f30542ed428f87b9e593c5810ad867bae457cbb2 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sat, 24 Apr 2021 20:35:33 +0300 Subject: Xcode: make Swift projects work. --- mesonbuild/backend/backends.py | 6 ++++++ mesonbuild/backend/ninjabackend.py | 6 ------ mesonbuild/backend/xcodebackend.py | 9 ++++++++- test cases/swift/1 exe/main.swift | 1 + test cases/swift/1 exe/meson.build | 2 +- test cases/swift/1 exe/prog.swift | 1 - 6 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 test cases/swift/1 exe/main.swift delete mode 100644 test cases/swift/1 exe/prog.swift diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index 734a7e4..e6628b6 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -417,6 +417,12 @@ class Backend: raise MesonException('Unknown data type in object list.') return obj_list + def is_swift_target(self, target): + for s in target.sources: + if s.endswith('swift'): + return True + return False + def get_executable_serialisation(self, cmd, workdir=None, extra_bdeps=None, capture=None, env: T.Optional[build.EnvironmentVariables] = None): diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index e8a7d4b..fa07235 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -1701,12 +1701,6 @@ int dummy; def target_swift_modulename(self, target): return target.name - def is_swift_target(self, target): - for s in target.sources: - if s.endswith('swift'): - return True - return False - def determine_swift_dep_modules(self, target): result = [] for l in target.link_targets: diff --git a/mesonbuild/backend/xcodebackend.py b/mesonbuild/backend/xcodebackend.py index 6fc4729..aeaee5c 100644 --- a/mesonbuild/backend/xcodebackend.py +++ b/mesonbuild/backend/xcodebackend.py @@ -37,6 +37,7 @@ XCODETYPEMAP = {'c': 'sourcecode.c.c', 'hxx': 'sourcecode.cpp.h', 'hh': 'sourcecode.cpp.hh', 'inc': 'sourcecode.c.h', + 'swift': 'sourcecode.swift', 'dylib': 'compiled.mach-o.dylib', 'o': 'compiled.mach-o.objfile', 's': 'sourcecode.asm', @@ -1277,6 +1278,7 @@ class XCodeBackend(backends.Backend): bt_dict.add_item('buildSettings', settings_dict) settings_dict.add_item('ARCHS', '"$(NATIVE_ARCH_ACTUAL)"') settings_dict.add_item('ONLY_ACTIVE_ARCH', 'YES') + settings_dict.add_item('SWIFT_VERSION', '4.0') settings_dict.add_item('SDKROOT', '"macosx"') settings_dict.add_item('SYMROOT', '"%s/build"' % self.environment.get_build_dir()) bt_dict.add_item('name', f'"{buildtype}"') @@ -1382,7 +1384,12 @@ class XCodeBackend(backends.Backend): else: product_name = target.get_basename() ldargs += target.link_args - linker, stdlib_args = self.determine_linker_and_stdlib_args(target) + # Swift is special. Again. You can't mix Swift with other languages + # in the same target. Thus for Swift we only use + if self.is_swift_target(target): + linker, stdlib_args = target.compilers['swift'], [] + else: + linker, stdlib_args = self.determine_linker_and_stdlib_args(target) if not isinstance(target, build.StaticLibrary): ldargs += self.build.get_project_link_args(linker, target.subproject, target.for_machine) ldargs += self.build.get_global_link_args(linker, target.for_machine) diff --git a/test cases/swift/1 exe/main.swift b/test cases/swift/1 exe/main.swift new file mode 100644 index 0000000..1b489de --- /dev/null +++ b/test cases/swift/1 exe/main.swift @@ -0,0 +1 @@ +print("Swift executable is working.") diff --git a/test cases/swift/1 exe/meson.build b/test cases/swift/1 exe/meson.build index f986e9a..4436a8e 100644 --- a/test cases/swift/1 exe/meson.build +++ b/test cases/swift/1 exe/meson.build @@ -1,3 +1,3 @@ project('swift exe', 'swift') -test('swifttest', executable('swifttest', 'prog.swift')) +test('swifttest', executable('swifttest', 'main.swift')) diff --git a/test cases/swift/1 exe/prog.swift b/test cases/swift/1 exe/prog.swift deleted file mode 100644 index 1b489de..0000000 --- a/test cases/swift/1 exe/prog.swift +++ /dev/null @@ -1 +0,0 @@ -print("Swift executable is working.") -- cgit v1.1