Skip to content

Add modifications to support compiling on iOS. #19

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

Open
wants to merge 5 commits into
base: main-numpymeson
Choose a base branch
from
Open
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
9 changes: 5 additions & 4 deletions docs/markdown/Dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,11 @@ TODO

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

```meson
accelerate_dep = dependency('accelerate',
Expand Down
2 changes: 2 additions & 0 deletions docs/markdown/Reference-tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,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 @@ -1062,8 +1062,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
17 changes: 16 additions & 1 deletion mesonbuild/dependencies/blas_lapack.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,10 @@ def __init__(self, name: str, environment: 'Environment', kwargs: T.Dict[str, T.
self.parse_modules(kwargs)

for_machine = MachineChoice.BUILD if kwargs.get('native', False) else MachineChoice.HOST
if environment.machines[for_machine].is_darwin() and self.check_macOS_recent_enough():
if (
(environment.machines[for_machine].system == 'darwin' and self.check_macOS_recent_enough())
or (environment.machines[for_machine].system == 'ios' and self.check_iOS_recent_enough())
):
self.detect(kwargs)

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

def check_iOS_recent_enough(self) -> bool:
ios_version = platform.ios_ver().system
deploy_target = os.environ.get('IPHONEOS_DEPLOYMENT_TARGET', ios_version)
if not mesonlib.version_compare(deploy_target, '>=16.4'):
return False

# We also need the SDK to be >=16.4
sdk = "iphonesimulator" if platform.ios_ver().is_simulator else "iphoneos"
cmd = ['xcrun', '-sdk', sdk, '--show-sdk-version']
sdk_version = subprocess.run(cmd, capture_output=True, check=True, text=True).stdout.strip()
return mesonlib.version_compare(sdk_version, '>=16.4')

def detect(self, kwargs: T.Dict[str, T.Any]) -> None:
from .framework import ExtraFrameworkDependency
dep = ExtraFrameworkDependency('Accelerate', self.env, kwargs)
Expand Down
4 changes: 2 additions & 2 deletions mesonbuild/envconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,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 @@ -447,6 +447,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',
}
Expand Down
13 changes: 10 additions & 3 deletions mesonbuild/linkers/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,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 @@ -155,7 +156,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 @@ -213,7 +214,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 @@ -232,7 +236,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
22 changes: 16 additions & 6 deletions mesonbuild/linkers/linkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,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 @@ -758,10 +760,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, options: 'KeyedOptionDictType') -> T.List[str]:
return ['-bundle'] + self._apply_prefix('-undefined,dynamic_lookup')
def get_std_shared_module_args(self, target: 'BuildTarget') -> T.List[str]:
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 Expand Up @@ -888,8 +897,9 @@ class LLVMDynamicLinker(GnuLikeDynamicLinkerMixin, PosixDynamicLinkerMixin, Dyna

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'):
super().__init__(exelist, for_machine, prefix_arg, always_args, version=version)
always_args: T.List[str], *, system: str = 'unknown system',
version: str = 'unknown version'):
super().__init__(exelist, for_machine, prefix_arg, always_args, system=system, version=version)

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