Skip to content

Commit 071e0c1

Browse files
committed
fix: Create proper nested module structure for wit_bindgen::rt
The generated code expects crate::wit_bindgen::rt::run_ctors_once() but the previous implementation only did `pub use wit_bindgen_rt as wit_bindgen;` which made wit_bindgen an alias, not a module with an rt submodule. Fixed by creating the proper nested structure: pub mod wit_bindgen { pub use wit_bindgen_rt as rt; } This provides: - crate::wit_bindgen (module) - crate::wit_bindgen::rt (wit_bindgen_rt crate) Fixes error: error[E0433]: failed to resolve: could not find `rt` in `wit_bindgen` --> hello_component_wrapper_guest.rs:113:29 | 113 | crate::wit_bindgen::rt::run_ctors_once(); | ^^ could not find `rt` in `wit_bindgen`
1 parent 7e6f934 commit 071e0c1

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

rust/rust_wasm_component_bindgen.bzl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,14 @@ 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 wit-bindgen-rt as wit_bindgen
58+
# Create wrapper content - create nested module structure for wit-bindgen-rt
5959
# The wit-bindgen CLI generates code that expects: crate::wit_bindgen::rt
6060
# The CLI also generates the export! macro with --pub-export-macro flag
6161
wrapper_content = """// Generated wrapper for WIT bindings
6262
//
63-
// This wrapper re-exports wit-bindgen-rt as wit_bindgen to provide the runtime
64-
// at the path expected by wit-bindgen CLI (--runtime-path crate::wit_bindgen::rt)
63+
// This wrapper creates a wit_bindgen module with rt submodule that re-exports
64+
// wit-bindgen-rt crate. This provides the runtime at the path expected by
65+
// wit-bindgen CLI (--runtime-path crate::wit_bindgen::rt)
6566
//
6667
// The export! macro is generated by wit-bindgen CLI (via --pub-export-macro)
6768
@@ -70,9 +71,11 @@ def _generate_wrapper_impl(ctx):
7071
#![allow(unused_imports)]
7172
#![allow(dead_code)]
7273
73-
// Re-export wit-bindgen-rt as wit_bindgen to provide the runtime module
74-
// This provides wit_bindgen::rt with proper allocator integration
75-
pub use wit_bindgen_rt as wit_bindgen;
74+
// Create nested module structure: wit_bindgen::rt
75+
// The wit-bindgen CLI expects crate::wit_bindgen::rt::run_ctors_once() etc.
76+
pub mod wit_bindgen {
77+
pub use wit_bindgen_rt as rt;
78+
}
7679
7780
// Generated bindings follow (including export! macro):
7881
"""

0 commit comments

Comments
 (0)