diff --git a/Changelog.md b/Changelog.md index 0014ca4d9..4d3485d9d 100644 --- a/Changelog.md +++ b/Changelog.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +* Use platform tag from `sysconfig.platform` on non-portable Linux in [#709](https://github.com/PyO3/maturin/pull/709) +* Consider current machine architecture when generating platform tags for abi3 + wheels on linux in [#709](https://github.com/PyO3/maturin/pull/709) + ## [0.12.2] - 2021-11-26 * Add support for excluding files from wheels by `.gitignore` in [#695](https://github.com/PyO3/maturin/pull/695) diff --git a/src/auditwheel/platform_tag.rs b/src/auditwheel/platform_tag.rs index 430c565bb..9b17e68b1 100644 --- a/src/auditwheel/platform_tag.rs +++ b/src/auditwheel/platform_tag.rs @@ -54,6 +54,13 @@ impl PlatformTag { PlatformTag::Linux => Vec::new(), } } + + /// Is this a portable linux platform tag + /// + /// Only manylinux and musllinux are portable + pub fn is_portable(&self) -> bool { + !matches!(self, PlatformTag::Linux) + } } impl fmt::Display for PlatformTag { diff --git a/src/build_options.rs b/src/build_options.rs index 16f552816..e55265f32 100644 --- a/src/build_options.rs +++ b/src/build_options.rs @@ -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; @@ -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]; diff --git a/src/python_interpreter.rs b/src/python_interpreter.rs index 859946528..81f347dec 100644 --- a/src/python_interpreter.rs +++ b/src/python_interpreter.rs @@ -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; @@ -314,7 +313,7 @@ fn fun_with_abiflags( ) -> Result { 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 ಠ_ಠ", @@ -379,9 +378,11 @@ impl PythonInterpreter { /// /// If abi3 is true, cpython wheels use the generic abi3 with the given version as minimum pub fn get_tag(&self, platform_tag: PlatformTag, universal2: bool) -> String { - let platform = if self.target.is_windows() { - // Restrict `sysconfig.get_platform()` usage to Windows only for now - // so we don't need to deal with macOS deployment target + // Restrict `sysconfig.get_platform()` usage to Windows and non-portable Linux only for now + // so we don't need to deal with macOS deployment target + let use_sysconfig_platform = + self.target.is_windows() || (self.target.is_linux() && !platform_tag.is_portable()); + let platform = if use_sysconfig_platform { self.platform .clone() .unwrap_or_else(|| self.target.get_platform_tag(platform_tag, universal2)) diff --git a/src/target.rs b/src/target.rs index 4da626b44..f96f35e95 100644 --- a/src/target.rs +++ b/src/target.rs @@ -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}; @@ -92,6 +93,7 @@ pub struct Target { arch: Arch, env: Environment, triple: String, + cross_compiling: bool, } impl Target { @@ -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 @@ -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_else(|_| 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(".") } @@ -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 { vec![format!( diff --git a/tests/common/editable.rs b/tests/common/editable.rs index 23bf5934a..684d9785e 100644 --- a/tests/common/editable.rs +++ b/tests/common/editable.rs @@ -23,6 +23,8 @@ pub fn test_editable(package: impl AsRef, bindings: Option) -> Res &interpreter, "--manifest-path", &package_string, + "--compatibility", + "linux", "--cargo-extra-args='--quiet'", ];