Stream: general

Topic: WASM (from Wit gen) -> WAT -> Wasmtime Component


view this post on Zulip Zeeshan Lakhani (Feb 08 2023 at 12:55):

Howdy, all, I have a test working that complies a wasm file (using WIT, with wit_bindgen_guest_rust::generate!), in a separate project, and then another project that loads said file and encodes it to a component (via wit-component ComponentEncoder), and then execute the fn via Wasmtime, using wasmtime::component::bindgen! . All good.

However, unlike working with wasmtime Modules, converting the compiled wasm to wat and then using wat::parse_bytes/file to convert it .wasm again results in an error trying to find the exported function using the same toolchain. Is this expectation correct for this toolchain? I just wanted to make sure.

view this post on Zulip Alex Crichton (Feb 08 2023 at 13:05):

Yes roundtripping the core module loses custom sections which are used by wit component. Round tripping the component should work though

view this post on Zulip Zeeshan Lakhani (Feb 08 2023 at 13:38):

@Alex Crichton gotcha and thanks. That makes sense to me. I'll test through roundtripping the component. Is there a way to dynamically check if the incoming bytes represent a component vs mod without trying to use wast? Probably can decode metadata from the incoming representation?

view this post on Zulip Alex Crichton (Feb 08 2023 at 14:06):

Yes you can check the first 8 bytes to see whether it's a component or a core wasm module

view this post on Zulip Zeeshan Lakhani (Feb 08 2023 at 15:15):

@Alex Crichton does work indeed, thanks again.


Last updated: Dec 23 2024 at 12:05 UTC