Build Zig compiler for native machine

I already have zig installed in my computer, but i want a build optimized for my specific CPU to get nicer compile times. I use a slow laptop.

I know this might be a silly question, but even after reading a bit through the documentation, i am not sure wich compiler flags i should use to build Zig. (My 1st time building a non-toy compiler)

I want to avoid running tests that are not relevant for my machine and also bulding LLVM wich would take hours, not very pleasant to do every time i update Zig.

Check out the build options on the bootstrapping page, I think you just want native-[whatever]-[whatever]

https://codeberg.org/ziglang/zig-bootstrap

So you have to update LLVM only once every LLVM version upgrade (e.g. when Zig switches from LLVM 21 to LLVM 22).
This specific optimization for your specific CPU will improve compile times only a tiny bit. And most time spent during the compilation process (of release-mode binaries) is spent in the LLVM part (emitting an object, optimizing it and linking it). Debug builds use (since some time) Zig’s in-house backend, and there is incremental compilation.
So I’d discourage you from trying to get more performance by building for your specific CPU. That rarely makes it any better (and since, when not in Debug mode, the most time is spent in LLVM, it doesn’t really make sense to not build LLVM).

1 Like