Skip to content

Commit f4cbfaa

Browse files
authored
wit-bindgen-rust: link component type for imports. (#542)
* wit-bindgen-rust: link component type for imports. This commit forces a reference to the component type in import sub-modules. It fixes an issue when building bindings to a different crate and only referencing an import binding. As there was no reference to `__link_section`, the generated core module from the LLVM toolchain was missing the component type custom section. The fix simply performs what we're already doing for exports in the `export!` macro, but adds the reference to each generated import submodule. * Use `super` instead of `crate` for referencing `__link_section` in imports.
1 parent 483f92e commit f4cbfaa

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

crates/rust/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,7 @@ impl WorldGenerator for RustWasm {
230230
#[used]
231231
#[doc(hidden)]
232232
#[cfg(target_arch = \"wasm32\")]
233-
static __FORCE_SECTION_REF: fn() = __force_section_ref;
234-
#[doc(hidden)]
235-
#[cfg(target_arch = \"wasm32\")]
236-
fn __force_section_ref() {{
237-
{prefix}__link_section()
238-
}}
233+
static __FORCE_SECTION_REF: fn() = {prefix}__link_section;
239234
}});
240235
",
241236
prefix = self.opts.macro_call_prefix.as_deref().unwrap_or("")
@@ -377,9 +372,14 @@ impl InterfaceGenerator<'_> {
377372
"
378373
#[allow(clippy::all)]
379374
pub mod {snake} {{
375+
#[used]
376+
#[doc(hidden)]
377+
#[cfg(target_arch = \"wasm32\")]
378+
static __FORCE_SECTION_REF: fn() = super::__link_section;
379+
380380
{module}
381381
}}
382-
"
382+
",
383383
);
384384
}
385385

0 commit comments

Comments
 (0)