I'm trying to generate the JS host for a WIT world but I can´t figure out which input it expects. Passing the *.wit file such as the one in https://bytecodealliance.github.io/wit-bindgen/ fails with
Error: expected `(`
--> demo.wit:1:1
|
1 | interface host-funcs {
| ^
Using a wat file also fails ("attempted to parse a wasm module with a component parser").
I believe the JS host bindings expect a WebAssembly component as input, which it infers the world from. It needs the component because it generates some glue (polyfills what a component-model-native host like Wasmtime would do) that depends on the inner core modules of the component.
ok, so in the case of the demo, was the wit file also generated from this component? If so, how?
The demo takes a wit, synthesizes a dummy core wasm module that implements the world, then makes a component with all that, and then runs the js bindings over that component output
You can inspect the wasm outputs and see one should be full of unused imports and functions that only have unreachable instructions
ok, but what command is used to go from .wit -> core wasm & component?
With the latest wasm-tools
CLI you can do:
$ wasm-tools component embed foo.wit --dummy --world foo | wasm-tools component new -t
where foo.wit
looks like:
default world foo {}
and that'll print out the component (in the wasm text format)
Last updated: Dec 23 2024 at 12:05 UTC