Skip to content

Commit f4f60bf

Browse files
author
ikrima
committedFeb 25, 2022
[zig] compiler stages
1 parent 36e5464 commit f4f60bf

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed
 

‎content/dev-notes/zig/zig-build.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,20 @@ provide compile-time configuration to your code
261261
* somewhere in its belly invokes your `pub fn build(b: *Builder)` on a `Builder` it created earlier
262262
* The very last thing it does is hand over to this `Builder` you got to modify using `make()`
263263
* the main workhorse is `LibExeObjStep.make` which spawns the actual zig compiler (e.g. `zig build-exe/zig build-lib/zig cc`) with the builder/step settings converted as command line args
264-
* code at [src/main.zig](https://github.com/ziglang/zig/blob/master/src/main.zig),
264+
* code at [src/main.zig](https://github.com/ziglang/zig/blob/master/src/main.zig)
265+
266+
### Compiler Stages
267+
268+
Zig uses multiple compiler stages for bootstrapping the compiler:
269+
270+
* **zig0**: is just the c++ compiler as a static library
271+
* only implements the backend for build-exe/obj etc
272+
* **stage1**: is the current compiler, written in C++, compiled with Clang
273+
* uses *zig0* library to build pieces of *stage2* in (subcommands like translate-c etc)
274+
* **stage2**: is the current project, written in Zig, compiled with *stage1*
275+
* **stage3**: is the fully self-hosted, *stage2* code compiled with *stage2*
276+
* *stage1* doesn't implement full optimizations so *stage2* binary is not optimized
277+
* *stage3* binary is optimized b/c *stage2* implements optimizations/much better codegen
265278

266279
### std.build.Builder
267280

0 commit comments

Comments
 (0)
Please sign in to comment.