Hi,
I’ve been traveling and used this time to binge-listen to various zig related talks and podcasts.
As an aside, before the actual question in this post:
The material the zig community is producing is amazing.
So much so, that it’s a major motivation for me to learn Zig.
I really enjoy consuming programming-related content.
And the material from zig showtime and software you can love is something special.
At some point I thought “ok, this is amazing. Now imagine if you were actually using zig and somewhat invested into it yourself. This content would be even more fun”.
That’s actually a major motivation, learning zig so that the talks and videos you guys produce are even more fun.
Well and it feels good to dive back into a low-level language.
So, one podcast I listened to was this: Bootstrapping a Compiler via WASM with Loris Cro - Software Unscripted | Podcast on Spotify
Bootstrapping a compiler via wasm with Loris Cro.
I’d like to ask some follow-up questions, regarding the bootstrapping process of zig.
I listened to it while driving, so I may have missed some important details.
But as far as I understood:
Problem: We want to avoid compiling a whole chain of zig compiler versions, in order to arrive at the latest commit (for example when starting from scratch, or losing the binary somehow).
Key insight: The person about to commit to the compiler has a working version locally. How can we share this version?
Importantly: it’s not possible to just share a binary. That’s not cross-platform.
Potential fix: Compile the local version to C.
As far as I understood from the talk, the major blocker here is zig comptime.
Comptime is executed before outputting C code.
And among other things, it’s used to resolve platform specific configuration options.
So the local zig compiler would have to be compiled to different C codebases for all combinations of OS, arch, etc.
That is not viable.
Fix: Compile the local version of the zig compiler to wasm. Then if you want to have it on some other platform, you only need a wasm VM.
At this point I think I started being confused. The podcast explains that zig contains a minimal wasm VM.
But they also say that the wasm code execution can be sped up by compiling the wasm to C and then compiling the C to native code.
So, is the wasm VM used at all?
And what about comptime? The podcast presents this as a major problem when generating C code. Why is this not a problem for wasm? Particularly, since as far as I understand, the wasm code isn’t even executed as wasm, it’s converted to C. How can this not run into the problem of comptime already having been run?