Build Mode
Zig has four build modes:
- Debug (default)
- ReleaseFast
- ReleaseSafe
- ReleaseSmall
To add standard build options to a build.zig
file:
const Builder = @import("std").build.Builder;
pub fn build(b: *Builder) void {
const exe = b.addExecutable("example", "example.zig");
exe.setBuildMode(b.standardReleaseOptions());
b.default_step.dependOn(&exe.step);
}
This causes these options to be available:
-Drelease-safe=[bool] optimizations on and safety on
-Drelease-fast=[bool] optimizations on and safety off
-Drelease-small=[bool] size optimizations on and safety off
Debug
$ zig build-exe example.zig
- Fast compilation speed
- Safety checks enabled
- Slow runtime performance
- Large binary size
- No reproducible build requirement
ReleaseFast
$ zig build-exe example.zig -O ReleaseFast
- Fast runtime performance
- Safety checks disabled
- Slow compilation speed
- Large binary size
- Reproducible build
ReleaseSafe
$ zig build-exe example.zig -O ReleaseSafe
- Medium runtime performance
- Safety checks enabled
- Slow compilation speed
- Large binary size
- Reproducible build
ReleaseSmall
$ zig build-exe example.zig -O ReleaseSmall
- Medium runtime performance
- Safety checks disabled
- Slow compilation speed
- Small binary size
- Reproducible build
See also: