Skip to content

Commit

Permalink
Calculate minimal manylinux platform tag based on rustc version
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Aug 14, 2022
1 parent 1b301e5 commit 1e92e60
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 61 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ fs-err = "2.5.0"
fat-macho = { version = "0.4.5", default-features = false }
once_cell = "1.7.2"
rustc_version = "0.4.0"
semver = "1.0.13"
target-lexicon = "0.12.0"
pyproject-toml = "0.3.0"
python-pkginfo = "0.5.4"
Expand Down
5 changes: 2 additions & 3 deletions src/auditwheel/audit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,14 +363,13 @@ pub fn auditwheel_rs(
///
/// Currently only gcc is supported, clang doesn't have a `--print-sysroot` option
pub fn get_sysroot_path(target: &Target) -> Result<PathBuf> {
use crate::target::get_host_target;
use std::process::{Command, Stdio};

if let Some(sysroot) = std::env::var_os("TARGET_SYSROOT") {
return Ok(PathBuf::from(sysroot));
}

let host_triple = get_host_target()?;
let host_triple = target.host_triple();
let target_triple = target.target_triple();
if host_triple != target_triple {
let mut build = cc::Build::new();
Expand All @@ -379,7 +378,7 @@ pub fn get_sysroot_path(target: &Target) -> Result<PathBuf> {
.cargo_metadata(false)
// opt_level, host and target are required
.opt_level(0)
.host(&host_triple)
.host(host_triple)
.target(target_triple);
let compiler = build
.try_get_compiler()
Expand Down
3 changes: 1 addition & 2 deletions src/cross_compile.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::target::get_host_target;
use crate::{PythonInterpreter, Target};
use anyhow::{bail, Result};
use fs_err::{self as fs, DirEntry};
Expand All @@ -8,7 +7,7 @@ use std::path::{Path, PathBuf};

pub fn is_cross_compiling(target: &Target) -> Result<bool> {
let target_triple = target.target_triple();
let host = get_host_target()?;
let host = target.host_triple();
if target_triple == host {
// Not cross-compiling
return Ok(false);
Expand Down
63 changes: 37 additions & 26 deletions src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::python_interpreter::InterpreterKind;
use crate::{PlatformTag, PythonInterpreter};
use anyhow::{anyhow, bail, format_err, Context, Result};
use platform_info::*;
use rustc_version::VersionMeta;
use serde::Deserialize;
use std::env;
use std::fmt;
Expand Down Expand Up @@ -132,8 +133,8 @@ pub struct Target {
env: Environment,
triple: String,
cross_compiling: bool,
/// Host machine target triple
pub(crate) host_triple: String,
/// rustc version information
pub(crate) rustc_version: VersionMeta,
/// Is user specified `--target`
pub(crate) user_specified: bool,
}
Expand All @@ -148,7 +149,8 @@ impl Target {
Architecture, ArmArchitecture, Mips32Architecture, Mips64Architecture, OperatingSystem,
};

let host_triple = get_host_target()?;
let rustc_version = rustc_version_meta()?;
let host_triple = &rustc_version.host;
let (platform, triple) = if let Some(ref target_triple) = target_triple {
let platform: Triple = target_triple
.parse()
Expand Down Expand Up @@ -204,7 +206,7 @@ impl Target {
arch,
env: platform.environment,
triple,
host_triple,
rustc_version,
user_specified: target_triple.is_some(),
cross_compiling: false,
};
Expand Down Expand Up @@ -408,13 +410,19 @@ impl Target {
/// Returns the oldest possible Manylinux tag for this architecture
pub fn get_minimum_manylinux_tag(&self) -> PlatformTag {
match self.arch {
Arch::Aarch64
| Arch::Armv7L
| Arch::Powerpc64
| Arch::Powerpc64Le
| Arch::S390X
| Arch::X86
| Arch::X86_64 => PlatformTag::manylinux2014(),
Arch::Aarch64 | Arch::Armv7L | Arch::Powerpc64 | Arch::Powerpc64Le | Arch::S390X => {
PlatformTag::manylinux2014()
}
Arch::X86 | Arch::X86_64 => {
let rust_1_64 = semver::Version::new(1, 64, 0);
// rustc 1.64.0 bumps glibc requirement to 2.17
// see https://blog.rust-lang.org/2022/08/01/Increasing-glibc-kernel-requirements.html
if self.rustc_version.semver >= rust_1_64 {
PlatformTag::manylinux2014()
} else {
PlatformTag::manylinux2010()
}
}
Arch::Armv6L
| Arch::Wasm32
| Arch::Riscv64
Expand Down Expand Up @@ -445,11 +453,16 @@ impl Target {
}
}

/// Returns target triple string
/// Returns target triple as string
pub fn target_triple(&self) -> &str {
&self.triple
}

/// Returns host triple as string
pub fn host_triple(&self) -> &str {
&self.rustc_version.host
}

/// Returns true if the current platform is not windows
pub fn is_unix(&self) -> bool {
match self.os {
Expand Down Expand Up @@ -627,22 +640,20 @@ impl Target {
}
}

pub(crate) fn get_host_target() -> Result<String> {
let host = rustc_version::version_meta()
.map(|meta| meta.host)
.map_err(|err| match err {
rustc_version::Error::CouldNotExecuteCommand(e)
if e.kind() == std::io::ErrorKind::NotFound =>
{
anyhow!(
"rustc, the rust compiler, is not installed or not in PATH. \
fn rustc_version_meta() -> Result<VersionMeta> {
let meta = rustc_version::version_meta().map_err(|err| match err {
rustc_version::Error::CouldNotExecuteCommand(e)
if e.kind() == std::io::ErrorKind::NotFound =>
{
anyhow!(
"rustc, the rust compiler, is not installed or not in PATH. \
This package requires Rust and Cargo to compile extensions. \
Install it through the system's package manager or via https://rustup.rs/.",
)
}
err => anyhow!(err).context("Failed to run rustc to get the host target"),
})?;
Ok(host)
)
}
err => anyhow!(err).context("Failed to run rustc to get the host target"),
})?;
Ok(meta)
}

fn macosx_deployment_target(
Expand Down
81 changes: 52 additions & 29 deletions test-crates/cargo-mock/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/common/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub fn test_integration(
if zig && build_context.target.is_linux() && !build_context.target.is_musl_target() {
assert!(filename
.to_string_lossy()
.ends_with("manylinux_2_17_x86_64.manylinux2014_x86_64.whl"))
.ends_with("manylinux_2_12_x86_64.manylinux2010_x86_64.whl"))
}
let venv_suffix = if supported_version == "py3" {
"py3".to_string()
Expand Down

0 comments on commit 1e92e60

Please sign in to comment.