@@ -567,13 +567,43 @@ def __init__(
567
567
self ._build_dir = pathlib .Path (build_dir ).absolute () if build_dir else (self ._working_dir / 'build' )
568
568
self ._install_dir = self ._working_dir / 'install'
569
569
self ._meson_native_file = self ._source_dir / '.mesonpy-native-file.ini'
570
+ self ._meson_cross_file = self ._source_dir / '.mesonpy-cross-file.ini'
571
+ self ._meson_args = collections .defaultdict (list , meson_args or {})
570
572
self ._env = os .environ .copy ()
571
573
572
574
# prepare environment
573
575
ninja_path = _env_ninja_command ()
574
576
if ninja_path is not None :
575
577
self ._env .setdefault ('NINJA' , str (ninja_path ))
576
578
579
+ # setuptools-like ARCHFLAGS environment variable support
580
+ if sysconfig .get_platform ().startswith ('macosx-' ):
581
+ archflags = self ._env .get ('ARCHFLAGS' )
582
+ if archflags is not None :
583
+ arch , * other = filter (None , (x .strip () for x in archflags .split ('-arch' )))
584
+ if other :
585
+ raise ConfigError (
586
+ f'multi-architecture builds are not supported but $ARCHFLAGS is set to { archflags !r} ' )
587
+ macver , _ , nativearch = platform .mac_ver ()
588
+ if arch != nativearch :
589
+ x = self ._env .setdefault ('_PYTHON_HOST_PLATFORM' , f'macosx-{ macver } -{ arch } ' )
590
+ if not x .endswith (arch ):
591
+ raise ConfigError (
592
+ f'$ARCHFLAGS and $_PYTHON_HOST_PLATFORM environment variables do not agree: { archflags !r} { x !r} ' )
593
+ family = 'aarch64' if arch == 'arm64' else arch
594
+ cross_file_data = textwrap .dedent (f'''
595
+ [binaries]
596
+ c = ['cc', '-arch', { arch !r} ]
597
+ cpp = ['cpp', '-arch', { arch !r} ]
598
+ [host_machine]
599
+ system = 'Darwin'
600
+ cpu = { arch !r}
601
+ cpu_family = { family !r}
602
+ endian = 'little'
603
+ ''' )
604
+ self ._meson_cross_file .write_text (cross_file_data )
605
+ self ._meson_args ['setup' ].extend (('--cross-file' , os .fspath (self ._meson_cross_file )))
606
+
577
607
# load config -- PEP 621 support is optional
578
608
self ._config = tomllib .loads (self ._source_dir .joinpath ('pyproject.toml' ).read_text ())
579
609
self ._pep621 = 'project' in self ._config
@@ -595,10 +625,9 @@ def __init__(
595
625
self ._validate_metadata ()
596
626
597
627
# load meson args
598
- self ._meson_args = collections .defaultdict (tuple , meson_args or {})
599
628
for key in self ._get_config_key ('args' ):
600
629
args_from_config = tuple (self ._get_config_key (f'args.{ key } ' ))
601
- self ._meson_args [key ] = args_from_config + tuple ( self . _meson_args [ key ] )
630
+ self ._meson_args [key ]. extend ( args_from_config )
602
631
# XXX: We should validate the user args to make sure they don't conflict with ours.
603
632
604
633
self ._check_for_unknown_config_keys ({
@@ -975,7 +1004,7 @@ def _validate_string_collection(key: str) -> None:
975
1004
with Project .with_temp_working_dir (
976
1005
build_dir = builddir ,
977
1006
meson_args = typing .cast (MesonArgs , {
978
- key : config_settings .get (f'{ key } -args' , () )
1007
+ key : config_settings .get (f'{ key } -args' , [] )
979
1008
for key in meson_args_keys
980
1009
}),
981
1010
) as project :
0 commit comments