Skip to content

Conversation

@avrabe
Copy link
Contributor

@avrabe avrabe commented Nov 13, 2025

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.

@avrabe avrabe force-pushed the fix/add-missing-rustc-binaries branch from 738871d to b715cc7 Compare November 13, 2025 05:52
avrabe added a commit to pulseengine/rules_wasm_component that referenced this pull request Nov 13, 2025
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
avrabe added a commit to pulseengine/rules_wasm_component that referenced this pull request Nov 14, 2025
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
@avrabe avrabe force-pushed the fix/add-missing-rustc-binaries branch from b715cc7 to 030a4cf Compare December 4, 2025 05:55
Copy link
Collaborator

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

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

Thanks!

@illicitonion illicitonion force-pushed the fix/add-missing-rustc-binaries branch from 030a4cf to 2b63294 Compare December 15, 2025 20:57
@havasd
Copy link
Contributor

havasd commented Dec 27, 2025

@illicitonion is there anything which prevents this to be merged? this change is useful for macos as well #3307

Copy link
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.

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?

@havasd
Copy link
Contributor

havasd commented Dec 29, 2025

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.

@UebelAndre
Copy link
Collaborator

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 😄

@avrabe avrabe force-pushed the fix/add-missing-rustc-binaries branch from 2b63294 to 3563a3d Compare December 30, 2025 08:34
@avrabe
Copy link
Contributor Author

avrabe commented Dec 30, 2025

Thanks for the feedback @UebelAndre - updated the approach:

  • Removed wasm-component-ld from rustc_lib (now covered by rust-lld's *-ld glob)
  • Added rust-objcopy as its own filegroup + optional toolchain attribute

@havasd thanks for the offer to contribute - I went ahead and made the changes. Hope this looks better now.

Adds `rust-objcopy` as a separate filegroup and optional attribute on
`rust_toolchain`, following the same pattern as `rust-lld`.

The filegroup uses `allow_empty = True` for compatibility with Rust
versions before 1.84.0 where the binary is not available.
@avrabe avrabe force-pushed the fix/add-missing-rustc-binaries branch from 3563a3d to 1720224 Compare December 30, 2025 08:40
avrabe added a commit to pulseengine/rules_wasm_component that referenced this pull request Dec 31, 2025
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>
avrabe added a commit to pulseengine/rules_wasm_component that referenced this pull request Dec 31, 2025
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>
- 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.
@avrabe avrabe force-pushed the fix/add-missing-rustc-binaries branch from f34108f to c30cafc Compare December 31, 2025 15:38
@avrabe
Copy link
Contributor Author

avrabe commented Dec 31, 2025

Updated with additional fixes for wasm-component-ld support:

Commit 1: Add rust-objcopy as optional toolchain attribute (as requested)

Commit 2: Fix sysroot construction for linker tools

  • _symlink_sysroot_tree was ignoring the target_files parameter, using target.files instead - this prevented wasm-component-ld and gcc-ld/* from being symlinked into the sysroot
  • The linker was placed at {sysroot}/bin/ but rustc adds {sysroot}/lib/rustlib/{host}/bin/ to PATH when invoking linkers (rustc source). Now extracts the correct path from the source location.

wasm-component-ld searches PATH for wasm-ld or rust-lld (source), so the linker must be in the directory that rustc adds to PATH.

These fixes enable wasm-component-ld to find rust-lld on Windows where Bazel's manifest-based runfiles don't provide the same fallback paths as Unix symlinks.

avrabe added a commit to pulseengine/rules_wasm_component that referenced this pull request Dec 31, 2025
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>
avrabe added a commit to pulseengine/rules_wasm_component that referenced this pull request Dec 31, 2025
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>
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.

4 participants