Skip to content

Wire rust_objcopy into the generated sysroot action inputs#3972

Merged
UebelAndre merged 1 commit intobazelbuild:mainfrom
brianduff:bduff/rust-objcopy-sysroot-inputs
Apr 16, 2026
Merged

Wire rust_objcopy into the generated sysroot action inputs#3972
UebelAndre merged 1 commit intobazelbuild:mainfrom
brianduff:bduff/rust-objcopy-sysroot-inputs

Conversation

@brianduff
Copy link
Copy Markdown
Contributor

@brianduff brianduff commented Apr 16, 2026

Summary

#3727 added a rust_objcopy attribute to rust_toolchain, a separate rust-objcopy filegroup, 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 join 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:

error: unable to run `rust-objcopy`: No such file or directory (os error 2)

Tracking: #3307.

Fix

Mirror the linker handling in _generate_sysroot: symlink rust_objcopy into the sysroot at lib/rustlib/<triple>/bin/rust-objcopy (where rustc looks) and append it to direct_files so it becomes a declared Rustc action input.

Verification

Patched rules_rust via local_path_override in a minimal smoke workspace using rustc 1.93.0 on aarch64-apple-darwin:

  • bazel build -c opt //:hello succeeds (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 — it was absent before.

Before: no rust-objcopy entry in the Rustc action inputs.
After: bazel-out/.../rust_toolchain/lib/rustlib/aarch64-apple-darwin/bin/rust-objcopy.

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).
@brianduff brianduff marked this pull request as ready for review April 16, 2026 19:23
Copy link
Copy Markdown
Collaborator

@UebelAndre UebelAndre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thank you!

@UebelAndre UebelAndre added this pull request to the merge queue Apr 16, 2026
Merged via the queue into bazelbuild:main with commit 85007f4 Apr 16, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants