Initially I only had a fuzzy appreciation for Zig’s self-hosting problem/solution. After listening to the Software Unscripted podcast where they chatted with one of the Zig core team I feel like I have a better understanding of what’s going on which I will attempt to summarize here.
Zig is self hosted which means that if you have the latest zig compiler already you can compile any zig program (including the source code for zig compiler). If you don’t have the latest Zig compiler floating around you need a bootstrap compiler – i.e. a compiler not written in Zig that can compile the latest Zig compiler source code. The basic flow for adding features to Zig is as follows: Dev adds some new language feature X and compiles Zig with compiler U to produce compiler V. Zig compiler implementation is updated to use feature X via compiler V and compiled to produce compiler W. note: Compilers V and W are indistinguishable in which programs they can compile. compilers V and W can compile programs that U cannot. If someone else goes through these steps instead of you, then they have a copy of compiler V instead of you. If, after every step for every feature, the Zig team published a linux compatible version of Zig then anyone could stay up to date on Zig development. However, the Zig team doesn’t want to force people to use linux to bootstrap their Zig compiler (b/c developer experience is very important to Zig). This is the Zig self-hosting problem.
Well OK, why don’t they publish Zig on every OS after each step? The Zig team also doesn’t want to do that b/c it would take up a huge amount of storage (and $). Their solution is to basically do option 1, but instead of publishing an executable that runs on linux they publish a version of the Zig compiler that’s been transpiled to webassembly – the insight here is that every OS can run webassembly. The net result is that on a brand new machine, if you want the bleeding edge version of Zig (not an official release), you can download the webassembly bootstrap compiler (which is presumably updated frequently), download the Zig source code from github, compile that code with the webassembly compiler, and now you have the latest version of Zig without too much hassle.
(feel free to fact check me on anything)