Stream: wasmtime

Topic: ✔ Passing string to wasm, Rust host, Rust guest


view this post on Zulip ReactorScram (Sep 20 2022 at 23:15):

I saw this already: https://bytecodealliance.zulipchat.com/#narrow/stream/217126-wasmtime/topic/Pass.20string.20to.20and.20return.20string.20back.20from.20WASM.20function

But I don't really want to use wit. Is that the only way, even though it's not stable yet?
Is there a manual way I can load a string into memory and have the guest function read it, without using unsafe?

view this post on Zulip Peter Huene (Sep 20 2022 at 23:21):

You could always export custom memory management functions from the guest for the host to call to allocate space in the guest's linear memory. The host could then allocate the space, copy the string into it, and then pass the address to the guest; you'd be on your own to figure out ownership semantics for the allocation, though.

view this post on Zulip Peter Huene (Sep 20 2022 at 23:22):

we do hope that eventually we get to the place where this is pretty much handled for you with minimal fuss with the component model and wit (or perhaps some more proc-macro magic in the future), however.

view this post on Zulip ReactorScram (Sep 21 2022 at 01:17):

Thanks! Didn't realize that was the trick, and I couldn't find any examples in the wasmtime repo labelled "string".

I put up my example code if any other noobs happen across the thread https://six-five-six-four.com/git/reactor/wasm_test

Can't believe serde_json compiles down to 56 KB of wasm... on disk anyway.

wasm_test

view this post on Zulip Notification Bot (Sep 21 2022 at 01:17):

ReactorScram has marked this topic as resolved.


Last updated: Nov 22 2024 at 16:03 UTC