Skip to content

Commit 85007f4

Browse files
authored
Wire rust_objcopy into the generated sysroot action inputs (#3972)
## 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`.
1 parent eb280fa commit 85007f4

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

rust/toolchain.bzl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ def _generate_sysroot(
213213
llvm_tools = None,
214214
rust_std = None,
215215
rustfmt = None,
216-
linker = None):
216+
linker = None,
217+
rust_objcopy = None):
217218
"""Generate a rust sysroot from collection of toolchain components
218219
219220
Args:
@@ -228,6 +229,7 @@ def _generate_sysroot(
228229
rust_std (Target, optional): A collection of Files containing Rust standard library components.
229230
rustfmt (File, optional): The path to a `rustfmt` executable.
230231
linker (Target, optional): The linker target (e.g. `rust-lld`).
232+
rust_objcopy (File, optional): The path to a `rust-objcopy` executable.
231233
232234
Returns:
233235
struct: A struct of generated files representing the new sysroot
@@ -300,6 +302,18 @@ def _generate_sysroot(
300302
direct_files.append(sysroot_linker)
301303
transitive_file_sets.append(sysroot_linker_files)
302304

305+
# rust-objcopy. rustc invokes this when `-Cstrip=debuginfo` is set and
306+
# looks for it inside the sysroot at lib/rustlib/{triple}/bin, so it
307+
# needs to land at the same relative path under the generated sysroot
308+
# and be declared as an action input.
309+
if rust_objcopy:
310+
dest = "bin"
311+
if "/lib/rustlib/" in rust_objcopy.dirname:
312+
idx = rust_objcopy.dirname.find("/lib/rustlib/")
313+
dest = rust_objcopy.dirname[idx + 1:]
314+
sysroot_rust_objcopy = _symlink_sysroot_bin(ctx, name, dest, rust_objcopy)
315+
direct_files.append(sysroot_rust_objcopy)
316+
303317
# Llvm tools
304318
sysroot_llvm_tools = None
305319
if llvm_tools:
@@ -425,6 +439,7 @@ def _rust_toolchain_impl(ctx):
425439
cargo_clippy = ctx.file.cargo_clippy,
426440
llvm_tools = ctx.attr.llvm_tools,
427441
linker = ctx.attr.linker,
442+
rust_objcopy = ctx.file.rust_objcopy,
428443
)
429444

430445
# Determine the path and short_path of the sysroot

0 commit comments

Comments
 (0)