Stream: general

Topic: Confusion about exported tables


view this post on Zulip hoping (Jun 05 2025 at 10:07):

I am unsure if this is the correct place to ask this question, but I have nowhere to ask.
I am trying to simulate an environment to run wasm-bindgen built wasm in wasmtime.
When I saw the glue code in JS, I was confused about the purpose of exported tables.

view this post on Zulip Lann Martin (Jun 05 2025 at 12:51):

Direct access to tables is somewhat of an advanced topic. Usually your compiler/toolchain takes care of generating code for any table management.

view this post on Zulip Lann Martin (Jun 05 2025 at 12:56):

I don't know how wasm-bindgen deals with that. There are others here who probably do. :slight_smile:

view this post on Zulip Alex Crichton (Jun 05 2025 at 15:29):

While it should be theoretically possible to run wasm-bindgen modules in Wasmtime it's very much a situation where you'll be on your own. You'll effectively need to translate the JS glue code into Rust and while all the primitives are there AFAIK there's no generic way to do this translation. For example wasm-bindgen generates many imports that it knows about of how to generate JS but as someone just looking at the module you have no prior knowledge of what all the imports are for.

If you have specific questions about wasmtime's API we can probably help with that, but if you've got questions about the output of wasm-bindgen that's more of a wasm-bindgen question where I don't think you'll have much support as you're doing something effectively unsupported (running wasm-bindgen modules off the web)

view this post on Zulip hoping (Jun 06 2025 at 01:50):

Lann Martin said:

Direct access to tables is somewhat of an advanced topic. Usually your compiler/toolchain takes care of generating code for any table management.

So, we can't access the table in the client code. Then, if I insert data into that table, wasm_bindgen can retrieve it and send it through other imported functions. If client side can't access the table, how can it be possible?

view this post on Zulip hoping (Jun 06 2025 at 01:56):

Alex Crichton said:

While it should be theoretically possible to run wasm-bindgen modules in Wasmtime it's very much a situation where you'll be on your own. You'll effectively need to translate the JS glue code into Rust and while all the primitives are there AFAIK there's no generic way to do this translation. For example wasm-bindgen generates many imports that it knows about of how to generate JS but as someone just looking at the module you have no prior knowledge of what all the imports are for.

If you have specific questions about wasmtime's API we can probably help with that, but if you've got questions about the output of wasm-bindgen that's more of a wasm-bindgen question where I don't think you'll have much support as you're doing something effectively unsupported (running wasm-bindgen modules off the web)

Thanks for the help. I can try to do it myself. I already get all the imported functions provided by wasm_bindgen and generate empty implementations for all the functions. My WASM code runs in the wasmtime engine now. But my code includes some async code that uses wasm_bind_futures::spawn_local. Because of the empty implementation, the async task does not work right.
When I dig into it, I find an exported table. This is my blind spot. I need some knowledge to go on.

view this post on Zulip Lann Martin (Jun 06 2025 at 12:08):

There are wasm instructions for guests to access tables, but it may not be straightforward to use those instructions from the language / toolchain you are using.

view this post on Zulip hoping (Jun 09 2025 at 02:12):

Thanks for all the replies. I just forgot all about the export tables and did whatever the glue code did. Finally, it works.


Last updated: Dec 06 2025 at 05:03 UTC