Skip to content

Commit

Permalink
Infer target triple from ARCHFLAGS for macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Jun 14, 2022
1 parent 7ee686b commit 792131c
Showing 1 changed file with 33 additions and 22 deletions.
55 changes: 33 additions & 22 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,36 @@ 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 strip = pyproject.map(|x| x.strip()).unwrap_or_default() || strip;

let target = Target::from_target_triple(target_triple)?;

let wheel_dir = match self.out {
Some(ref dir) => dir.clone(),
Expand All @@ -546,6 +575,7 @@ impl BuildOptions {
self.find_interpreters(
&bridge,
&[],
&target,
get_min_python_minor(&metadata21),
generate_import_lib,
)?
Expand All @@ -556,7 +586,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,25 +599,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;
let platform_tags = if self.platform_tag.is_empty() {
Expand Down

0 comments on commit 792131c

Please sign in to comment.