-
-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #742 from messense/patchelf
Implement auditwheel repair with patchelf
- Loading branch information
Showing
9 changed files
with
414 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
mod audit; | ||
mod musllinux; | ||
pub mod patchelf; | ||
mod platform_tag; | ||
mod policy; | ||
mod repair; | ||
|
||
pub use self::audit::*; | ||
pub use audit::*; | ||
pub use platform_tag::PlatformTag; | ||
pub use policy::{Policy, MANYLINUX_POLICIES, MUSLLINUX_POLICIES}; | ||
pub use repair::{get_external_libs, hash_file}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
use anyhow::{bail, Context, Result}; | ||
use std::ffi::OsStr; | ||
use std::path::Path; | ||
use std::process::Command; | ||
|
||
/// Replace a declared dependency on a dynamic library with another one (`DT_NEEDED`) | ||
pub fn replace_needed<S: AsRef<OsStr>>( | ||
file: impl AsRef<Path>, | ||
old_lib: &str, | ||
new_lib: &S, | ||
) -> Result<()> { | ||
let mut cmd = Command::new("patchelf"); | ||
cmd.arg("--replace-needed") | ||
.arg(old_lib) | ||
.arg(new_lib) | ||
.arg(file.as_ref()); | ||
let output = cmd | ||
.output() | ||
.context("Failed to execute 'patchelf', did you install it?")?; | ||
if !output.status.success() { | ||
bail!( | ||
"patchelf --replace-needed failed: {}", | ||
String::from_utf8_lossy(&output.stderr) | ||
); | ||
} | ||
Ok(()) | ||
} | ||
|
||
/// Change `SONAME` of a dynamic library | ||
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?")?; | ||
if !output.status.success() { | ||
bail!( | ||
"patchelf --set-soname failed: {}", | ||
String::from_utf8_lossy(&output.stderr) | ||
); | ||
} | ||
Ok(()) | ||
} | ||
|
||
/// /// Remove a `RPATH` from executables and libraries | ||
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?")?; | ||
if !output.status.success() { | ||
bail!( | ||
"patchelf --remove-rpath failed: {}", | ||
String::from_utf8_lossy(&output.stderr) | ||
); | ||
} | ||
Ok(()) | ||
} | ||
|
||
/// Change the `RPATH` of executables and libraries | ||
pub fn set_rpath<S: AsRef<OsStr>>(file: impl AsRef<Path>, rpath: &S) -> Result<()> { | ||
remove_rpath(&file)?; | ||
let mut cmd = Command::new("patchelf"); | ||
cmd.arg("--force-rpath") | ||
.arg("--set-rpath") | ||
.arg(rpath) | ||
.arg(file.as_ref()); | ||
let output = cmd | ||
.output() | ||
.context("Failed to execute 'patchelf', did you install it?")?; | ||
if !output.status.success() { | ||
bail!( | ||
"patchelf --set-rpath failed: {}", | ||
String::from_utf8_lossy(&output.stderr) | ||
); | ||
} | ||
Ok(()) | ||
} | ||
|
||
/// Get the `RPATH` of executables and libraries | ||
pub fn get_rpath(file: impl AsRef<Path>) -> Result<String> { | ||
let mut cmd = Command::new("patchelf"); | ||
cmd.arg("--print-rpath").arg(file.as_ref()); | ||
let output = cmd | ||
.output() | ||
.context("Failed to execute 'patchelf', did you install it?")?; | ||
if !output.status.success() { | ||
bail!( | ||
"patchelf --print-rpath failed: {}", | ||
String::from_utf8_lossy(&output.stderr) | ||
); | ||
} | ||
let rpath = String::from_utf8(output.stdout)?; | ||
Ok(rpath.trim().to_string()) | ||
} |
Oops, something went wrong.