Skip to content

Commit 725c1a2

Browse files
committed
Improve support for iOS targets.
1 parent 19482e4 commit 725c1a2

File tree

6 files changed

+42
-8
lines changed

6 files changed

+42
-8
lines changed

mesonbuild/compilers/detect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ def detect_rust_compiler(env: 'Environment', for_machine: MachineChoice) -> Rust
11231123
else:
11241124
linker = type(cc.linker)(compiler, for_machine, cc.LINKER_PREFIX,
11251125
always_args=always_args, version=cc.linker.version,
1126-
**extra_args)
1126+
**extra_args) # type: ignore
11271127
elif 'link' in override[0]:
11281128
linker = guess_win_linker(env,
11291129
override, cls, version, for_machine, use_linker_prefix=False)

mesonbuild/envconfig.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,9 @@ def is_linux(self) -> bool:
320320

321321
def is_darwin(self) -> bool:
322322
"""
323-
Machine is Darwin (iOS/tvOS/OS X)?
323+
Machine is a Darwin kernel (macOS/iOS/tvOS/watchOS)?
324324
"""
325-
return self.system in {'darwin', 'ios', 'tvos'}
325+
return self.system in {'darwin', 'ios', 'tvos', 'watchos'}
326326

327327
def is_android(self) -> bool:
328328
"""

mesonbuild/environment.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,9 @@ def detect_cpu(compilers: CompilersDict) -> str:
487487
'linux': 'linux',
488488
'cygwin': 'nt',
489489
'darwin': 'xnu',
490+
'ios': 'xnu',
491+
'tvos': 'xnu',
492+
'watchos': 'xnu',
490493
'dragonfly': 'dragonfly',
491494
'haiku': 'haiku',
492495
'gnu': 'gnu',

mesonbuild/linkers/detect.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,10 @@ def guess_nix_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty
222222
elif 'xtools-' in o.split('\n', maxsplit=1)[0]:
223223
xtools = o.split(' ', maxsplit=1)[0]
224224
v = xtools.split('-', maxsplit=2)[1]
225-
linker = linkers.AppleDynamicLinker(compiler, for_machine, comp_class.LINKER_PREFIX, override, version=v)
225+
linker = linkers.AppleDynamicLinker(
226+
compiler, for_machine, comp_class.LINKER_PREFIX, override,
227+
system=env.machines[for_machine].system, version=v
228+
)
226229
# detect linker on MacOS - must be after other platforms because the
227230
# "(use -v to see invocation)" will match clang on other platforms,
228231
# but the rest of the checks will fail and call __failed_to_detect_linker.
@@ -241,7 +244,10 @@ def guess_nix_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty
241244
break
242245
else:
243246
__failed_to_detect_linker(compiler, check_args, o, e)
244-
linker = linkers.AppleDynamicLinker(compiler, for_machine, comp_class.LINKER_PREFIX, override, version=v)
247+
linker = linkers.AppleDynamicLinker(
248+
compiler, for_machine, comp_class.LINKER_PREFIX, override,
249+
system=env.machines[for_machine].system, version=v
250+
)
245251
else:
246252
__failed_to_detect_linker(compiler, check_args, o, e)
247253
return linker

mesonbuild/linkers/linkers.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,11 @@ def _apply_prefix(self, arg: T.Union[str, T.List[str]]) -> T.List[str]:
138138

139139
def __init__(self, exelist: T.List[str],
140140
for_machine: mesonlib.MachineChoice, prefix_arg: T.Union[str, T.List[str]],
141-
always_args: T.List[str], *, version: str = 'unknown version'):
141+
always_args: T.List[str], *, system: str = 'unknown system',
142+
version: str = 'unknown version'):
142143
self.exelist = exelist
143144
self.for_machine = for_machine
145+
self.system = system
144146
self.version = version
145147
self.prefix_arg = prefix_arg
146148
self.always_args = always_args
@@ -803,10 +805,18 @@ def get_asneeded_args(self) -> T.List[str]:
803805
return self._apply_prefix('-dead_strip_dylibs')
804806

805807
def get_allow_undefined_args(self) -> T.List[str]:
806-
return self._apply_prefix('-undefined,dynamic_lookup')
808+
# iOS doesn't allow undefined symbols when linking
809+
if self.system == 'ios':
810+
return []
811+
else:
812+
return self._apply_prefix('-undefined,dynamic_lookup')
807813

808814
def get_std_shared_module_args(self, target: 'BuildTarget') -> T.List[str]:
809-
return ['-dynamiclib'] + self._apply_prefix('-undefined,dynamic_lookup')
815+
# iOS requires modules to be linked as dynamic libraries.
816+
if self.system == 'ios':
817+
return ["-dynamiclib"]
818+
else:
819+
return ['-bundle'] + self._apply_prefix('-undefined,dynamic_lookup')
810820

811821
def get_pie_args(self) -> T.List[str]:
812822
return []

mesonbuild/utils/universal.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ class _VerPickleLoadable(Protocol):
119119
'is_freebsd',
120120
'is_haiku',
121121
'is_hurd',
122+
'is_ios',
122123
'is_irix',
123124
'is_linux',
124125
'is_netbsd',
@@ -127,6 +128,8 @@ class _VerPickleLoadable(Protocol):
127128
'is_parent_path',
128129
'is_qnx',
129130
'is_sunos',
131+
'is_tvos',
132+
'is_watchos',
130133
'is_windows',
131134
'is_wsl',
132135
'iter_regexin_iter',
@@ -625,6 +628,18 @@ def is_osx() -> bool:
625628
return platform.system().lower() == 'darwin'
626629

627630

631+
def is_ios() -> bool:
632+
return platform.system().lower() == 'ios'
633+
634+
635+
def is_tvos() -> bool:
636+
return platform.system().lower() == 'tvos'
637+
638+
639+
def is_watchos() -> bool:
640+
return platform.system().lower() == 'watchos'
641+
642+
628643
def is_linux() -> bool:
629644
return platform.system().lower() == 'linux'
630645

0 commit comments

Comments
 (0)