Stream: general

Topic: using wit-bindgen in rust


view this post on Zulip Ralph Deters (Jan 22 2023 at 15:36):

Hello,
Where can I find an example of "how to use the new wit / bindgen!"? the ones I found don't seem to work with the new version. I am interested in something that defines import and export functions for a webassemly (in rust) and shows how to use the webassembly in a (rust) host program.

view this post on Zulip Ramon Klass (Jan 22 2023 at 18:15):

did you find an example? This is the latest I could find but it's outdated already
https://blog.mediosz.club/2022/11/17/how-to-use-wit-bindgen/

view this post on Zulip Ramon Klass (Jan 22 2023 at 18:28):

I should clarify that it does work but I can't get a component that uses wasi to run

view this post on Zulip r-muhairi (Jan 22 2023 at 18:36):

There is a demo showcasing rust-guest,
https://github.com/bytecodealliance/wit-bindgen/tree/main/crates/wit-bindgen-demo

For rust as a host using wasmtime::Component::bindgen! provided by the (feature=component-model) look at the tests,
and ensure you explicitly enable it in the engine through setting

        let mut config = Config::new();
        Config::wasm_component_model(&mut config, true);
        let engine = Engine::new(&config).unwrap();
A language binding generator for WebAssembly interface types - wit-bindgen/crates/wit-bindgen-demo at main · bytecodealliance/wit-bindgen

view this post on Zulip Notification Bot (Jan 22 2023 at 19:53):

Ralph Deters has marked this topic as unresolved.

view this post on Zulip Ralph Deters (Jan 22 2023 at 19:56):

hello ramon,:
yes, I liked the example, but as you said it is a bit outdated. I am looking for the "updated version".

view this post on Zulip Ralph Deters (Jan 22 2023 at 20:20):

hello r-muhairi,
Thanks for the links. unfortunately, I couldn't see how a rust host interacts with the webassembly e.g. calls a function in the webassembly.

view this post on Zulip r-muhairi (Jan 22 2023 at 21:26):

Ralph Deters said:

hello r-muhairi,
Thanks for the links. unfortunately, I couldn't see how a rust host interacts with the webassembly e.g. calls a function in the webassembly.

I've fixed the demo and changed it to only include the rust host,

my fork can be found here:
https://github.com/r-muhairi/component-model-demo

Reasoning behind changing the wit file so that the markdown world became an interface as opposed to world and introducing a new world called renderer:

It seems i couldn't export a function directly? It wasn't generating an export macro doing this

default world markdown {
  export render: func(markdown: string) -> string
}
This repository demonstrate how to use component model with wasmtime. - GitHub - r-muhairi/component-model-demo: This repository demonstrate how to use component model with wasmtime.

view this post on Zulip Ralph Deters (Jan 23 2023 at 02:04):

hello r-muhairi,
thanks for your help and the great example - it works perfectly.

view this post on Zulip Pat Hickey (Jan 23 2023 at 18:58):

wit-bindgen is not really stable for use yet, its constantly changing & breaking compatibility, so we haven't written any documentation for using it yet and don't encourage production use yet

view this post on Zulip r-muhairi (Jan 23 2023 at 19:34):

Thanks for the words of warning,

Yeah the blog author failed to raise that point, I personally am fully aware of that just experimenting with them at the moment, planning on contributing as well.


Last updated: Dec 23 2024 at 12:05 UTC