Stream: general

Topic: Cost of embedding wat into Rust/C


view this post on Zulip Mario (Jun 15 2022 at 15:46):

Hi,

It seems I can use wasmtime to embed wat into Rust/C. If I wanted to compile this code with the embedded wat into wasm, would there be an overhead in the wasm module?

view this post on Zulip Mario (Jun 15 2022 at 15:47):

Referring to this section in the docs: https://docs.wasmtime.dev/examples-rust-hello-world.html

I would like to compile the hello.rs file into a wasm module, could not find any compiletime strategies so now looking at a way to do it at runtime

view this post on Zulip Alex Crichton (Jun 15 2022 at 16:06):

Sorry when you say "embed wat" do you meant embedding a translation from the text format of WebAssembly to the binary format? Or do you mean embedding a wasm engine in general?

view this post on Zulip Mario (Jun 15 2022 at 16:07):

The former; to embed wat so that its inlined in the final wasm binary. I was not able to see a way to do it like inline_asm!, so I started looking at wasmtime... It may not be the correct strategy, please let me know

view this post on Zulip Alex Crichton (Jun 15 2022 at 16:18):

Wasmtime in general cannot be compiled to WebAssembly itself, and in general I don't think there's any way to embed *.wat text syntax into a wasm binary and run it at runtime of the wasm binary itself, or at least not a portable way of doing so.

view this post on Zulip Mario (Jun 15 2022 at 16:21):

So the only solution is to either write all of your code in a high level language or write all of your code in wat, given that you want the final output to be a wasm binary?

view this post on Zulip Alex Crichton (Jun 15 2022 at 16:25):

I think LLVM has a textual format for its object file format which you may be able to use, but I'm not personally aware of a great way of writing *.wat and linking it into a final wasm binary myself.

view this post on Zulip Mario (Jun 15 2022 at 16:29):

Oh thanks for the pointer, I'll check out LLVM

view this post on Zulip Mario (Jun 15 2022 at 16:58):

@Alex Crichton does this also apply to embedding wasm byte code too?

view this post on Zulip Alex Crichton (Jun 15 2022 at 16:58):

to the best of my knowledge yeah, it's not easy to do. You basically need to craft an input to wasm-ld which I don't think is a trivial operation (in that I don't know of off-the-shelf methods to do that)

view this post on Zulip Mario (Jun 15 2022 at 17:05):

Ah I see, okay I’ll look into doing it first and then trying to package it so that others can use it


Last updated: Nov 22 2024 at 16:03 UTC