Repository navigation
fix(toolchains): skip install_name_tool when the libpython dylib id is already @rpath - #4528
Open
TrapsterDK wants to merge 4 commits into
Open
TrapsterDK wants to merge 4 commits into
TrapsterDK wants to merge 4 commits into
Conversation
…path Fixes bazel-contrib#4527 Assisted-by: Claude
Contributor
Author
|
AI disclosure: this change was written with Claude. A human (TrapsterDK) is the author and reviews and posts all replies on this PR; no agent monitors or answers comments automatically. Assisted by Claude. |
Assisted-by: Claude
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the change reducing unnecessary macOS runtime-fetching tool dependencies.
No open issues 🎉
What changed in this PR
This PR addresses #4527 by avoiding an unnecessary install_name_tool dependency when fetching macOS Python runtimes through python_repository.
Changes:
- Skip dylib ID repair when the binary contains the expected
@rpath/<dylib>string, retaining the existing repair otherwise. - Add a release note describing the macOS fetching fix.
| File | Description |
|---|---|
python/private/python_repository.bzl |
Guard the install_name_tool lookup and invocation with a dylib content check. |
news/4527.fixed.md |
Document the reduced host-tool requirement for macOS runtime fetching. |
Review effort: Balanced
…l_name_tool The skip check searched the whole dylib for `@rpath/<dylib>`, so the same path in another load command or string would skip the id fix-up and leave the build-host id in place. Check that the path is the name of the LC_ID_DYLIB load command of a thin 64-bit Mach-O file instead, without running `otool`, which may be missing from PATH like `install_name_tool`. Anything else still gets the id rewritten. * Adds unit tests for the check. * Wraps the news entry and links the issue. Assisted-by: Claude
The skip check still searched the whole dylib for `@rpath/<dylib>`, so a well-formed id command in the data after the load commands could skip the id fix-up. Read `ncmds` and `sizeofcmds` from the mach_header_64 and walk the load commands by `cmdsize`, staying inside `sizeofcmds`; the first LC_ID_DYLIB decides. Fields are decoded with a byte table since `rctx.read` returns Latin-1 characters and Starlark has no `ord`. Universal and 32-bit binaries, and malformed load commands, still get the id rewritten. * Adds unit tests for an id command outside the load command area, a truncated file, a 32-bit binary, and sizes with bytes >= 0x80. * Adds a dev repo and py_test that check the same file after `rctx.read`. Assisted-by: Claude
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #4527
On macOS, fetching a python-build-standalone runtime always ran
install_name_tool -id @rpath/<dylib>onlibpython*.dylib, even when thedylib already had that id. With a
PATHthat has noinstall_name_tool(for example a hermetic
--repo_env=PATH=...), the repository rule failed inpython_repository.FixUpDyldIdPathalthough no change was needed.To fix,
python_repositorynow reads the dylib and skipsinstall_name_toolonly when its
LC_ID_DYLIBload command names@rpath/<dylib>. The checkparses the Mach-O in Starlark rather than running
otool -D, which could bemissing from
PATHtoo: it readsncmdsandsizeofcmdsfrom the 64-bitheader, walks the load commands by
cmdsizewithout leavingsizeofcmds, andcompares the install name of the first
LC_ID_DYLIB. The same path in anotherload command or after the load commands does not count. Universal and 32-bit
binaries, and malformed load commands, get the id rewritten as before.
Tested with new unit tests in
//tests/python_repositorythat cover amatching id, a build-host id, the path outside the id command and outside the
load command area, a truncated file, a different dylib name, universal and
32-bit binaries, and sizes with bytes >= 0x80. A
py_testthere also checksa dylib with such bytes after it is written to disk and read back with
rctx.read.