-
-
Notifications
You must be signed in to change notification settings - Fork 404
Implement auditwheel repair with patchelf #742
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
68314ed
Add a patchelf mod which calls out to the patchelf utility
messense 27ee336
Split `PlatformTagValidationError` into more specified ones
messense 4e5b2e4
Implement auditwheel repair
messense 28262ec
Use lddtree
messense 3913e3a
Fix a clippy warning
messense 436ee3b
No repair support for cross compiled wheel yet
messense e84fe76
Apply suggestions from code review
messense 51ce673
Use Python 3.10.0 for test
messense a534874
Update lddtree to 0.1.4
messense aa25d34
Update changelog for auditwheel repair
messense 1af539a
Preserving existing rpath entries
messense File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.