diff --git a/Changelog.md b/Changelog.md index 45e65ae2d..6ab95cfaf 100644 --- a/Changelog.md +++ b/Changelog.md @@ -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 diff --git a/src/build_context.rs b/src/build_context.rs index d6dd5c43c..c2df703db 100644 --- a/src/build_context.rs +++ b/src/build_context.rs @@ -277,11 +277,25 @@ impl BuildContext { &self, artifact: &Path, platform_tag: &[PlatformTag], + python_interpreter: Option<&PythonInterpreter>, ) -> Result<(Policy, Vec)> { if self.skip_auditwheel || self.editable { return Ok((Policy::default(), Vec::new())); } + if let Some(python_interpreter) = python_interpreter { + if platform_tag.is_empty() + && self.target.is_linux() + && !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()) @@ -454,7 +468,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 { @@ -528,7 +543,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 { @@ -624,7 +640,7 @@ impl BuildContext { pub fn build_cffi_wheel(&self) -> Result> { 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 { @@ -702,7 +718,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 { diff --git a/src/python_interpreter/mod.rs b/src/python_interpreter/mod.rs index df7c89324..4b76c8fb6 100644 --- a/src/python_interpreter/mod.rs +++ b/src/python_interpreter/mod.rs @@ -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 {