Hello! I used to use the #[wasmtime_rust::wasmtime]
procedural macro to generate bindings for WebAssembly modules. Is the macro no longer available? I cannot seem to find it in the wasmtime docs.
Also, I was wondering how I could implement the ability to pass strings to/from modules, and I arrived at the conclusion that it would be best to use the wasm-bindgen ABI and not reinvent the wheel. Assuming the aforementioned procedural macro is no longer available, would there be an interest in such macro, that would generate bindings for wasm-bindgen compatible types?
@Jakub Hlusička the crate/macro still semi-exists today but it's sort of on life support, we haven't invested much into it in quite some time now
I'd recommend using the wasmtime
crate, and otherwise writing a custom bindings generator which targets the wasmtime
crate
We're working on getting things like strings working with interface types, but that will take some time to implement.
Good to know, I always forget to check the misc
directory. :D
I was wondering about how I'd implement the ability to have an exported function which returns a String
. I don't think multi-value returns are implemented yet. I think I could do something like
#[wasm_bindgen]
fn exported(ptr: *mut (u32, u32)) {}
to pass a ptr
to a location in the linear memory where I'd store (1) the pointer to the string data and (2) the length. I'm not sure what would happen if the linear memory is not large enough, however. Does wasmtime automatically grow the linear memory? Is this the usual approach to returning strings/dynamically allocated data?
@Jakub Hlusička FWIW multi-value works as a feature in wasmtime, but toolchains do not have support to emit modules which use multi-value right now. Dealing with strings is very tricky in general, but the shape of what you'll probably want to do is to arrange for an ABI like you've specified and also export an alloc/free function from the mdoule
that way the host will call into the wasm to malloc bytes, fill it in, and then pass the pointer/length to the function
or if the host is given a string it knows how to free it
Okay, thanks for your help, I will give this a try. :)
Last updated: Nov 22 2024 at 17:03 UTC