Skip to content

Commit 23ec306

Browse files
authored
Merge pull request #19 from freakboy3742/numpy-ios-support
Add modifications to support compiling on iOS.
2 parents 0821347 + 6fa5876 commit 23ec306

File tree

8 files changed

+57
-18
lines changed

8 files changed

+57
-18
lines changed

docs/markdown/Dependencies.md

Lines changed: 5 additions & 4 deletions
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',

docs/markdown/Reference-tables.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ Meson natively.
205205
| ios-simulator | |
206206
| tvos | Apple tvOS |
207207
| tvos-simulator | |
208+
| visionos | Apple visionOS |
209+
| visionos-simulator | |
208210
| watchos | Apple watchOS |
209211
| watchos-simulator | |
210212

mesonbuild/compilers/detect.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,8 +1089,8 @@ def detect_rust_compiler(env: 'Environment', for_machine: MachineChoice) -> Rust
10891089
version=cc.linker.version, **extra_args) # type: ignore
10901090
else:
10911091
linker = type(cc.linker)(compiler, for_machine, cc.LINKER_PREFIX,
1092-
always_args=always_args, version=cc.linker.version,
1093-
**extra_args)
1092+
always_args=always_args, system=cc.linker.system,
1093+
version=cc.linker.version, **extra_args)
10941094
elif 'link' in override[0]:
10951095
linker = guess_win_linker(env,
10961096
override, cls, version, for_machine, use_linker_prefix=False)

mesonbuild/dependencies/blas_lapack.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,10 @@ def __init__(self, name: str, environment: 'Environment', kwargs: T.Dict[str, T.
739739
self.parse_modules(kwargs)
740740

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

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

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

mesonbuild/envconfig.py

Lines changed: 2 additions & 2 deletions
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 Darwin (macOS/iOS/tvOS/visionOS/watchOS)?
314314
"""
315-
return self.system in {'darwin', 'ios', 'tvos'}
315+
return self.system in {'darwin', 'ios', 'tvos', 'visionos', 'watchos'}
316316

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

mesonbuild/environment.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,10 @@ def detect_cpu(compilers: CompilersDict) -> str:
474474
'linux': 'linux',
475475
'cygwin': 'nt',
476476
'darwin': 'xnu',
477+
'ios': 'xnu',
478+
'tvos': 'xnu',
479+
'visionos': 'xnu',
480+
'watchos': 'xnu',
477481
'dragonfly': 'dragonfly',
478482
'haiku': 'haiku',
479483
'gnu': 'gnu',

mesonbuild/linkers/detect.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ def guess_nix_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty
131131
env.coredata.add_lang_args(comp_class.language, comp_class, for_machine, env)
132132
extra_args = extra_args or []
133133

134+
system = env.machines[for_machine].system
134135
ldflags = env.coredata.get_external_link_args(for_machine, comp_class.language)
135136
extra_args += comp_class._unix_args_to_native(ldflags, env.machines[for_machine])
136137

@@ -164,7 +165,7 @@ def guess_nix_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty
164165
lld_cls = linkers.LLVMDynamicLinker
165166

166167
linker = lld_cls(
167-
compiler, for_machine, comp_class.LINKER_PREFIX, override, version=v)
168+
compiler, for_machine, comp_class.LINKER_PREFIX, override, system=system, version=v)
168169
elif 'Snapdragon' in e and 'LLVM' in e:
169170
linker = linkers.QualcommLLVMDynamicLinker(
170171
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
222223
elif 'xtools-' in o.split('\n', maxsplit=1)[0]:
223224
xtools = o.split(' ', maxsplit=1)[0]
224225
v = xtools.split('-', maxsplit=2)[1]
225-
linker = linkers.AppleDynamicLinker(compiler, for_machine, comp_class.LINKER_PREFIX, override, version=v)
226+
linker = linkers.AppleDynamicLinker(
227+
compiler, for_machine, comp_class.LINKER_PREFIX, override,
228+
system=system, version=v
229+
)
226230
# detect linker on MacOS - must be after other platforms because the
227231
# "(use -v to see invocation)" will match clang on other platforms,
228232
# 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
241245
break
242246
else:
243247
__failed_to_detect_linker(compiler, check_args, o, e)
244-
linker = linkers.AppleDynamicLinker(compiler, for_machine, comp_class.LINKER_PREFIX, override, version=v)
248+
linker = linkers.AppleDynamicLinker(
249+
compiler, for_machine, comp_class.LINKER_PREFIX, override,
250+
system=system, version=v
251+
)
245252
else:
246253
__failed_to_detect_linker(compiler, check_args, o, e)
247254
return linker

mesonbuild/linkers/linkers.py

Lines changed: 16 additions & 6 deletions
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
@@ -763,10 +765,17 @@ def get_asneeded_args(self) -> T.List[str]:
763765
return self._apply_prefix('-dead_strip_dylibs')
764766

765767
def get_allow_undefined_args(self) -> T.List[str]:
766-
return self._apply_prefix('-undefined,dynamic_lookup')
768+
# iOS doesn't allow undefined symbols when linking
769+
if self.system == 'ios':
770+
return []
771+
else:
772+
return self._apply_prefix('-undefined,dynamic_lookup')
767773

768-
def get_std_shared_module_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
769-
return ['-bundle'] + self._apply_prefix('-undefined,dynamic_lookup')
774+
def get_std_shared_module_args(self, target: 'BuildTarget') -> T.List[str]:
775+
if self.system == 'ios':
776+
return ['-dynamiclib']
777+
else:
778+
return ['-bundle'] + self.get_allow_undefined_args()
770779

771780
def get_pie_args(self) -> T.List[str]:
772781
return []
@@ -890,8 +899,9 @@ class LLVMDynamicLinker(GnuLikeDynamicLinkerMixin, PosixDynamicLinkerMixin, Dyna
890899

891900
def __init__(self, exelist: T.List[str],
892901
for_machine: mesonlib.MachineChoice, prefix_arg: T.Union[str, T.List[str]],
893-
always_args: T.List[str], *, version: str = 'unknown version'):
894-
super().__init__(exelist, for_machine, prefix_arg, always_args, version=version)
902+
always_args: T.List[str], *, system: str = 'unknown system',
903+
version: str = 'unknown version'):
904+
super().__init__(exelist, for_machine, prefix_arg, always_args, system=system, version=version)
895905

896906
# Some targets don't seem to support this argument (windows, wasm, ...)
897907
self.has_allow_shlib_undefined = self._supports_flag('--allow-shlib-undefined', always_args)

0 commit comments

Comments
 (0)