diff --git a/Changelog.md b/Changelog.md index 2c03f6f29..f78771c7a 100644 --- a/Changelog.md +++ b/Changelog.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Add support for cross compiling PyPy wheels when abi3 feature is enabled in [#963](https://github.com/PyO3/maturin/pull/963) * Add `--find-interpreter` option to `build` and `publish` commands to search for python interpreters in [#964](https://github.com/PyO3/maturin/pull/964) * Add support for Linux armv6l in [#966](https://github.com/PyO3/maturin/pull/966) +* Infer target triple from `ARCHFLAGS` for macOS to be compatible with `cibuildwheel` in [#967](https://github.com/PyO3/maturin/pull/967) ## [0.12.19] - 2022-06-05 diff --git a/src/build_options.rs b/src/build_options.rs index f70206349..c92eb46e0 100644 --- a/src/build_options.rs +++ b/src/build_options.rs @@ -170,10 +170,10 @@ impl BuildOptions { &self, bridge: &BridgeModel, interpreter: &[PathBuf], + target: &Target, min_python_minor: Option, generate_import_lib: bool, ) -> Result> { - let target = &Target::from_target_triple(self.target.clone())?; match bridge { BridgeModel::Bindings(binding_name, _) | BridgeModel::Bin(Some((binding_name, _))) => { let mut native_interpreters = false; @@ -533,7 +533,35 @@ impl BuildOptions { ); } - let target = Target::from_target_triple(self.target.clone())?; + let mut target_triple = self.target.clone(); + + let mut universal2 = self.universal2; + // Also try to determine universal2 from ARCHFLAGS environment variable + if let Ok(arch_flags) = env::var("ARCHFLAGS") { + let arches: HashSet<&str> = arch_flags + .split("-arch") + .filter_map(|x| { + let x = x.trim(); + if x.is_empty() { + None + } else { + Some(x) + } + }) + .collect(); + match (arches.contains("x86_64"), arches.contains("arm64")) { + (true, true) => universal2 = true, + (true, false) if target_triple.is_none() => { + target_triple = Some("x86_64-apple-darwin".to_string()) + } + (false, true) if target_triple.is_none() => { + target_triple = Some("aarch64-apple-darwin".to_string()) + } + _ => {} + } + }; + + let target = Target::from_target_triple(target_triple)?; let wheel_dir = match self.out { Some(ref dir) => dir.clone(), @@ -546,6 +574,7 @@ impl BuildOptions { self.find_interpreters( &bridge, &[], + &target, get_min_python_minor(&metadata21), generate_import_lib, )? @@ -556,7 +585,7 @@ impl BuildOptions { } else { self.interpreter.clone() }; - self.find_interpreters(&bridge, &interpreter, None, generate_import_lib)? + self.find_interpreters(&bridge, &interpreter, &target, None, generate_import_lib)? }; let mut rustc_extra_args = self.rustc_extra_args.clone(); @@ -569,24 +598,6 @@ impl BuildOptions { } rustc_extra_args = split_extra_args(&rustc_extra_args)?; - let mut universal2 = self.universal2; - // Also try to determine universal2 from ARCHFLAGS environment variable - if let Ok(arch_flags) = env::var("ARCHFLAGS") { - let arches: HashSet<&str> = arch_flags - .split("-arch") - .filter_map(|x| { - let x = x.trim(); - if x.is_empty() { - None - } else { - Some(x) - } - }) - .collect(); - if arches.contains("x86_64") && arches.contains("arm64") { - universal2 = true; - } - }; let strip = pyproject.map(|x| x.strip()).unwrap_or_default() || strip; let skip_auditwheel = pyproject.map(|x| x.skip_auditwheel()).unwrap_or_default() || self.skip_auditwheel;