Skip to content

Commit 0ea155b

Browse files
committed
fix: apply WASM transition to rust_shared_library in component builds
- Add _wasm_rust_shared_library wrapper rule to properly apply wasm_transition - Fix target triple mismatch where host components tried to link WASM bindings - Remove legacy hermetic toolchain files and unused BUILD.* files - Fix wit_deps_check.bzl stdout parameter issue - Add comprehensive toolchain configuration documentation guide Fixes component builds that were failing with target triple mismatches between aarch64-apple-darwin (host) and wasm32-wasip2 (component bindings).
1 parent d72c587 commit 0ea155b

File tree

13 files changed

+616
-3530
lines changed

13 files changed

+616
-3530
lines changed

docs-site/src/content/docs/guides/toolchain-configuration.md

Lines changed: 580 additions & 0 deletions
Large diffs are not rendered by default.

rust/rust_wasm_component.bzl

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,32 @@ load("//providers:providers.bzl", "WasmComponentInfo", "WitInfo")
66
load("//tools/bazel_helpers:wasm_tools_actions.bzl", "check_is_component_action")
77
load(":transitions.bzl", "wasm_transition")
88

9+
def _wasm_rust_shared_library_impl(ctx):
10+
"""Implementation that forwards a rust_shared_library with WASM transition applied"""
11+
target_info = ctx.attr.target[0]
12+
13+
# Forward DefaultInfo and RustInfo
14+
providers = [target_info[DefaultInfo]]
15+
16+
# Forward RustInfo if available
17+
if hasattr(target_info, "rust_info"):
18+
providers.append(target_info.rust_info)
19+
20+
return providers
21+
22+
_wasm_rust_shared_library = rule(
23+
implementation = _wasm_rust_shared_library_impl,
24+
attrs = {
25+
"target": attr.label(
26+
cfg = wasm_transition,
27+
doc = "rust_shared_library target to build for WASM",
28+
),
29+
"_allowlist_function_transition": attr.label(
30+
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
31+
),
32+
},
33+
)
34+
935
def _rust_wasm_component_impl(ctx):
1036
"""Implementation of rust_wasm_component rule"""
1137

@@ -174,8 +200,10 @@ def rust_wasm_component(
174200
# Filter out conflicting kwargs to avoid multiple values for parameters
175201
filtered_kwargs = {k: v for k, v in kwargs.items() if k not in ["tags", "visibility"]}
176202

203+
# Create the host-platform rust_shared_library first
204+
host_library_name = rust_library_name + "_host"
177205
rust_shared_library(
178-
name = rust_library_name,
206+
name = host_library_name,
179207
srcs = all_srcs,
180208
crate_root = crate_root,
181209
deps = all_deps,
@@ -187,6 +215,12 @@ def rust_wasm_component(
187215
**filtered_kwargs
188216
)
189217

218+
# Apply WASM transition to get actual WASM module
219+
_wasm_rust_shared_library(
220+
name = rust_library_name,
221+
target = ":" + host_library_name,
222+
)
223+
190224
# Convert to component for this profile
191225
component_name = "{}_{}".format(name, profile)
192226
_rust_wasm_component_rule(

toolchains/BUILD.hermetic

Lines changed: 0 additions & 33 deletions
This file was deleted.

toolchains/BUILD.nixpkgs

Lines changed: 0 additions & 57 deletions
This file was deleted.

toolchains/BUILD.wasm_tools_bazel

Lines changed: 0 additions & 47 deletions
This file was deleted.

toolchains/BUILD.wizer_bazel

Lines changed: 0 additions & 41 deletions
This file was deleted.

toolchains/bazel_tools_deps/BUILD.bazel

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)