Skip to content

Commit 88442a8

Browse files
committed
fix: Use wit-bindgen-rt crate instead of wit-bindgen for runtime support
The wit-bindgen crate (v0.47.0) is for procedural macros (generate!()). For CLI-generated bindings, we need wit-bindgen-rt (v0.39.0) which provides: - export! macro for component exports - wit_bindgen::rt module with proper allocator integration Changes: - tools/checksum_updater/Cargo.toml: Added wit-bindgen-rt = "0.39.0" - rust/rust_wasm_component_bindgen.bzl: Changed wrapper to use wit_bindgen_rt - rust/rust_wasm_component_bindgen.bzl: Changed deps to @crates//:wit-bindgen-rt - MODULE.bazel: Updated comment to reflect wit-bindgen-rt usage - docs/embedded_runtime_fix.md: Updated documentation Fixes error: could not find `export` in bindings crate
1 parent 7f621c3 commit 88442a8

File tree

4 files changed

+36
-21
lines changed

4 files changed

+36
-21
lines changed

MODULE.bazel

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,11 @@ crate.from_cargo(
282282
],
283283
)
284284

285-
# Note: wit-bindgen crate is available from checksum_updater/Cargo.toml (version 0.47.0)
286-
# It provides the proper wit_bindgen::rt module for generated bindings instead of embedded stubs
285+
# Note: wit-bindgen-rt crate is available from checksum_updater/Cargo.toml (version 0.39.0)
286+
# It provides the proper runtime support for CLI-generated bindings:
287+
# - export! macro for component exports
288+
# - wit_bindgen::rt module with correct allocator integration
289+
# This replaces the previously embedded runtime stubs
287290

288291
use_repo(crate, "crates", "ssh_keygen_crates", "wasm_embed_aot_crates", "wasmsign2_crates", "wizer_crates")
289292

docs/embedded_runtime_fix.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,42 @@ The `rust_wasm_component_bindgen` rule had embedded **broken runtime stubs** for
2525

2626
### Changes Made
2727

28-
#### 1. Used Existing wit-bindgen Crate Dependency
28+
#### 1. Added wit-bindgen-rt Runtime Crate
2929

30-
The `wit-bindgen` crate (version 0.47.0) is already available from `tools/checksum_updater/Cargo.toml`:
30+
The `wit-bindgen-rt` crate provides runtime support for CLI-generated bindings. Added to `tools/checksum_updater/Cargo.toml`:
3131

3232
```toml
3333
[dependencies]
34-
wit-bindgen = "0.47.0"
34+
wit-bindgen = "0.47.0" # For proc macro usage
35+
wit-bindgen-rt = "0.39.0" # Runtime support (export macro, allocator, etc)
3536
```
3637

37-
This is automatically available as `@crates//:wit-bindgen` through the crates repository.
38+
This is automatically available as `@crates//:wit-bindgen-rt` through the crates repository.
3839

39-
#### 2. Simplified Runtime Wrapper (rust/rust_wasm_component_bindgen.bzl:58-76)
40+
**Key distinction**:
41+
- `wit-bindgen` = Procedural macro crate for `generate!()` macro
42+
- `wit-bindgen-rt` = Runtime crate for CLI-generated bindings (what we need)
43+
44+
#### 2. Simplified Runtime Wrapper (rust/rust_wasm_component_bindgen.bzl:58-79)
4045

4146
**Before**: 114 lines of embedded runtime stubs
42-
**After**: 4 lines of simple re-export
47+
**After**: 6 lines of simple re-exports
4348

4449
```rust
45-
// Re-export the real wit-bindgen crate to provide proper runtime implementation
50+
// Re-export wit-bindgen-rt as wit_bindgen to provide proper runtime implementation
4651
// The wit-bindgen CLI generates code that expects: crate::wit_bindgen::rt
47-
pub use wit_bindgen;
52+
pub use wit_bindgen_rt as wit_bindgen;
53+
54+
// Re-export the export macro at crate level for convenience
55+
pub use wit_bindgen_rt::export;
4856
```
4957

50-
#### 3. Added Dependencies to Bindings Libraries (lines 315, 326)
58+
#### 3. Added Dependencies to Bindings Libraries (lines 326, 337)
5159

52-
Both host and WASM bindings libraries now depend on the real crate:
60+
Both host and WASM bindings libraries now depend on the runtime crate:
5361

5462
```starlark
55-
deps = ["@crates//:wit-bindgen"], # Provide real wit-bindgen runtime
63+
deps = ["@crates//:wit-bindgen-rt"], # Provide wit-bindgen runtime (export macro, allocator)
5664
```
5765

5866
#### 4. Removed Complex Filtering Logic

rust/rust_wasm_component_bindgen.bzl

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,25 @@ def _generate_wrapper_impl(ctx):
5555
"""Generate a wrapper that includes both bindings and runtime shim"""
5656
out_file = ctx.actions.declare_file(ctx.label.name + ".rs")
5757

58-
# Create wrapper content - re-export the real wit-bindgen crate
58+
# Create wrapper content - re-export wit-bindgen-rt as wit_bindgen
5959
# The wit-bindgen CLI generates code that expects: crate::wit_bindgen::rt
60-
# Instead of embedding broken runtime stubs, we use the real wit-bindgen crate
60+
# wit-bindgen-rt provides the runtime support (export macro, allocator, etc)
6161
wrapper_content = """// Generated wrapper for WIT bindings
6262
//
63-
// This wrapper re-exports the wit-bindgen crate to provide the runtime
63+
// This wrapper re-exports wit-bindgen-rt as wit_bindgen to provide the runtime
6464
// at the path expected by wit-bindgen CLI (--runtime-path crate::wit_bindgen::rt)
6565
6666
// Suppress clippy warnings for generated code
6767
#![allow(clippy::all)]
6868
#![allow(unused_imports)]
6969
#![allow(dead_code)]
7070
71-
// Re-export the real wit-bindgen crate to provide proper runtime implementation
72-
// This provides wit_bindgen::rt with correct allocator integration
73-
pub use wit_bindgen;
71+
// Re-export wit-bindgen-rt as wit_bindgen to provide proper runtime implementation
72+
// This provides the export! macro, rt module with correct allocator integration
73+
pub use wit_bindgen_rt as wit_bindgen;
74+
75+
// Re-export the export macro at crate level for convenience
76+
pub use wit_bindgen_rt::export;
7477
7578
// Generated bindings follow:
7679
"""
@@ -320,7 +323,7 @@ def rust_wasm_component_bindgen(
320323
crate_name = name.replace("-", "_") + "_bindings",
321324
edition = "2021",
322325
visibility = visibility, # Make native bindings publicly available
323-
deps = ["@crates//:wit-bindgen"], # Provide real wit-bindgen runtime
326+
deps = ["@crates//:wit-bindgen-rt"], # Provide wit-bindgen runtime (export macro, allocator)
324327
)
325328

326329
# Create a separate WASM bindings library using guest wrapper
@@ -331,7 +334,7 @@ def rust_wasm_component_bindgen(
331334
crate_name = name.replace("-", "_") + "_bindings",
332335
edition = "2021",
333336
visibility = ["//visibility:private"],
334-
deps = ["@crates//:wit-bindgen"], # Provide real wit-bindgen runtime
337+
deps = ["@crates//:wit-bindgen-rt"], # Provide wit-bindgen runtime (export macro, allocator)
335338
)
336339

337340
# Create a WASM-transitioned version of the WASM bindings library

tools/checksum_updater/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }
3232
tempfile = "3.23"
3333
async-trait = "0.1"
3434
wit-bindgen = "0.47.0" # WIT binding generation for macro usage
35+
wit-bindgen-rt = "0.39.0" # Runtime support for CLI-generated bindings (export macro, allocator, etc)
3536
uuid = { version = "1.18", default-features = false } # UUID generation for user service (deterministic, no getrandom dependency)
3637

3738
[dev-dependencies]

0 commit comments

Comments
 (0)