diff options
| author | Katalin Rebhan <me@dblsaiko.net> | 2025-02-17 18:25:40 +0100 |
|---|---|---|
| committer | Jussi Pakkanen <jussi.pakkanen@mailbox.org> | 2025-07-24 13:54:53 +0300 |
| commit | f34d2c3aa3047562f7ecb4174c5d513b9d6ebe74 (patch) | |
| tree | 05ed2151baa5b34863ceb0848cacc161e75e5169 /mesonbuild/backend | |
| parent | c07eb44c2b54025a98162e0ccd4c70c0f9b2d244 (diff) | |
| download | meson-f34d2c3aa3047562f7ecb4174c5d513b9d6ebe74.tar.gz | |
Add -parse-as-library to Swift library targets
Diffstat (limited to 'mesonbuild/backend')
| -rw-r--r-- | mesonbuild/backend/ninjabackend.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index ba75ce737..82411b0e6 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -2288,6 +2288,13 @@ class NinjaBackend(backends.Backend): compile_args += swiftc.get_cxx_interoperability_args(target.compilers) compile_args += self.build.get_project_args(swiftc, target.subproject, target.for_machine) compile_args += self.build.get_global_args(swiftc, target.for_machine) + if isinstance(target, (build.StaticLibrary, build.SharedLibrary)): + # swiftc treats modules with a single source file, and the main.swift file in multi-source file modules + # as top-level code. This is undesirable in library targets since it emits a main function. Add the + # -parse-as-library option as necessary to prevent emitting the main function while keeping files explicitly + # named main.swift treated as the entrypoint of the module in case this is desired. + if len(abssrc) == 1 and os.path.basename(abssrc[0]) != 'main.swift': + compile_args += swiftc.get_library_args() for i in reversed(target.get_include_dirs()): basedir = i.get_curdir() for d in i.get_incdirs(): |
