Generate component with only specified interfaces
Hi everyone!
I'm not 100% sure if this is the right place to ask this question or if it maybe is a more of a rustc problem.
In any case: I'm trying to generate a component that implements a certain interface and only that interface.
Consider this example:
wit_bindgen::generate!({
inline: r#"
package foo:bar;
world bar {
export baz : interface {
zero: func() -> u32;
}
}
"#
});
struct MyComponent;
impl crate::exports::baz::Guest for MyComponent {
fn zero() -> u32 {
0
}
}
export!(MyComponent);
Given this code, I would expect the wit embedded in the resulting component to look similar to this
package root:component;
world root {
export baz: interface {
zero: func() -> u32;
}
}
Instead, wasm-tools component wit target/wasm32-wasip2/debug/super_simplest.wasm outputs
package root:component;
world root {
import wasi:cli/[email protected];
import wasi:cli/[email protected];
import wasi:io/[email protected];
import wasi:io/[email protected];
import wasi:cli/[email protected];
import wasi:cli/[email protected];
import wasi:cli/[email protected];
import wasi:clocks/[email protected];
import wasi:filesystem/[email protected];
import wasi:filesystem/[email protected];
export baz: interface {
zero: func() -> u32;
}
}
// + all package definitions of imported packages
My guess was that these imports are necessary to handle stuff like error messages on panic that the rust compiler might introduce. However, compiling while declaring the #![no_std] (which I assumed to disable these things) at the top of lib.rs does not help and the same wit is embedded.
Is there a way to only generate the interface as specified?
I'm using wit-bindgen 0.42.1, cargo/rustc 1.87.0-nightly, and wasm-tools 1.219.1.
Cheers, Markus
P.S.: After writing this issue I tried everything out with the code mentioned here and have encountered the same problem.
I believe you want to use cargo build --target wasm32-unknown-unknown ...