Stream: wasmtime

Topic: can wasmtime generate a binary?


view this post on Zulip Rishav Sharan (Jun 10 2022 at 13:15):

Hi after compiling a hello world program, I am left with a cwasm file - which I am assuming is a bytecode binary format.
Is it possible for me to get an executable binary out of wasmtime?

view this post on Zulip bjorn3 (Jun 10 2022 at 14:33):

which I am assuming is a bytecode binary format.

It is file containing native code.

Is it possible for me to get an executable binary out of wasmtime?

Wasm needs a runtime. If you want you can use wasmtime as library in a regular non-wasm executable and use include_bytes!() to include the .cwasm file in the binary. You can disable the cranelift feature of wasmtime as there is no need to compile anything. This will make the executable smaller and save compile time.

view this post on Zulip Rishav Sharan (Jun 10 2022 at 14:45):

Thanks @bjorn3
not sure i grasped the process. there any sample code/example that I can read through on how to do this?

view this post on Zulip bjorn3 (Jun 10 2022 at 14:49):

Assuming you want to use wasi you can use the following example as starter: https://github.com/bytecodealliance/wasmtime/blob/main/examples/wasi/main.rs I think you only need to replace the Module::from_file(...)? call with Module::deserialize(&engine, include_bytes!("the_precompiled_wasm_module.cwasm"))?.

Standalone JIT-style runtime for WebAssembly, using Cranelift - wasmtime/main.rs at main · bytecodealliance/wasmtime

view this post on Zulip Rishav Sharan (Jun 10 2022 at 14:52):

Thank you!


Last updated: Nov 22 2024 at 17:03 UTC