Live data from Hacker News

Zig is now self–hosted by default

github.com

1–10 of 115 posts

Re: Zig is now self–hosted by default

#2
To clarify what this means, since things can get confusing with subtle differences in wordings:

* stage1 is when zig is built from C++ code[1] (the "bootstrap" compiler) using system C/C++ compiler toolchain.

* stage2 is when zig is built from Zig code[2] using stage1.

* stage3 is when zig is rebuilt from the same Zig code[2] using stage2.

Before today, zig would give you stage1 by default, and you could opt in to stage2 using `-fno-stage1`. After today, zig gives you stage3 by default, and you can opt in to stage1 using `-fstage1`.

In all three cases, LLVM is being used. Although Zig has started to fully self-host by providing backends that have no dependency on LLVM, none of these fully self-hosted backends are complete.

Why bother self-hosting? Because:

* Zig produces smaller, faster binaries than C++ that use less memory[4]. Case in point: the new self-hosted compiler is 1.5x faster than the C++ implementation and uses 3x less peak RAM.

* Development velocity in Zig is much faster than C++, and debugging is a breeze in comparison due to Zig being much safer than C++ and having better debug tooling. Similarly, comptime features let us add more assertions and debug checks that are not possible in C++.

* Zig compiles much faster than C++.

* Zig cross compiles better than C++ making it easier to create builds of the compiler for every target.

* The self-hosted compiler does not need a softfloat library dependency to support f16 or f128 operations.

* Zig's std lib data structures are incredibly useful, especially compared to the C++ STL.

There are still many known bugs; not every project will be able to upgrade immediately. See the full upgrade guide [3] for help deciding when and how to upgrade.

[1]: https://github.com/ziglang/zig/tree/master/src/stage1

[2]: https://github.com/ziglang/zig/tree/master/src

[3]: https://github.com/ziglang/zig/wiki/Self-Hosted-Compiler-Upg...

[4]: https://media.handmade-seattle.com/practical-data-oriented-d...

Re: Zig is now self–hosted by default

#3

To clarify what this means, since things can get confusing with subtle differences in wordings: * stage1 is when zig is built from C++ code[1] (the "bootstrap" compiler) using system C/C++ compiler toolchain. * stage2 is when zig is built from Zig code[2] using stage1. * stage3 is when zig is rebuilt from the same Zig code[2] using stage2. Before today, zig would give you stage1 by default, and you could opt in to st…

Congratulations. This is an important milestone.

Re: Zig is now self–hosted by default

#6
post #5

Very exciting. Are there plans to maintain the bootstrap path over the longer term? It always makes me sad when I hear about compilers which must bootstrap from magic binary blobs.

I hope so, but it seems like even if they didn't maintain it you could build today's stage1 using LLVM 14 and then work from the resulting binary instead of a binary you downloaded from online.

Re: Zig is now self–hosted by default

#8
post #5

Very exciting. Are there plans to maintain the bootstrap path over the longer term? It always makes me sad when I hear about compilers which must bootstrap from magic binary blobs.

I believe the goal is to replace the C++ with a C bootstrap that is initially auto generated from the zig code by zig but manually cleaned up and maintained to match

Re: Zig is now self–hosted by default

#9
post #5

Very exciting. Are there plans to maintain the bootstrap path over the longer term? It always makes me sad when I hear about compilers which must bootstrap from magic binary blobs.

I believe the goal is to replace the C++ with a C bootstrap that is initially auto generated from the zig code by zig but manually cleaned up and maintained to match

Starting from auto-generated code isn't considered a proper bootstrap process by the Bootstrappable Builds project. You need to be able to start without any binaries or auto-generated code from the project itself. Usually that would mean starting with a basic implementation in another language, but starting with an older version of the same project that was written in another language and then going through several older versions of different milestones is often easier than reimplementing the language from scratch in another language.

https://bootstrappable.org/

Re: Zig is now self–hosted by default

#10
Oh boi, oh boi, oh boi, oh boi, this is a historic moment. I think at the current rate I will start focusing my energy on learning and using Zig when version 0.12.0 is out :)

Awesome work guys. I am so looking forward to this language!

Post reply on HN