Stream: wasmtime

Topic: dumb question: with C API, how do I make host references?


view this post on Zulip Las (Mar 09 2024 at 12:55):

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?

view this post on Zulip Alex Crichton (Mar 10 2024 at 20:46):

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

view this post on Zulip Las (Mar 10 2024 at 23:40):

@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

view this post on Zulip Las (Mar 10 2024 at 23:41):

In the WASM C API you do this by creating a foreign and attaching host info.

view this post on Zulip Las (Mar 10 2024 at 23:41):

But this is unimplemented by wasmtime.

view this post on Zulip Alex Crichton (Mar 11 2024 at 14:11):

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.

view this post on Zulip Las (Mar 11 2024 at 14:23):

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.

view this post on Zulip Las (Mar 11 2024 at 14:23):

The WASM C API needs a lot of work honestly, very underdeveloped

view this post on Zulip Las (Mar 11 2024 at 14:24):

If the parts of the ecosystem I need don’t support it I’ll implement it myself

view this post on Zulip Alex Crichton (Mar 11 2024 at 14:25):

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

view this post on Zulip Alex Crichton (Mar 11 2024 at 14:25):

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