Add rust_objcopy attribute to rust_toolchan#3727
Conversation
738871d to
b715cc7
Compare
Testing PR bazelbuild/rules_rust#3727 which adds wasm-component-ld.exe and rust-objcopy.exe to rustc_lib filegroup. This should fix Windows wasm32-wasip2 builds by ensuring the linker is copied into the Bazel sandbox. Issue: avrabe/rules_rust#8
Testing PR bazelbuild/rules_rust#3727 which adds wasm-component-ld.exe and rust-objcopy.exe to rustc_lib filegroup. This should fix Windows wasm32-wasip2 builds by ensuring the linker is copied into the Bazel sandbox. Issue: avrabe/rules_rust#8
b715cc7 to
030a4cf
Compare
030a4cf to
2b63294
Compare
|
@illicitonion is there anything which prevents this to be merged? this change is useful for macos as well #3307 |
UebelAndre
left a comment
There was a problem hiding this comment.
There's now a rust-lld target which has at least wasm-component-ld as a runfile. I think this is a better home for that but don't know exactly where objcopy should go. What about it's own filegroup and adding it as it's own optional attribute to rustc_toolchain?
I agree with you that it would be good to be a separate attribute of the toolchain for objcopy. It would simplify some parts as we have some custom rules for stripping targets. Unless @avrabe would do it. I could contribute that change. |
I'd be happy to review that from whoever wanted to put up the PR 😄 |
2b63294 to
3563a3d
Compare
|
Thanks for the feedback @UebelAndre - updated the approach:
@havasd thanks for the offer to contribute - I went ahead and made the changes. Hope this looks better now. |
3563a3d to
1720224
Compare
PR #3727 (bazelbuild/rules_rust#3727) is still open in upstream rules_rust. The previous commit incorrectly removed the fork override, breaking Windows builds. The fork at avrabe/rules_rust includes the fix that adds wasm-component-ld.exe to the rustc_lib filegroup, which is required for Windows WASM component builds. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Override rules_rust 0.68.1 with fork that fixes the bug where target_files parameter was ignored in _symlink_sysroot_tree. This ensures wasm-component-ld is symlinked into the sysroot, fixing Windows builds for wasm32-wasip2 targets. See: bazelbuild/rules_rust#3727 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
f34108f to
c30cafc
Compare
|
Updated with additional fixes for Commit 1: Add Commit 2: Fix sysroot construction for linker tools
These fixes enable |
PR #3727 (bazelbuild/rules_rust#3727) is still open in upstream rules_rust. The previous commit incorrectly removed the fork override, breaking Windows builds. The fork at avrabe/rules_rust includes the fix that adds wasm-component-ld.exe to the rustc_lib filegroup, which is required for Windows WASM component builds. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Override rules_rust 0.68.1 with fork that fixes the bug where target_files parameter was ignored in _symlink_sysroot_tree. This ensures wasm-component-ld is symlinked into the sysroot, fixing Windows builds for wasm32-wasip2 targets. See: bazelbuild/rules_rust#3727 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
7ae12cf to
e25e6cb
Compare
Adds `rust-objcopy` as a separate filegroup and optional attribute on `rust_toolchain`, following the same pattern as `rust-lld`. The filegroup is only generated when rust-objcopy is available (Rust 1.84.0+).
- Use target_files parameter instead of target.files in loop
- Place linker at lib/rustlib/{triple}/bin/ so rustc's PATH includes it
Fixes wasm-component-ld failing to find rust-lld on Windows.
Head branch was pushed to by a user without write access
e6d2f0e to
1241b83
Compare
|
Hi @UebelAndre - I think I accidentally disabled auto-merge when rebasing. All CI is green and I've addressed your feedback. Could you re-enable auto-merge or re-review when you get a chance? Thanks! |
UebelAndre
left a comment
There was a problem hiding this comment.
I'm so sorry about the delay here! Thank you so much for the change!
## Summary
Add `rust-objcopy` and `wasm-component-ld` to the `rustc_lib` filegroup
in `repository_utils.bzl`. These binaries are present in recent rustc
distributions (wasm-component-ld since 1.82.0, rust-objcopy since
1.84.0) but were not previously declared.
### Changes
- **Binary Declaration**: Add `rust-objcopy{binary_ext}` and
`wasm-component-ld{binary_ext}` to the rustc_lib filegroup glob patterns
### Context
On Windows, Bazel copies files into the sandbox rather than symlinking,
so only explicitly listed files are available. This caused wasm32-wasip2
builds to fail with `linker 'wasm-component-ld.exe' not found`.
On Linux/macOS, the issue was masked by symlink-based sandboxing which
allowed rustc to access unlisted files in the same directory.
---------
Co-authored-by: UebelAndre <github@uebelandre.com>
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).
## 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`.
Summary
Add
rust-objcopyandwasm-component-ldto therustc_libfilegroup inrepository_utils.bzl. These binaries are present in recent rustc distributions (wasm-component-ld since 1.82.0, rust-objcopy since 1.84.0) but were not previously declared.Changes
rust-objcopy{binary_ext}andwasm-component-ld{binary_ext}to the rustc_lib filegroup glob patternsContext
On Windows, Bazel copies files into the sandbox rather than symlinking, so only explicitly listed files are available. This caused wasm32-wasip2 builds to fail with
linker 'wasm-component-ld.exe' not found.On Linux/macOS, the issue was masked by symlink-based sandboxing which allowed rustc to access unlisted files in the same directory.