Stream: general

Topic: Expected format for `wit-bindgen host js`


view this post on Zulip Fabrice Desré (Jan 20 2023 at 02:02):

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

view this post on Zulip Peter Huene (Jan 20 2023 at 04:57):

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.

view this post on Zulip Fabrice Desré (Jan 20 2023 at 05:03):

ok, so in the case of the demo, was the wit file also generated from this component? If so, how?

view this post on Zulip Alex Crichton (Jan 20 2023 at 05:13):

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

view this post on Zulip Alex Crichton (Jan 20 2023 at 05:14):

You can inspect the wasm outputs and see one should be full of unused imports and functions that only have unreachable instructions

view this post on Zulip Fabrice Desré (Jan 20 2023 at 06:37):

ok, but what command is used to go from .wit -> core wasm & component?

view this post on Zulip Alex Crichton (Jan 20 2023 at 15:36):

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: Oct 23 2024 at 20:03 UTC