more zig bootstrap updates

This commit is contained in:
2024-11-12 23:54:20 +02:00
parent 23e0f39506
commit a240d21fca

View File

@@ -5,10 +5,10 @@ slug: zig-reproduced-without-binaries
draft: true draft: true
--- ---
I decided to bootstrap zig without using binaries that are [checked in the I decided to bootstrap Zig without using binaries that are [checked in the
repository](https://github.com/ziglang/zig/blob/0.13.0/stage1/zig1.wasm) and repository](https://github.com/ziglang/zig/blob/0.13.0/stage1/zig1.wasm) and
answer if the resulting `zig1.wasm` in the latest zig release (0.13.0) is the answer if the resulting `zig1.wasm` in the latest Zig release (0.13.0) is the
same the one bootstrapped without those binaries. same the one bootstrapped without using those binaries.
TLDR: yes, they are the same: TLDR: yes, they are the same:
@@ -20,7 +20,7 @@ $ sha256sum code/zig{,2}/stage1/zig1.wasm
I can now confidently say (and you can also check, you don't need to [trust I can now confidently say (and you can also check, you don't need to [trust
me][2]) that there is nothing hiding in `zig1.wasm` that hasn't been me][2]) that there is nothing hiding in `zig1.wasm` that hasn't been
checked-in. checked-in as a source file.
Many, many thanks to [Hilton Chain][1] for reasons I that will become clear Many, many thanks to [Hilton Chain][1] for reasons I that will become clear
later. The rest of this post walks through how I arrived to this claim. later. The rest of this post walks through how I arrived to this claim.
@@ -28,7 +28,7 @@ later. The rest of this post walks through how I arrived to this claim.
# Official zig1.wasm # Official zig1.wasm
Steps to acquire the official incarnation of `zig1.wasm` are straightforward: Steps to acquire the official incarnation of `zig1.wasm` are straightforward:
download zig, build `zig3` using the official instructions, use it to download Zig, build `zig3` using the official instructions, use it to
`update-zig1`: `update-zig1`:
``` ```
@@ -36,7 +36,7 @@ git clone https://github.com/ziglang/zig; cd zig
git checkout 0.13.0 git checkout 0.13.0
mkdir build; pushd build mkdir build; pushd build
cmake .. cmake ..
make -j install make -j$(nproc) install
popd popd
build/stage3/bin/zig build update-zig1 build/stage3/bin/zig build update-zig1
``` ```
@@ -49,8 +49,7 @@ $ git diff --stat
1 file changed, 0 insertions(+), 0 deletions(-) 1 file changed, 0 insertions(+), 0 deletions(-)
``` ```
We will be comparing this `zig1.wasm` to the one bootstrapped in the next We will be comparing this file to the one bootstrapped in the next section.
section.
# Binary-free zig1.wasm # Binary-free zig1.wasm
@@ -74,12 +73,12 @@ Date: 2022-11-13T01:35:20+02:00
1 file changed, 0 insertions(+), 0 deletions(-) 1 file changed, 0 insertions(+), 0 deletions(-)
``` ```
[Andrew's motivation][3] is legit from a Zig developer's perspective. However, [Andrew's motivation][3] is reasonable from a Zig developer's perspective.
checked-in binary blobs have trust issues, regardless of what we think about However, checked-in binary blobs have trust issues, regardless of what we think
the author. about the author.
The last commit that can[^1] be built without binary blobs is the parent of The last commit that can[^1] be built without using binary blobs is the parent
this one: of this one:
``` ```
commit 28514476ef8c824c3d189d98f23d0f8d23e496ea commit 28514476ef8c824c3d189d98f23d0f8d23e496ea
@@ -92,21 +91,20 @@ Date: 2022-11-01T05:29:55+02:00
use stage1 as a backend anymore. use stage1 as a backend anymore.
``` ```
Once C++ implementation was removed, Zig is required to build Zig. This is a After this, Zig is required to build Zig. This is a cyclic dependency, which
cyclic dependency, which Zig Core team breaks by continuously checking in *a* Zig Core team breaks by continuously checking in *a* Zig compiler in
Zig implementation in wasm, the `zig1.wasm` file, which is used to build the wasm, the `zig1.wasm` file, which is used to build the compiler.
compiler.
Andrew suggests a motivated third-party to implement a [Zig Andrew suggests a motivated third-party to implement a [Zig
interpreter][zig-interpreter] in non-zig that could break this chain. While interpreter][zig-interpreter] in non-Zig that could break this chain. While
that would be certainly be ideal, nobody has built it yet 🤷. that would be certainly be ideal, nobody has built it yet 🤷.
The steps to build "trusted"[^3] zig are roughly: The steps to build "trusted"[^3] Zig are roughly:
1. Build zig from the C++ implementation of the commit above (with hacks and 1. Build Zig from the C++ implementation of the commit above (with hacks and
tricks to make it [actually compile][4]). tricks to make it [actually compile][4]).
2. Use previous step to build the first Zig self-hosted. 2. Use previous step to build the first Zig self-hosted.
3. Proceed to the next step. When the updated zig does not build, find creative 3. Proceed to the next step. When the updated Zig does not build, find creative
ways to build it anyway (or, when really stuck, ask @mlugg). ways to build it anyway (or, when really stuck, ask @mlugg).
4. Goto 2 for [45+ times][5]. 4. Goto 2 for [45+ times][5].
@@ -131,7 +129,7 @@ $ ls -lh /gnu/store/kqwq8sjgwi561sp78vfi6xkgm9i3wysk-zig-0.13.0-zig1/bin/zig1.wa
``` ```
Once I had `zig1.wasm` of 0.13.0, I did the same as I did in the official Once I had `zig1.wasm` of 0.13.0, I did the same as I did in the official
`zig1.wasm`: built zig3, used it to build `zig1.wasm`, and voilà, the hashes of `zig1.wasm`: built `zig3`, used it to build `zig1.wasm`, and voilà, the hashes of
the official `zig1.wasm` and the one built here match. the official `zig1.wasm` and the one built here match.
# Conclusion # Conclusion