Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn about patchelf version requirement #1327

Merged
merged 1 commit into from
Dec 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 31 additions & 12 deletions src/auditwheel/patchelf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,33 @@ use std::ffi::OsStr;
use std::path::Path;
use std::process::Command;

static MISSING_PATCHELF_ERROR: &str = "Failed to execute 'patchelf', did you install it? Hint: Try `pip install maturin[patchelf]` (or just `pip install patchelf`)";

/// Verify patchelf version
pub fn verify_patchelf() -> Result<()> {
let output = Command::new("patchelf")
.arg("--version")
.output()
.context(MISSING_PATCHELF_ERROR)?;
let version = String::from_utf8(output.stdout)
.context("Failed to parse patchelf version")?
.trim()
.to_string();
let version = version.strip_prefix("patchelf").unwrap_or(&version).trim();
let semver = version
.parse::<semver::Version>()
.context("Failed to parse patchelf version")?;
println!("{:?}", semver);
if semver < semver::Version::new(0, 14, 0) {
// TODO: turn it into an error in 1.0
eprintln!(
"⚠️ Warning: patchelf {} found. auditwheel repair requires patchelf >= 0.14.",
version
);
}
Ok(())
}

/// Replace a declared dependency on a dynamic library with another one (`DT_NEEDED`)
pub fn replace_needed<O: AsRef<OsStr>, N: AsRef<OsStr>>(
file: impl AsRef<Path>,
Expand All @@ -13,9 +40,7 @@ pub fn replace_needed<O: AsRef<OsStr>, N: AsRef<OsStr>>(
cmd.arg("--replace-needed").arg(old).arg(new);
}
cmd.arg(file.as_ref());
let output = cmd
.output()
.context("Failed to execute 'patchelf', did you install it? Hint: Try `pip install maturin[patchelf]` (or just `pip install patchelf`)")?;
let output = cmd.output().context(MISSING_PATCHELF_ERROR)?;
if !output.status.success() {
bail!(
"patchelf --replace-needed failed: {}",
Expand All @@ -29,9 +54,7 @@ pub fn replace_needed<O: AsRef<OsStr>, N: AsRef<OsStr>>(
pub fn set_soname<S: AsRef<OsStr>>(file: impl AsRef<Path>, soname: &S) -> Result<()> {
let mut cmd = Command::new("patchelf");
cmd.arg("--set-soname").arg(soname).arg(file.as_ref());
let output = cmd
.output()
.context("Failed to execute 'patchelf', did you install it?")?;
let output = cmd.output().context(MISSING_PATCHELF_ERROR)?;
if !output.status.success() {
bail!(
"patchelf --set-soname failed: {}",
Expand All @@ -45,9 +68,7 @@ pub fn set_soname<S: AsRef<OsStr>>(file: impl AsRef<Path>, soname: &S) -> Result
pub fn remove_rpath(file: impl AsRef<Path>) -> Result<()> {
let mut cmd = Command::new("patchelf");
cmd.arg("--remove-rpath").arg(file.as_ref());
let output = cmd
.output()
.context("Failed to execute 'patchelf', did you install it?")?;
let output = cmd.output().context(MISSING_PATCHELF_ERROR)?;
if !output.status.success() {
bail!(
"patchelf --remove-rpath failed: {}",
Expand All @@ -65,9 +86,7 @@ pub fn set_rpath<S: AsRef<OsStr>>(file: impl AsRef<Path>, rpath: &S) -> Result<(
.arg("--set-rpath")
.arg(rpath)
.arg(file.as_ref());
let output = cmd
.output()
.context("Failed to execute 'patchelf', did you install it?")?;
let output = cmd.output().context(MISSING_PATCHELF_ERROR)?;
if !output.status.success() {
bail!(
"patchelf --set-rpath failed: {}",
Expand Down
5 changes: 4 additions & 1 deletion src/build_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ impl BuildContext {

/// Add library search paths in Cargo target directory rpath when building in editable mode
fn add_rpath(&self, artifacts: &[&BuildArtifact]) -> Result<()> {
if self.editable && self.target.is_linux() {
if self.editable && self.target.is_linux() && !artifacts.is_empty() {
for artifact in artifacts {
if artifact.linked_paths.is_empty() {
continue;
Expand Down Expand Up @@ -355,6 +355,9 @@ impl BuildContext {
if ext_libs.iter().all(|libs| libs.is_empty()) {
return Ok(());
}

patchelf::verify_patchelf()?;

// Put external libs to ${module_name}.libs directory
// See https://github.com/pypa/auditwheel/issues/89
let mut libs_dir = self
Expand Down