Skip to content

Improve support for iOS targets (v2) #14481

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/markdown/Reference-tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ Meson natively.
| ios-simulator | |
| tvos | Apple tvOS |
| tvos-simulator | |
| visionos | Apple visionOS |
| visionos-simulator | |
| watchos | Apple watchOS |
| watchos-simulator | |

Expand Down
4 changes: 2 additions & 2 deletions mesonbuild/compilers/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions mesonbuild/envconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
4 changes: 4 additions & 0 deletions mesonbuild/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
13 changes: 10 additions & 3 deletions mesonbuild/linkers/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand All @@ -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
15 changes: 12 additions & 3 deletions mesonbuild/linkers/linkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -809,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 []
Expand Down
Loading