I'm looking at the https://github.com/WebAssembly/wasm-c-api/blob/2ce1367c9d1271c83fb63bef26d896a2f290cd23/example/hostref.c example, but the relevant functions aren't implemented by wasmtime according to the documentation. wasm_foreign_t
doesn't seem to be implemented at all!
How am I supposed to do this from the C API?
Could you describe a bit more about what you're trying to do with the C API? Wasmtime tries to implement what it can of the wasm-c-api repository but it can only do so much with the parts that are incompatible with Wasmtime
@Alex Crichton I wish to create values opaque to the module, that the module can pass around, e.g. wrappers around fds, and so I want to use externrefs, but I don’t see a way of making an arbitrary externref from the C API, i.e. https://docs.rs/wasmtime/latest/wasmtime/struct.ExternRef.html#method.new
In the WASM C API you do this by creating a foreign and attaching host info.
But this is unimplemented by wasmtime.
Ah ok, in that case I'd recommend using an indexing scheme. Even if you could make an externref that's not well-integrated with wasm toolchains today, so instead I'd recommend having a table on the host of things and pass indices of that into wasm.
That’s unfortunate, would you accept a PR that implements this part of the WASM C API? I think you can translate it cleanly into ExternRefs.
The WASM C API needs a lot of work honestly, very underdeveloped
If the parts of the ecosystem I need don’t support it I’ll implement it myself
Unfortunately we actually just removed support for externref in the C API last week. This is done as we figure out a how to best implement the GC proposal and expose the ability to work with it safely from the C API. We are still going to add it back in, but we're in a bit of transition period right now unfortunately
And yes I would agree that the wasm-c-api repository alone is probably not enough to get something nontrivial done. That's why we also have wasmtime.h
and a suite of wasmtime-specific symbols.
Last updated: Nov 22 2024 at 16:03 UTC