Stream: wasmtime

Topic: Passing data structures


view this post on Zulip Alistair Cunningham (Apr 03 2024 at 20:23):

What's the latest recommendation and best practice for passing anything other than integers between the host and the WASM guest? Is the trick of passing a pointer and a length in the guest's memory still the best? Or perhaps handling the guest's stdin and stdout using WASI? Or something else?

view this post on Zulip Alistair Cunningham (Apr 03 2024 at 20:23):

How should data be formatted? Perhaps using BSON? I'll definitely need to pass strings and arrays of strings, and perhaps structs too.

view this post on Zulip Lann Martin (Apr 03 2024 at 20:39):

The latest recommendation here would be to use the component model, which supports complex data types: https://component-model.bytecodealliance.org/design/wit.html

view this post on Zulip Alistair Cunningham (Apr 03 2024 at 21:56):

Thank you Lann. Does this exist for Go?

view this post on Zulip Alistair Cunningham (Apr 03 2024 at 22:50):

Is there anything like Extism for Wasmtime?

view this post on Zulip fitzgen (he/him) (Apr 04 2024 at 00:02):

wit-bindgen can create bindings for tinygo: https://github.com/bytecodealliance/wit-bindgen/?tab=readme-ov-file#guest-tinygo

I believe mainline go is WIP, but they don't allow go programs to export arbitrary functions at the wasm level, which is a bit of a blocker IIUC

also fwiw, it seems like extism is built on top of wasmtime: https://github.com/extism/extism/blob/9aa817def7a1616629e30862c93d9ec68f774f7c/runtime/Cargo.toml#L12

A language binding generator for WebAssembly interface types - bytecodealliance/wit-bindgen
The framework for building with WebAssembly (wasm). Easily load wasm modules, move data, call functions, and build extensible apps. - extism/extism

view this post on Zulip Alistair Cunningham (Apr 04 2024 at 12:39):

Thank you fitzgen, I'll take a look at these.

view this post on Zulip Alistair Cunningham (Apr 04 2024 at 12:41):

The other thing I was thinking of doing was open two named pipes using mkfifo() in WASI, one for each direction, and passing BSON or JSON messages between host and guest using them. Has anyone tried this?

view this post on Zulip Alistair Cunningham (Apr 04 2024 at 12:43):

Of course doing this would require having file access in WASI working, which I haven't yet managed in Wasmtime (see my "Writing files using WASI PreopenDir()" post).


Last updated: Nov 22 2024 at 16:03 UTC