4 ms·
Okay so we start from some C source code, and we build an interpreter for WASM + WASI from that (WASM that has access to system calls) C source -> WASM inte
by gavinray 4y ago
Okay so we start from some C source code, and we build an interpreter for WASM + WASI from that (WASM that has access to system calls)
C source -> WASM interpreter w/ system access
Now we can take the Zig self-hosted compiler (the one in .zig), which has been compiled to .wasm/.wasi files. Since we have an interpreter for those now, we can do this:
Zig compiler as .wasi instead of .exe --> WASM interpreter --> Zig's "translate-to-c" function, for the .zig file sources of the Zig compiler
E.G.
$ run-webassembly "zig-compiler-as-wasm.wasi" --translate-c <source code to zig compiler>
At this point, we have the Zig compiler as .c files. Now you can use GCC/clang or whatnot, to build a regular binary for the compiler
Output of Zig's "translate-to-c" from previous step --> GCC/clang --> Zig compiler but NOT AS WASM, as a regular binary
- MrBuddyCasino 4y agohow do you compile the Zig self-hosted compiler to wasm?
- TUSF 4y agoDefen explained explains this well here: https://news.ycombinator.com/item?id=33914969 https://news.ycombinator.com/item?id=33914969
- shp0ngle 4y agoAh. OK. I still don't understand why did Zig need to write their own WASM interpreter in C. There is no already existing interpreter of WASM? Also was that WASM interpreter written in C, or in Zig and compiled to C? Wait it might be covered in the article. I will read once more, slowly...
- TUSF 4y agoThey wanted you to only have to use what's in the git repo itself, plus whatever C compiler is on your system. Thus, a basic WASM→C converter was written, and kept minimal to save on space, because it's only meant to work on this one binary.