Wire rust_objcopy into the generated sysroot action inputs#3972
Merged
UebelAndre merged 1 commit intobazelbuild:mainfrom Apr 16, 2026
Merged
Conversation
bazelbuild#3727 added a `rust_objcopy` attribute to `rust_toolchain`, a separate `rust-objcopy` filegroup in the compiler repo BUILD, and automatic opt-in for Rust 1.84+/recent nightlies. But the glue to turn that attribute into a real action input is missing: `ctx.file.rust_objcopy` is stashed on ToolchainInfo and never used again. It never flows through `_generate_sysroot` into `direct_files`, so it doesn't land in `toolchain.all_files` and isn't declared as an input to the Rustc action. On Linux/macOS with symlink-based sandboxing this is masked — rustc happens to see the neighboring file in the unsandboxed rules_rust external repo. Under remote execution, Windows (file-copy sandbox), or stricter local sandboxes, rustc invokes `rust-objcopy` and fails with: error: unable to run `rust-objcopy`: No such file or directory Thread: bazelbuild#3307 Fix: mirror the `linker` handling — symlink `rust_objcopy` into the generated sysroot at its sibling-of-rustc path (`lib/rustlib/<triple>/bin/rust-objcopy`, which is where rustc looks) and add the symlink to `direct_files` so it joins `all_files` and becomes a declared Rustc action input. Verified by: - Patched rules_rust via `local_path_override` in a minimal smoke workspace using rustc 1.93.0, aarch64-apple-darwin. - `bazel build -c opt //:hello` succeeds (regression: opt-mode process_wrapper uses `-Cstrip=debuginfo`, which invokes rust-objcopy). - `bazel aquery 'mnemonic("Rustc", //:hello)'` now lists the sysroot rust-objcopy symlink as a declared input (was absent before).
UebelAndre
approved these changes
Apr 16, 2026
Collaborator
UebelAndre
left a comment
There was a problem hiding this comment.
Looks good to me, thank you!
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.
Summary
#3727 added a
rust_objcopyattribute torust_toolchain, a separaterust-objcopyfilegroup, and automatic opt-in for Rust 1.84+/recent nightlies. But the glue to turn that attribute into a real action input is missing:ctx.file.rust_objcopyis stashed onToolchainInfoand never used again. It never flows through_generate_sysrootintodirect_files, so it doesn't jointoolchain.all_filesand isn't declared as an input to the Rustc action.On Linux/macOS with symlink-based sandboxing this is masked — rustc happens to see the neighboring file in the unsandboxed
rules_rustexternal repo. Under remote execution, Windows (file-copy sandbox), or stricter local sandboxes, rustc invokesrust-objcopyand fails:Tracking: #3307.
Fix
Mirror the
linkerhandling in_generate_sysroot: symlinkrust_objcopyinto the sysroot atlib/rustlib/<triple>/bin/rust-objcopy(where rustc looks) and append it todirect_filesso it becomes a declared Rustc action input.Verification
Patched
rules_rustvialocal_path_overridein a minimal smoke workspace using rustc 1.93.0 on aarch64-apple-darwin:bazel build -c opt //:hellosucceeds (opt-modeprocess_wrapperuses-Cstrip=debuginfo, which invokes rust-objcopy).bazel aquery 'mnemonic("Rustc", //:hello)'now lists the sysrootrust-objcopysymlink as a declared input — it was absent before.Before: no
rust-objcopyentry in the Rustc action inputs.After:
bazel-out/.../rust_toolchain/lib/rustlib/aarch64-apple-darwin/bin/rust-objcopy.