Skip to content

Commit

Permalink
Consider current machine architecture when generating platform tags f…
Browse files Browse the repository at this point in the history
…or linux
  • Loading branch information
messense committed Nov 28, 2021
1 parent 5f650ca commit 86dffdd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/build_options.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::auditwheel::PlatformTag;
use crate::build_context::{BridgeModel, ProjectLayout};
use crate::cross_compile::{find_sysconfigdata, is_cross_compiling, parse_sysconfigdata};
use crate::cross_compile::{find_sysconfigdata, parse_sysconfigdata};
use crate::python_interpreter::InterpreterKind;
use crate::BuildContext;
use crate::CargoToml;
Expand Down Expand Up @@ -515,7 +515,7 @@ pub fn find_interpreter(
}
}

if binding_name == "pyo3" && target.is_unix() && is_cross_compiling(target)? {
if binding_name == "pyo3" && target.is_unix() && target.cross_compiling() {
if let Some(cross_lib_dir) = std::env::var_os("PYO3_CROSS_LIB_DIR") {
println!("⚠️ Cross-compiling is poorly supported");
let host_python = &interpreter[0];
Expand Down
3 changes: 1 addition & 2 deletions src/python_interpreter.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::auditwheel::PlatformTag;
use crate::cross_compile::is_cross_compiling;
use crate::{BridgeModel, Target};
use anyhow::{bail, format_err, Context, Result};
use regex::Regex;
Expand Down Expand Up @@ -314,7 +313,7 @@ fn fun_with_abiflags(
) -> Result<String> {
if bridge != &BridgeModel::Cffi
&& target.get_python_os() != message.system
&& !is_cross_compiling(target)?
&& !target.cross_compiling()
{
bail!(
"platform.system() in python, {}, and the rust target, {:?}, don't match ಠ_ಠ",
Expand Down
25 changes: 21 additions & 4 deletions src/target.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::cross_compile::is_cross_compiling;
use crate::python_interpreter::InterpreterKind;
use crate::{PlatformTag, PythonInterpreter};
use anyhow::{bail, format_err, Context, Result};
Expand Down Expand Up @@ -92,6 +93,7 @@ pub struct Target {
arch: Arch,
env: Environment,
triple: String,
cross_compiling: bool,
}

impl Target {
Expand Down Expand Up @@ -139,12 +141,15 @@ impl Target {
bail!("{} is not supported on {}", arch, os);
}

Ok(Target {
let mut target = Target {
os,
arch,
env: platform.environment,
triple,
})
cross_compiling: false,
};
target.cross_compiling = is_cross_compiling(&target)?;
Ok(target)
}

/// Returns the platform part of the tag for the wheel name
Expand Down Expand Up @@ -186,9 +191,16 @@ impl Target {
)
}
(Os::Linux, _) => {
let mut tags = vec![format!("{}_{}", platform_tag, self.arch)];
let arch = if self.cross_compiling {
self.arch.to_string()
} else {
PlatformInfo::new()
.map(|info| info.machine().into_owned())
.unwrap_or(self.arch.to_string())
};
let mut tags = vec![format!("{}_{}", platform_tag, arch)];
for alias in platform_tag.aliases() {
tags.push(format!("{}_{}", alias, self.arch));
tags.push(format!("{}_{}", alias, arch));
}
tags.join(".")
}
Expand Down Expand Up @@ -297,6 +309,11 @@ impl Target {
)
}

/// Is cross compiling for this target
pub fn cross_compiling(&self) -> bool {
self.cross_compiling
}

/// Returns the tags for the WHEEL file for cffi wheels
pub fn get_py3_tags(&self, platform_tag: PlatformTag, universal2: bool) -> Vec<String> {
vec![format!(
Expand Down

0 comments on commit 86dffdd

Please sign in to comment.