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.
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/
I should clarify that it does work but I can't get a component that uses wasi to run
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();
Ralph Deters has marked this topic as unresolved.
hello ramon,:
yes, I liked the example, but as you said it is a bit outdated. I am looking for the "updated version".
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.
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
}
hello r-muhairi,
thanks for your help and the great example - it works perfectly.
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
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