Skip to content

Cross-compiling, for free

12 July 2026 ยท Zig 0.16

Every Zig install builds for every target it knows, with no SDK or sysroot to set up: the standard library is compiled from source for the target, and the libc it needs ships with the compiler.

zig build-exe hello.zig -target aarch64-linux-musl -O ReleaseSmall
file hello

That's a static ARM64 Linux binary, built on any machine. A target is an architecture, an operating system and an ABI, and zig targets lists every one it knows.

In a project, b.standardTargetOptions(.{}) in build.zig turns the same choice into a flag:

zig build -Dtarget=x86_64-windows-gnu -Doptimize=ReleaseFast

And because the compiler carries clang and those libcs, zig cc stands in for a C compiler that cross-compiles as well, which is how some projects that aren't written in Zig at all use it:

zig cc -target x86_64-linux-musl -O2 hello.c -o hello