Build Mode

Zig has four build modes:

To add standard build options to a build.zig file:

  1. const Builder = @import("std").build.Builder;
  2. pub fn build(b: *Builder) void {
  3. const exe = b.addExecutable("example", "example.zig");
  4. exe.setBuildMode(b.standardReleaseOptions());
  5. b.default_step.dependOn(&exe.step);
  6. }

This causes these options to be available:

  1. -Drelease-safe=[bool] optimizations on and safety on
  2. -Drelease-fast=[bool] optimizations on and safety off
  3. -Drelease-small=[bool] size optimizations on and safety off

Debug

  1. $ zig build-exe example.zig
  • Fast compilation speed
  • Safety checks enabled
  • Slow runtime performance
  • Large binary size
  • No reproducible build requirement

ReleaseFast

  1. $ zig build-exe example.zig -O ReleaseFast
  • Fast runtime performance
  • Safety checks disabled
  • Slow compilation speed
  • Large binary size
  • Reproducible build

ReleaseSafe

  1. $ zig build-exe example.zig -O ReleaseSafe
  • Medium runtime performance
  • Safety checks enabled
  • Slow compilation speed
  • Large binary size
  • Reproducible build

ReleaseSmall

  1. $ zig build-exe example.zig -O ReleaseSmall
  • Medium runtime performance
  • Safety checks disabled
  • Slow compilation speed
  • Small binary size
  • Reproducible build

See also: