Skip to content

Commit 4175e29

Browse files
committed
Add modifications to support compiling on iOS.
1 parent 0d93515 commit 4175e29

File tree

7 files changed

+62
-12
lines changed

7 files changed

+62
-12
lines changed

docs/markdown/Dependencies.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -462,10 +462,11 @@ TODO
462462

463463
Supports the BLAS and LAPACK components of macOS Accelerate, also referred to
464464
as the vecLib framework. ILP64 support is only available on macOS 13.3 and up.
465-
From macOS 13.3, Accelerate ships with two different builds of 32-bit (LP64)
466-
BLAS and LAPACK. Meson will default to the newer of those builds, by defining
467-
`ACCELERATE_NEW_LAPACK`, unless `MACOS_DEPLOYMENT_TARGET` is set to a version
468-
lower than 13.3.
465+
From macOS 13.3 and iOS 16.4, Accelerate ships with two different builds of
466+
32-bit (LP64) BLAS and LAPACK. Meson will default to the newer of those builds,
467+
by defining `ACCELERATE_NEW_LAPACK`, unless `MACOS_DEPLOYMENT_TARGET` is set to
468+
a version lower than 13.3, or `IPHONEOS_DEPLOYMENT_TARGET` is set to a version
469+
lower than 16.4.
469470

470471
```meson
471472
accelerate_dep = dependency('accelerate',

mesonbuild/dependencies/blas_lapack.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,10 @@ def __init__(self, name: str, environment: 'Environment', kwargs: T.Dict[str, T.
738738
self.parse_modules(kwargs)
739739

740740
for_machine = MachineChoice.BUILD if kwargs.get('native', False) else MachineChoice.HOST
741-
if environment.machines[for_machine].is_darwin() and self.check_macOS_recent_enough():
741+
if (
742+
(environment.machines[for_machine].system == 'darwin' and self.check_macOS_recent_enough())
743+
or (environment.machines[for_machine].system == 'ios' and self.check_iOS_recent_enough())
744+
):
742745
self.detect(kwargs)
743746

744747
def check_macOS_recent_enough(self) -> bool:
@@ -752,6 +755,18 @@ def check_macOS_recent_enough(self) -> bool:
752755
sdk_version = subprocess.run(cmd, capture_output=True, check=True, text=True).stdout.strip()
753756
return mesonlib.version_compare(sdk_version, '>=13.3')
754757

758+
def check_iOS_recent_enough(self) -> bool:
759+
ios_version = platform.ios_ver().system
760+
deploy_target = os.environ.get('IPHONEOS_DEPLOYMENT_TARGET', ios_version)
761+
if not mesonlib.version_compare(deploy_target, '>=16.4'):
762+
return False
763+
764+
# We also need the SDK to be >=16.4
765+
sdk = "iphonesimulator" if platform.ios_ver().is_simulator else "iphoneos"
766+
cmd = ['xcrun', '-sdk', sdk, '--show-sdk-version']
767+
sdk_version = subprocess.run(cmd, capture_output=True, check=True, text=True).stdout.strip()
768+
return mesonlib.version_compare(sdk_version, '>=16.4')
769+
755770
def detect(self, kwargs: T.Dict[str, T.Any]) -> None:
756771
from .framework import ExtraFrameworkDependency
757772
dep = ExtraFrameworkDependency('Accelerate', self.env, kwargs)

mesonbuild/envconfig.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,9 @@ def is_linux(self) -> bool:
310310

311311
def is_darwin(self) -> bool:
312312
"""
313-
Machine is Darwin (iOS/tvOS/OS X)?
313+
Machine is a Darwin kernel (macOS/iOS/tvOS/watchOS)?
314314
"""
315-
return self.system in {'darwin', 'ios', 'tvos'}
315+
return self.system in {'darwin', 'ios', 'tvos', 'watchos'}
316316

317317
def is_android(self) -> bool:
318318
"""

mesonbuild/environment.py

+3
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,9 @@ def detect_cpu(compilers: CompilersDict) -> str:
447447
'linux': 'linux',
448448
'cygwin': 'nt',
449449
'darwin': 'xnu',
450+
'ios': 'xnu',
451+
'tvos': 'xnu',
452+
'watchos': 'xnu',
450453
'dragonfly': 'dragonfly',
451454
'haiku': 'haiku',
452455
}

mesonbuild/linkers/detect.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,10 @@ def guess_nix_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty
213213
elif 'xtools-' in o.split('\n', maxsplit=1)[0]:
214214
xtools = o.split(' ', maxsplit=1)[0]
215215
v = xtools.split('-', maxsplit=2)[1]
216-
linker = linkers.AppleDynamicLinker(compiler, for_machine, comp_class.LINKER_PREFIX, override, version=v)
216+
linker = linkers.AppleDynamicLinker(
217+
compiler, for_machine, comp_class.LINKER_PREFIX, override,
218+
system=env.machines[for_machine].system, version=v
219+
)
217220
# detect linker on MacOS - must be after other platforms because the
218221
# "(use -v to see invocation)" will match clang on other platforms,
219222
# but the rest of the checks will fail and call __failed_to_detect_linker.
@@ -232,7 +235,10 @@ def guess_nix_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty
232235
break
233236
else:
234237
__failed_to_detect_linker(compiler, check_args, o, e)
235-
linker = linkers.AppleDynamicLinker(compiler, for_machine, comp_class.LINKER_PREFIX, override, version=v)
238+
linker = linkers.AppleDynamicLinker(
239+
compiler, for_machine, comp_class.LINKER_PREFIX, override,
240+
system=env.machines[for_machine].system, version=v
241+
)
236242
else:
237243
__failed_to_detect_linker(compiler, check_args, o, e)
238244
return linker

mesonbuild/linkers/linkers.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,11 @@ def _apply_prefix(self, arg: T.Union[str, T.List[str]]) -> T.List[str]:
130130

131131
def __init__(self, exelist: T.List[str],
132132
for_machine: mesonlib.MachineChoice, prefix_arg: T.Union[str, T.List[str]],
133-
always_args: T.List[str], *, version: str = 'unknown version'):
133+
always_args: T.List[str], *, system: str = 'unknown system',
134+
version: str = 'unknown version'):
134135
self.exelist = exelist
135136
self.for_machine = for_machine
137+
self.system = system
136138
self.version = version
137139
self.prefix_arg = prefix_arg
138140
self.always_args = always_args
@@ -758,10 +760,18 @@ def get_asneeded_args(self) -> T.List[str]:
758760
return self._apply_prefix('-dead_strip_dylibs')
759761

760762
def get_allow_undefined_args(self) -> T.List[str]:
761-
return self._apply_prefix('-undefined,dynamic_lookup')
763+
# iOS doesn't allow undefined symbols when linking
764+
if self.system == 'ios':
765+
return []
766+
else:
767+
return self._apply_prefix('-undefined,dynamic_lookup')
762768

763769
def get_std_shared_module_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
764-
return ['-bundle'] + self._apply_prefix('-undefined,dynamic_lookup')
770+
# iOS requires modules to be linked as dynamic libraries.
771+
if self.system == 'ios':
772+
return ["-dynamiclib"]
773+
else:
774+
return ['-bundle'] + self._apply_prefix('-undefined,dynamic_lookup')
765775

766776
def get_pie_args(self) -> T.List[str]:
767777
return []

mesonbuild/utils/universal.py

+15
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,16 @@ class _VerPickleLoadable(Protocol):
118118
'is_freebsd',
119119
'is_haiku',
120120
'is_hurd',
121+
'is_ios',
121122
'is_irix',
122123
'is_linux',
123124
'is_netbsd',
124125
'is_openbsd',
125126
'is_osx',
126127
'is_qnx',
127128
'is_sunos',
129+
'is_tvos',
130+
'is_watchos',
128131
'is_windows',
129132
'is_wsl',
130133
'iter_regexin_iter',
@@ -629,6 +632,18 @@ def is_osx() -> bool:
629632
return platform.system().lower() == 'darwin'
630633

631634

635+
def is_ios() -> bool:
636+
return platform.system().lower() == 'ios'
637+
638+
639+
def is_tvos() -> bool:
640+
return platform.system().lower() == 'tvos'
641+
642+
643+
def is_watchos() -> bool:
644+
return platform.system().lower() == 'watchos'
645+
646+
632647
def is_linux() -> bool:
633648
return platform.system().lower() == 'linux'
634649

0 commit comments

Comments
 (0)