Hey! Just coming to check: I'm trying to use wasm to make plugins, which means a rust binary, and running rust-based wasm blobs. I'm hoping to be able to basically define traits in binary land and to implement them in blob land.
Do I understand correctly if I say that there currently is no tooling, that the things I see around wit aren't ready yet, and that for now the best I could do would be to implement eg. a serde-based pseudo-RPC protocol manually?
The closest thing to this right now is wiggle, which is for implementing an exported (to Wasm) interface in native rust. You want the other way around, which is to import an interface in native rust that is implemented in Wasm. Wiggle already has some of the pieces you’d want to do this, but it’s far from complete
If you’d like to work on adding that functionality to wiggle I’m happy to get you oriented and point you in the right direction but it’s not something we have in near term plans. Medium to long term we expect interface types to take care of many of the pieces of this problem that wiggle currently solves.
I’m on vacation this week but I’ll be back around next week
Thank you for your pointers! That said… is there any documentation for wiggle? The only thing I could find is this ; which looks to me like it doesn't actually do any bindings but just define a trait based on a .witx file, and then it's up to the user to actually make the bindings themselves?
For some more context: not having noticed your answer due to being new to zulip, I have implemented a manual version of bindings based on bincode for serialization of complex types based on an horrible macro-generating macro for exposing rust wasm functions to rust host, and I'm now trying to expose rust host functions to rust wasm, which could maybe happen through wiggle — but then maybe it'd be better to just do another horrible macro for the reverse direction, and to wait for interface types to hopefully help clean up everything?
@Léo Gaspard, take a look at the blog post I published a bit ago: https://bytecodealliance.org/articles/implementing-wasi-nn-in-wasmtime. It might cover some of the stuff you are looking for...
Thank you for the link! Wiggle looks much more useful in this blog post than in the one I had linked :)
There's just something worrying me here: GuestSlice
is claimed to point straight into guest memory, but... with the threads-in-wasm proposal, will that not become unsound? I seemed to understand that for future-proofing guest memory should be volatile-read/volatile-written :/
yes, a number of things in wiggle would be unsound under threads
we havent been putting any energy into implementing threads or future proofing our ecosystem for it.
and yeah, unfortunately i never wrote very many docs for wiggle, but andrew has written a great blog about it. im happy to chat here whenever about it
your use case of using wasmtime as a plugin engine is one i would love to see succeed, and I think would make wiggle more useful in general under module linking and other stuff thats coming up soon
Threads will use a linear memory with the shared
flag declared on it, so when we add support for threads, one option is to have APIs like GuestSlice
fail if the shared
flag is set.
yep, and you could even build that functionality into your GuestMemory
impl - never permit borrowing a region if the memory is shared
In a sense, the future-proofing is designed at a higher level. We won't ever be in a situation where we have a linear memory that's shared between threads without us knowing about it.
Sounds great, thank you! (It also means I can remove my usage of core_intrinsics now I know I no longer need to volatile memcpy from/to the wasm memory the things I'm currently sending by serialization ^^)
I'll try to use wiggle for exposing callbacks from host to guest, while still keeping my awful macro for exposing functions from guest to host, and let you know if I hit any issues :)
(FWIW, the first thing I'd suggest would be "link Andrew's blog post from the wiggle readme so people can find it")
thanks, i added various links here https://github.com/bytecodealliance/wasmtime/pull/2550/files#diff-fb7b366f6a5cf931206deb5544b12a6aa6748abde958abb148ced38c1259439c
Hmm... Is it possible to have the equivalent of a string hashmap? I've tried creating a stringpair type that just contains two strings, and then having an array of that stringpair, but it looks like the stringpair type breaks wiggle's codegen (as in it tries to say str: Sized)
@Andrew Brown I just noticed, your blog post is missing the cargo:rerun-if-changed lines so cargo works properly with changing the .witx files, maybe it'd make sense to add that? (I'm personally using walkdir, but guess the example could just hardcode the paths)
@Léo Gaspard, let me take a look... around where in the post?
Like, here, you mean? https://github.com/bytecodealliance/wasmtime/blob/e09b9400f8434907894949e37f791fbd507d57b3/crates/wasi-nn/build.rs
At the definition of cargo:rustc-env=WASI_ROOT= [...]
Yup!
That would be a nice thing to add... do you want to submit a PR to do this to the wasmtime repo and then I will update the blog post?
Gotcha, I'm doing that :)
Hmm actually on what repo/branch is it? I can't find the file either in wasmtime master or your fork's master
Ooooh master got renamed to main, nvm
:)
Here's the link: https://github.com/bytecodealliance/wasmtime/blob/main/crates/wasi-nn/build.rs
https://github.com/bytecodealliance/wasmtime/pull/2553 :)
Thanks! I'll approve and merge once CI finishes
Last updated: Dec 23 2024 at 12:05 UTC