Skip to content

Commit

Permalink
Merge pull request #709 from messense/linux-sysconfig-platform
Browse files Browse the repository at this point in the history
Use platform tag from `sysconfig.platform` on non-portable Linux
  • Loading branch information
messense authored Nov 28, 2021
2 parents 579b386 + b6edd31 commit 03a3290
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 11 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions src/auditwheel/platform_tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
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
11 changes: 6 additions & 5 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 Expand Up @@ -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))
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_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(".")
}
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
2 changes: 2 additions & 0 deletions tests/common/editable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub fn test_editable(package: impl AsRef<Path>, bindings: Option<String>) -> Res
&interpreter,
"--manifest-path",
&package_string,
"--compatibility",
"linux",
"--cargo-extra-args='--quiet'",
];

Expand Down

0 comments on commit 03a3290

Please sign in to comment.