I have a world.wit comprising function as well as type definitions. Futhermore, there is a corresponding component which I would like to use from a Rust host. There are no problems in calling the functions but somehow the host does not recognize the types, e.g. the following does not compile:
interface decoding {
record test {
t1: u32,
}
record r {
a: u32,
b: string,
}
// [..]
}
default world decoder {
export exports: self.decoding
}
// Cargo.toml: wasmtime = { version = "8", features = ["component-model"] }
wasmtime::component::bindgen!("world" in "../app/wit/world.wit");
use exports::{R, Test};
|
27 | use exports::{R, Test};
| ^ ^^^^ no `Test` in `exports`
| |
| no `R` in `exports`
| help: a similar name exists in the module: `_`
Is my expectation right that the host should be able to recognize and use types defined in a .wit?
Is there any obvious error or anything specific I have to consider in order to make the host recognize the types from my .wit?
see the out-of-line example here https://github.com/WebAssembly/component-model/blob/main/design/mvp/WIT.md#wit-worlds
I think it should work if you just remove your self.
mmhh.. removal of self.
, like,
default world decoder {
export exports: decoding
}
results in
error: expected '.', found '}'
--> ../app/wit/world.wit:45:1
|
45 | }
| ^
--> decoder/src/lib.rs:23:1
|
23 | wasmtime::component::bindgen!("world" in "../app/wit/world.wit");
ah no, sorry, your export should be in the form of export decoding
, if you want to rename that you need something like use decoding as exports; export exports
according to the documentation I linked
Thank you for your feedback. Unfortunately, I cannot positively reproduce your suggestions. I am aware of the provided documentation, though. When I try to craft a minimal working example I observe that even the snippets from the documentation do not seem to pass.
[Disclaimer: updated dependency to wasmtime 9]
The syntax has changed to the new form a few weeks ago and the example you look at might still be outdated. The new wit-bindgen for sure does neither accept nor need self.
Sorry that I have to contradict. The following compiles:
interface decoding {
record test {
t1: u32,
}
}
default world decoder {
export exports: self.decoding
}
With the (only) dependency in Cargo.toml:
wasmtime = { version = "9.0.4", features = ["component-model"] }
Everything else, I do not even get compiling. Helas, given example does not recognize the record.
Having said that I wonder if we may talk about different things: wasmtime
vs. wit-bindgen
?
When implementing the guest/component implementation, I use wit-bindgen = "0.6.0"
but in order to deal with the component from the Rust host I have a dependency to wasmtime
as mentioned above. Is it supposed to be done differently?
:face_with_peeking_eye: should have posted in channel wasmtime then, didn't I?
Christoph Brewing has marked this topic as resolved.
Last updated: Nov 22 2024 at 16:03 UTC