Skip to content
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

Infer target triple from ARCHFLAGS for macOS #967

Merged
merged 1 commit into from
Jun 14, 2022
Merged
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
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
53 changes: 32 additions & 21 deletions src/build_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ impl BuildOptions {
&self,
bridge: &BridgeModel,
interpreter: &[PathBuf],
target: &Target,
min_python_minor: Option<usize>,
generate_import_lib: bool,
) -> Result<Vec<PythonInterpreter>> {
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;
Expand Down Expand Up @@ -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(),
Expand All @@ -546,6 +574,7 @@ impl BuildOptions {
self.find_interpreters(
&bridge,
&[],
&target,
get_min_python_minor(&metadata21),
generate_import_lib,
)?
Expand All @@ -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();
Expand All @@ -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;
Expand Down