Repository navigation
fix(toolchains): skip install_name_tool when the libpython dylib id is already @rpath - #4528
TrapsterDK wants to merge 5 commits into
Conversation
…path Fixes bazel-contrib#4527 Assisted-by: Claude
|
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
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
What are the situations where this is true? Could we just not run the command if it is not found? This adds complex logic that I don't have confidence in maintaining (sure slopbot can keep it, but I want to be able to understand it). An easier fix would be to just skip using the |
Per review, drop the Mach-O parser. If `install_name_tool` is not on PATH, leave the libpython dylib id unchanged and log a warning instead of failing the fetch. python-build-standalone sets the id to `@rpath/<dylib>` itself since astral-sh/python-build-standalone#914. * Moves the fix-up into `fix_up_dylib_id` and tests it with the mock rctx for both cases. * Adds a no-op `watch` to the mock rctx, which `which_unchecked` calls. Assisted-by: Claude
|
Agreed, that is simpler. python-build-standalone sets the id to 933ab85 drops the Mach-O parser and its tests. If Assisted by Claude. |
Fixes #4527
On macOS, fetching a python-build-standalone runtime always ran
install_name_tool -id @rpath/<dylib>onlibpython*.dylib. With aPATHthat has no
install_name_tool(for example a hermetic--repo_env=PATH=...), the repository rule failed inpython_repository.FixUpDyldIdPath.To fix, the fix-up moves into
fix_up_dylib_id. Ifinstall_name_toolis noton
PATH, it logs a warning and leaves the dylib id unchanged instead offailing the fetch. python-build-standalone sets the id to
@rpath/<dylib>itself since astral-sh/python-build-standalone#914, so recent runtimes need no
rewrite.
Tested with new unit tests in
//tests/python_repositorythat use the mockrctx for both cases (tool present and tool missing). The mock rctx gets a
no-op
watch, whichwhich_uncheckedcalls.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.