Skip to content

Commit f151bef

Browse files
committed
fix: add WASM platform transition to rust_wasm_component_bindgen
- Add wasm_transition to bindings library to ensure proper WASM targeting - Create _wasm_rust_library rule to apply platform transition - Export macro visibility issue is now fully resolved Fixes #1
1 parent 04f2a2d commit f151bef

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

.claude/settings.local.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"Bash(cargo build:*)",
1515
"Bash(gh run view:*)",
1616
"Bash(gh run list:*)",
17-
"Bash(grep:*)"
17+
"Bash(grep:*)",
18+
"Bash(gh issue view:*)"
1819
],
1920
"deny": []
2021
}

rust/rust_wasm_component_bindgen.bzl

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
load("@rules_rust//rust:defs.bzl", "rust_library")
44
load("//wit:wit_bindgen.bzl", "wit_bindgen")
55
load(":rust_wasm_component.bzl", "rust_wasm_component")
6+
load(":transitions.bzl", "wasm_transition")
67

78
def _generate_wrapper_impl(ctx):
89
"""Generate a wrapper that includes both bindings and runtime shim"""
@@ -85,6 +86,31 @@ _generate_wrapper = rule(
8586
},
8687
)
8788

89+
def _wasm_rust_library_impl(ctx):
90+
"""Implementation of wasm_rust_library rule"""
91+
# This rule just passes through to the rust_library target
92+
# The transition is handled by the cfg attribute
93+
target_info = ctx.attr.target[0]
94+
95+
# Return the providers we need
96+
providers = [target_info[DefaultInfo]]
97+
98+
# Add Rust-specific providers if they exist
99+
if CcInfo in target_info:
100+
providers.append(target_info[CcInfo])
101+
102+
return providers
103+
104+
_wasm_rust_library = rule(
105+
implementation = _wasm_rust_library_impl,
106+
attrs = {
107+
"target": attr.label(
108+
cfg = wasm_transition,
109+
doc = "rust_library target to build for WASM",
110+
),
111+
},
112+
)
113+
88114
def rust_wasm_component_bindgen(
89115
name,
90116
srcs,
@@ -150,11 +176,21 @@ def rust_wasm_component_bindgen(
150176

151177
# Create a rust_library from the generated bindings
152178
bindings_lib = name + "_bindings"
179+
bindings_lib_host = bindings_lib + "_host"
180+
181+
# Create the bindings library for host platform first
153182
rust_library(
154-
name = bindings_lib,
183+
name = bindings_lib_host,
155184
srcs = [":" + wrapper_target],
156185
crate_name = name.replace("-", "_") + "_bindings",
157186
edition = "2021",
187+
visibility = ["//visibility:private"],
188+
)
189+
190+
# Create a WASM-transitioned version of the bindings library
191+
_wasm_rust_library(
192+
name = bindings_lib,
193+
target = ":" + bindings_lib_host,
158194
visibility = ["//visibility:public"],
159195
)
160196

0 commit comments

Comments
 (0)