-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Patch embedded install path for Python dylib on macOS during python install
#10629
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
5 commits
Select commit
Hold shift + click to select a range
79092d9
Fix: path install name for Python's dylibs on macOS when the toolchai…
LukeMathWalker 95d3adf
Address first round of review comments
LukeMathWalker dd94dc5
Test the patching process using otool
LukeMathWalker 200698f
Centralize warn message
LukeMathWalker 4f2dfba
Make test case more robust
zanieb 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
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use std::{io::ErrorKind, path::PathBuf}; | ||
|
||
use uv_fs::Simplified as _; | ||
use uv_warnings::warn_user; | ||
|
||
use crate::managed::ManagedPythonInstallation; | ||
|
||
pub fn patch_dylib_install_name(dylib: PathBuf) -> Result<(), Error> { | ||
let output = match std::process::Command::new("install_name_tool") | ||
.arg("-id") | ||
.arg(&dylib) | ||
.arg(&dylib) | ||
.output() | ||
{ | ||
Ok(output) => output, | ||
Err(e) => { | ||
let e = if e.kind() == ErrorKind::NotFound { | ||
Error::MissingInstallNameTool | ||
} else { | ||
e.into() | ||
}; | ||
return Err(e); | ||
} | ||
}; | ||
|
||
if !output.status.success() { | ||
let stderr = String::from_utf8_lossy(&output.stderr).into_owned(); | ||
return Err(Error::RenameError { dylib, stderr }); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
pub enum Error { | ||
#[error(transparent)] | ||
Io(#[from] std::io::Error), | ||
#[error("`install_name_tool` is not available on this system. | ||
This utility is part of macOS Developer Tools. Please ensure that the Xcode Command Line Tools are installed by running: | ||
|
||
xcode-select --install | ||
|
||
For more information, see: https://developer.apple.com/xcode/")] | ||
MissingInstallNameTool, | ||
#[error("Failed to update the install name of the Python dynamic library located at `{}`", dylib.user_display())] | ||
RenameError { dylib: PathBuf, stderr: String }, | ||
} | ||
|
||
impl Error { | ||
/// Emit a user-friendly warning about the patching failure. | ||
pub fn warn_user(&self, installation: &ManagedPythonInstallation) { | ||
let error = if tracing::enabled!(tracing::Level::DEBUG) { | ||
format!("\nUnderlying error: {self}") | ||
} else { | ||
String::new() | ||
}; | ||
warn_user!( | ||
"Failed to patch the install name of the dynamic library for {}. This may cause issues when building Python native extensions.{}", | ||
installation.executable().simplified_display(), | ||
error | ||
); | ||
} | ||
} |
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
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.