Stream: wit-bindgen

Topic: ✔ interface types not recognized


view this post on Zulip Christoph Brewing (Jun 19 2023 at 14:25):

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?

view this post on Zulip Ramon Klass (Jun 19 2023 at 14:33):

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.

Repository for design and specification of the Component Model - component-model/design/mvp/WIT.md at main · WebAssembly/component-model

view this post on Zulip Christoph Brewing (Jun 19 2023 at 14:51):

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");

view this post on Zulip Ramon Klass (Jun 19 2023 at 14:55):

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

view this post on Zulip Christoph Brewing (Jun 20 2023 at 07:53):

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]

Minimal example of wasmtime about generating the wit for a component - GitHub - Finfalter/componenthost: Minimal example of wasmtime about generating the wit for a component

view this post on Zulip Christof Petig (Jun 20 2023 at 08:16):

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.

view this post on Zulip Christoph Brewing (Jun 20 2023 at 08:50):

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.

view this post on Zulip Christoph Brewing (Jun 20 2023 at 08:56):

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?

view this post on Zulip Notification Bot (Jun 26 2023 at 13:30):

Christoph Brewing has marked this topic as resolved.


Last updated: Dec 23 2024 at 12:05 UTC