Hello, would anyone happen to have any examples of using wasm_bindgen_multi_value_xform
in their wasmtime
project? I'm interested in usng it in my project, but I'm not actually sure how I'm supposed to use it from the Rust side.
AFAIK, it has never been used outside of wasm-bindgen
, and was written very specifically for wasm-bindgen
, so I wouldn't put too much hope in using it outside that context
@fitzgen (he/him) Thank you for your reply, would you happen to know how are you supposed to use it in wasm_bindgen? There isn't any documentation for that as far as I can find.
Also Relatedly: Are you supposed to use wasm-bindgen
when you're trying to define your own API for modules that are run with wasmtime
? It seems heavily JavaScript and browser focused, where as I'm just looking to have modules with two functions (e.g. read
and write
) on the WASM side, which the host calls with a struct and then copy the object back to the host.
My current approach since WIT is not available, is to send everything as bytes, so I was trying to have read
and write
return (ptr: i32, len: i32)
to know where the bytes were in the wasmtime
memory.
No wasm-bindgen
is not intended to be used with wasmtime
, only with the JS glue that it also generates. The "next generation" is interface-types which should work for non-web runtimes and other wasm languages as well
For now in the meantime you'll need to effectively hand-write an ABI/API between modules and the host (or two modules), but we are indeed actively working on a solution to this :)
@Alex Crichton Thanks for clarifying. Writing my own ABI is fine with me, the part I’m struggling is trying to return have functions with multiple return values in Rust generated WASM, to for example; return the pointer and length of a vector from wasmtime::Memory
to the host.
Right now my guess is to return a i64 that is the pointer and length concatenated together, but that doesn’t really seem like the intended approach.
I added extern "wasm"
to rust (unstable) to support a multi value return Abi but it's unlikely to ever be stabilized
Multi value returns are not super well supported in C and Rust right now afaik
I'd recommend the i64 approach
Last updated: Nov 22 2024 at 17:03 UTC