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?
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
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?
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
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.
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?
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.
Oh thanks for the pointer, I'll check out LLVM
@Alex Crichton does this also apply to embedding wasm byte code too?
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)
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: Dec 23 2024 at 13:07 UTC