From 8cd8c3aaef236a6797e54d3eea279f242bb2016a Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Tue, 15 Apr 2025 10:18:42 +0200 Subject: [PATCH 1/3] environment: handle all iOS variants as xnu All of iOS, tvOS, visionOS, watchOS use the XNU kernel. Report that and also make them return true for is_darwin() which is really more like "is_xnu()". Co-authored-by: Russell Keith-Magee Signed-off-by: Paolo Bonzini --- docs/markdown/Reference-tables.md | 2 ++ mesonbuild/envconfig.py | 4 ++-- mesonbuild/environment.py | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/markdown/Reference-tables.md b/docs/markdown/Reference-tables.md index 1c5f9a33a4f3..a5d27858e473 100644 --- a/docs/markdown/Reference-tables.md +++ b/docs/markdown/Reference-tables.md @@ -208,6 +208,8 @@ Meson natively. | ios-simulator | | | tvos | Apple tvOS | | tvos-simulator | | +| visionos | Apple visionOS | +| visionos-simulator | | | watchos | Apple watchOS | | watchos-simulator | | diff --git a/mesonbuild/envconfig.py b/mesonbuild/envconfig.py index c877a7c5a78e..43fad0cd2ac4 100644 --- a/mesonbuild/envconfig.py +++ b/mesonbuild/envconfig.py @@ -320,9 +320,9 @@ def is_linux(self) -> bool: def is_darwin(self) -> bool: """ - Machine is Darwin (iOS/tvOS/OS X)? + Machine is Darwin (macOS/iOS/tvOS/visionOS/watchOS)? """ - return self.system in {'darwin', 'ios', 'tvos'} + return self.system in {'darwin', 'ios', 'tvos', 'visionos', 'watchos'} def is_android(self) -> bool: """ diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index a0d98ae581ae..f322cda95cc9 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -487,6 +487,10 @@ def detect_cpu(compilers: CompilersDict) -> str: 'linux': 'linux', 'cygwin': 'nt', 'darwin': 'xnu', + 'ios': 'xnu', + 'tvos': 'xnu', + 'visionos': 'xnu', + 'watchos': 'xnu', 'dragonfly': 'dragonfly', 'haiku': 'haiku', 'gnu': 'gnu', From 4926b0b9ac0f539dcfa4b8f89063e062f9f30037 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Tue, 15 Apr 2025 10:27:20 +0200 Subject: [PATCH 2/3] linkers: pass system to DynamicLinker.__init__ for Darwin linkers Apple linkers need to use different arguments on macOS and iOS-like platforms. Pass the system to the constructor so that it can be examined. Co-authored-by: Russell Keith-Magee Signed-off-by: Paolo Bonzini --- mesonbuild/compilers/detect.py | 4 ++-- mesonbuild/linkers/detect.py | 13 ++++++++++--- mesonbuild/linkers/linkers.py | 4 +++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/mesonbuild/compilers/detect.py b/mesonbuild/compilers/detect.py index 9dab06a85a63..53bdd85131d9 100644 --- a/mesonbuild/compilers/detect.py +++ b/mesonbuild/compilers/detect.py @@ -1122,8 +1122,8 @@ def detect_rust_compiler(env: 'Environment', for_machine: MachineChoice) -> Rust version=cc.linker.version, **extra_args) # type: ignore else: linker = type(cc.linker)(compiler, for_machine, cc.LINKER_PREFIX, - always_args=always_args, version=cc.linker.version, - **extra_args) + always_args=always_args, system=cc.linker.system, + version=cc.linker.version, **extra_args) elif 'link' in override[0]: linker = guess_win_linker(env, override, cls, version, for_machine, use_linker_prefix=False) diff --git a/mesonbuild/linkers/detect.py b/mesonbuild/linkers/detect.py index 493430a87cee..ee9bb0861e4f 100644 --- a/mesonbuild/linkers/detect.py +++ b/mesonbuild/linkers/detect.py @@ -131,6 +131,7 @@ def guess_nix_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty env.coredata.add_lang_args(comp_class.language, comp_class, for_machine, env) extra_args = extra_args or [] + system = env.machines[for_machine].system ldflags = env.coredata.get_external_link_args(for_machine, comp_class.language) extra_args += comp_class._unix_args_to_native(ldflags, env.machines[for_machine]) @@ -164,7 +165,7 @@ def guess_nix_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty lld_cls = linkers.LLVMDynamicLinker linker = lld_cls( - compiler, for_machine, comp_class.LINKER_PREFIX, override, version=v) + compiler, for_machine, comp_class.LINKER_PREFIX, override, system=system, version=v) elif 'Snapdragon' in e and 'LLVM' in e: linker = linkers.QualcommLLVMDynamicLinker( compiler, for_machine, comp_class.LINKER_PREFIX, override, version=v) @@ -222,7 +223,10 @@ def guess_nix_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty elif 'xtools-' in o.split('\n', maxsplit=1)[0]: xtools = o.split(' ', maxsplit=1)[0] v = xtools.split('-', maxsplit=2)[1] - linker = linkers.AppleDynamicLinker(compiler, for_machine, comp_class.LINKER_PREFIX, override, version=v) + linker = linkers.AppleDynamicLinker( + compiler, for_machine, comp_class.LINKER_PREFIX, override, + system=system, version=v + ) # detect linker on MacOS - must be after other platforms because the # "(use -v to see invocation)" will match clang on other platforms, # but the rest of the checks will fail and call __failed_to_detect_linker. @@ -241,7 +245,10 @@ def guess_nix_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty break else: __failed_to_detect_linker(compiler, check_args, o, e) - linker = linkers.AppleDynamicLinker(compiler, for_machine, comp_class.LINKER_PREFIX, override, version=v) + linker = linkers.AppleDynamicLinker( + compiler, for_machine, comp_class.LINKER_PREFIX, override, + system=system, version=v + ) else: __failed_to_detect_linker(compiler, check_args, o, e) return linker diff --git a/mesonbuild/linkers/linkers.py b/mesonbuild/linkers/linkers.py index e74ff708d045..47a76198e159 100644 --- a/mesonbuild/linkers/linkers.py +++ b/mesonbuild/linkers/linkers.py @@ -141,9 +141,11 @@ def _apply_prefix(self, arg: T.Union[str, T.List[str]]) -> T.List[str]: def __init__(self, exelist: T.List[str], for_machine: mesonlib.MachineChoice, prefix_arg: T.Union[str, T.List[str]], - always_args: T.List[str], *, version: str = 'unknown version'): + always_args: T.List[str], *, system: str = 'unknown system', + version: str = 'unknown version'): self.exelist = exelist self.for_machine = for_machine + self.system = system self.version = version self.prefix_arg = prefix_arg self.always_args = always_args From 79955ec11a3b65f205ef68b3df67956e767a0ba6 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Tue, 15 Apr 2025 10:32:37 +0200 Subject: [PATCH 3/3] linkers: apple: fix shared module args iOS should not use -undefined,dynamic_lookup; whereas macOS should revert from -dynamiclib to -bundle, as was the case before commit cfb5a48e0 ("linkers: darwin: do not use -bundle for shared_modules", 2025-03-24), because Postgres wants to use -bundle_loader and that is only possible together with -bundle. Co-authored-by: Russell Keith-Magee Signed-off-by: Paolo Bonzini --- mesonbuild/linkers/linkers.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mesonbuild/linkers/linkers.py b/mesonbuild/linkers/linkers.py index 47a76198e159..617d4ad3cf87 100644 --- a/mesonbuild/linkers/linkers.py +++ b/mesonbuild/linkers/linkers.py @@ -811,10 +811,17 @@ def get_asneeded_args(self) -> T.List[str]: return self._apply_prefix('-dead_strip_dylibs') def get_allow_undefined_args(self) -> T.List[str]: - return self._apply_prefix('-undefined,dynamic_lookup') + # iOS doesn't allow undefined symbols when linking + if self.system == 'ios': + return [] + else: + return self._apply_prefix('-undefined,dynamic_lookup') def get_std_shared_module_args(self, target: 'BuildTarget') -> T.List[str]: - return ['-dynamiclib'] + self._apply_prefix('-undefined,dynamic_lookup') + if self.system == 'ios': + return ['-dynamiclib'] + else: + return ['-bundle'] + self.get_allow_undefined_args() def get_pie_args(self) -> T.List[str]: return []