Zig WASM runtime in standard library?

I seem to recall reading about zig boot-strapping itself on new platforms using WASM. It got me wondering if Zig has a hidden WASM runtime somewhere in the standard library? If not, are the any plans to expose this? or maybe add one? All I found so far are bits I think are maybe used for compiling WASM.

I realise I could take one of the existing WASM runtimes, but I´d much rather use Zig´s own if it exists :slight_smile:

1 Like

The stage1 is a compiled WASM binary that uses WASI preview 1 functions for processing the compiler source code. It does not have WASM runtime, or rather, there is a custom wasm/wasi runtime in C that is used to bootstrap the wasm binary to your local system. If you want to use the WASI interpreter, then you can look at zig/stage1/wasi.c at master · ziglang/zig · GitHub Note that this is not a complete wasi/wasm implementation, only enough for what the stage1 binary needs.
The idea is that you would compile that function using your c tool chain, use the output to run the wasm to further build the stage 2 compiler.
You can read more in this thread: Questions on the bootstrapping process - #4 by kristoff

If you are looking for an embeddable wasm runtime in Zig, you can look at GitHub - rdunnington/bytebox: Standalone WebAssembly VM.

8 Likes

Thanks for the detailed answer! Both options look interesting, but using Bytebox might be the easiest. I only want a MVP/wasm1 runtime, and I hadnt come across Bytebox so far, having it written in Zig is a real bonus. Good work :slight_smile:

ByteBox is fully featured and supports wasm v2 and wasi preview 1. It’s easy to embed it, so my suggestion would be to start there.

1 Like