I had a running real-world application based on Rust/WASM. Let's call it a decoder. Before I fell into the black (summer) hole, everything was fine, compiling, executing ...
I was working on wasmtime = { version = "10", features = ["component-model"] }
and wit-bindgen = "0.9"
.
Now, after an upgrade to wasmtime = { version = "13", features = ["component-model"] }
and wit-bindgen = "0.12"
I get compilation errors. My world.wit looks like
package decoder:api
interface decode {
[..]
}
world decoder {
export decode
}
I try to use
it like
use crate::exports::decoder::api::decode::*;
// [..]
wit_bindgen::generate!(in "wit/world.wit");
// [..]
struct Decoder;
export_decoder!(Decoder);
The errors are
error: no `exports` map provided in configuration but key is required for `decoder:api/decode`
--> src/lib.rs:25:1
|
25 | wit_bindgen::generate!(in "wit/world.wit");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `wit_bindgen::generate` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0433]: failed to resolve: could not find `exports` in the crate root
--> src/lib.rs:23:12
|
23 | use crate::exports::decoder::api::decode::{DecodeReturn, SignalHandle};
| ^^^^^^^ could not find `exports` in the crate root
error: cannot find macro `export_decoder` in this scope
--> src/lib.rs:47:1
|
47 | export_decoder!(Decoder);
| ^^^^^^^^^^^^^^
error[E0433]: failed to resolve: could not find `exports` in the crate root
--> src/lib.rs:59:13
|
59 | impl crate::exports::decoder::api::decode::Decode for Decoder {
| ^^^^^^^ could not find `exports` in the crate root
I guess, it does not take much to get it compiling again. However, I do not understand what to change.
Also, in order to avoid this kind of question in the future, is there any place I can have a look in the docs?
Thanks a lot for any hint!
The syntax for generate!
has changed in the meantime. It looks like the errors you're seeing are from a Rust guest compiled to WebAssembly, so I'd recommending looking at the documentation for Rust support for more guidance
So I tried the first two examples after having installed cargo component:
The first compiles as described. The second one is more relevant for me since me too, I try to export an interface. However, it yields the following error:
$ cargo component build --release
Encoding target for add (add/target/bindings/add/target.wasm)
Compiling add v0.1.0 add)
error[E0432]: unresolved import `super`
--> src/lib.rs:3:1
|
3 | cargo_component_bindings::generate!();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `Component` in the root
|
= note: this error originates in the macro `cargo_component_bindings::generate` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this enum instead
|
3 | std::path::Component as _GuestImpl;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For the second example I have reused the project from the first example, just replaced world.wit and lib.rs.
Is it meant to work this way?
@Christoph Brewing cargo_component_bindings::generate!
assumes the implementation to be at super::Component
(relative to bindings module generated by the macro). However, you can override it using the implementor
argument to the macro; see https://github.com/bytecodealliance/cargo-component/issues/149 for an example!
Thanks! The combination of hints made it work for me.
Christoph Brewing has marked this topic as resolved.
Last updated: Dec 23 2024 at 12:05 UTC