Stream: wasmtime

Topic: Using multi_value_xform


view this post on Zulip XAMPPRocky (May 13 2021 at 20:10):

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.

view this post on Zulip fitzgen (he/him) (May 13 2021 at 21:25):

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

view this post on Zulip XAMPPRocky (May 14 2021 at 03:20):

@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.

view this post on Zulip Alex Crichton (May 14 2021 at 15:38):

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

view this post on Zulip Alex Crichton (May 14 2021 at 15:39):

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 :)

view this post on Zulip XAMPPRocky (May 14 2021 at 17:59):

@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.

view this post on Zulip Alex Crichton (May 14 2021 at 18:11):

I added extern "wasm" to rust (unstable) to support a multi value return Abi but it's unlikely to ever be stabilized

view this post on Zulip Alex Crichton (May 14 2021 at 18:11):

Multi value returns are not super well supported in C and Rust right now afaik

view this post on Zulip Alex Crichton (May 14 2021 at 18:11):

I'd recommend the i64 approach


Last updated: Dec 23 2024 at 14:03 UTC