Skip to content

Commit

Permalink
Skip auditwheel for non-compliant linux environment automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed May 21, 2022
1 parent f71f5ef commit 315ac71
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

* Add support for building bin bindings wheels with multiple platform tags in [#928](https://github.com/PyO3/maturin/pull/928)
* Skip auditwheel for non-compliant linux environment automatically in [#931](https://github.com/PyO3/maturin/pull/931)

## [0.12.17] - 2022-05-18

Expand Down
21 changes: 17 additions & 4 deletions src/build_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,22 @@ impl BuildContext {
&self,
artifact: &Path,
platform_tag: &[PlatformTag],
python_interpreter: Option<&PythonInterpreter>,
) -> Result<(Policy, Vec<Library>)> {
if self.skip_auditwheel || self.editable {
return Ok((Policy::default(), Vec::new()));
}

if let Some(python_interpreter) = python_interpreter {
if platform_tag.is_empty() && !python_interpreter.support_portable_wheels() {
println!(
"🐍 Skipping auditwheel because {} does not support manylinux/musllinux wheels",
python_interpreter
);
return Ok((Policy::default(), Vec::new()));
}
}

let mut musllinux: Vec<_> = platform_tag
.iter()
.filter(|tag| tag.is_musllinux())
Expand Down Expand Up @@ -454,7 +465,8 @@ impl BuildContext {
python_interpreter,
Some(&self.project_layout.extension_name),
)?;
let (policy, external_libs) = self.auditwheel(&artifact, &self.platform_tag)?;
let (policy, external_libs) =
self.auditwheel(&artifact, &self.platform_tag, python_interpreter)?;
let platform_tags = if self.platform_tag.is_empty() {
vec![policy.platform_tag()]
} else {
Expand Down Expand Up @@ -528,7 +540,8 @@ impl BuildContext {
Some(python_interpreter),
Some(&self.project_layout.extension_name),
)?;
let (policy, external_libs) = self.auditwheel(&artifact, &self.platform_tag)?;
let (policy, external_libs) =
self.auditwheel(&artifact, &self.platform_tag, Some(python_interpreter))?;
let platform_tags = if self.platform_tag.is_empty() {
vec![policy.platform_tag()]
} else {
Expand Down Expand Up @@ -624,7 +637,7 @@ impl BuildContext {
pub fn build_cffi_wheel(&self) -> Result<Vec<BuiltWheelMetadata>> {
let mut wheels = Vec::new();
let artifact = self.compile_cdylib(None, None)?;
let (policy, external_libs) = self.auditwheel(&artifact, &self.platform_tag)?;
let (policy, external_libs) = self.auditwheel(&artifact, &self.platform_tag, None)?;
let platform_tags = if self.platform_tag.is_empty() {
vec![policy.platform_tag()]
} else {
Expand Down Expand Up @@ -702,7 +715,7 @@ impl BuildContext {
.cloned()
.ok_or_else(|| anyhow!("Cargo didn't build a binary"))?;

let (policy, external_libs) = self.auditwheel(&artifact, &self.platform_tag)?;
let (policy, external_libs) = self.auditwheel(&artifact, &self.platform_tag, None)?;
let platform_tags = if self.platform_tag.is_empty() {
vec![policy.platform_tag()]
} else {
Expand Down
30 changes: 30 additions & 0 deletions src/python_interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,36 @@ impl PythonInterpreter {
Ok(ok) => Ok(String::from_utf8(ok.stdout)?),
}
}

/// Whether this Python interpreter support portable manylinux/musllinux wheels
///
/// Returns `true` if we can not decide
pub fn support_portable_wheels(&self) -> bool {
if !self.runnable {
return true;
}
let out = Command::new(&self.executable)
.args(&[
"-m",
"pip",
"debug",
"--verbose",
"--disable-pip-version-check",
])
.output();

match out {
Err(_) => true,
Ok(ok) if !ok.status.success() => true,
Ok(ok) => {
if let Ok(stdout) = String::from_utf8(ok.stdout) {
stdout.contains("manylinux") || stdout.contains("musllinux")
} else {
true
}
}
}
}
}

impl fmt::Display for PythonInterpreter {
Expand Down

0 comments on commit 315ac71

Please sign in to comment.