pub const CompilerBackend = enum(u64) {
/// It is allowed for a compiler implementation to not reveal its identity,
/// in which case this value is appropriate. Be cool and make sure your
/// code supports `other` Zig compilers!
other = 0,
/// The original Zig compiler created in 2015 by Andrew Kelley. Implemented
/// in C++. Used LLVM. Deleted from the ZSF ziglang/zig codebase on
/// December 6th, 2022.
stage1 = 1,
/// The reference implementation self-hosted compiler of Zig, using the
/// LLVM backend.
stage2_llvm = 2,
/// The reference implementation self-hosted compiler of Zig, using the
/// backend that generates C source code.
///
/// Note that one can observe whether the compilation will output C code
/// directly with `object_format` value rather than the `compiler_backend` value.
stage2_c = 3,
/// The reference implementation self-hosted compiler of Zig, using the
/// WebAssembly backend.
stage2_wasm = 4,
/// The reference implementation self-hosted compiler of Zig, using the
/// arm backend.
stage2_arm = 5,
/// The reference implementation self-hosted compiler of Zig, using the
/// x86_64 backend.
stage2_x86_64 = 6,
/// The reference implementation self-hosted compiler of Zig, using the
/// aarch64 backend.
stage2_aarch64 = 7,
/// The reference implementation self-hosted compiler of Zig, using the
/// x86 backend.
stage2_x86 = 8,
/// The reference implementation self-hosted compiler of Zig, using the
/// riscv64 backend.
stage2_riscv64 = 9,
/// The reference implementation self-hosted compiler of Zig, using the
/// sparc64 backend.
stage2_sparc64 = 10,
/// The reference implementation self-hosted compiler of Zig, using the
/// spirv backend.
stage2_spirv = 11,
/// The reference implementation self-hosted compiler of Zig, using the
/// powerpc backend.
stage2_powerpc = 12,
/// The reference implementation self-hosted compiler of Zig, using the
/// loongarch backend.
stage2_loongarch = 13,
/// The Zig Software Foundation self-hosted implementation of Zig. Backend
/// originally contributed by Ben Anderman in 2026.
zsf_spork8 = 14,
_,
}
This enum is set by the compiler and communicates which compiler implementation is used to produce machine code.
In theory, Zig code should be agnostic to the backend that implements the language. The only reason to observe this value is to work around problems with compiler implementations.
A common pitful is failing the compilation if the compiler backend does not match a whitelist of backends; a more resilient strategy is to detect that a known problem would occur in a blacklist of backends.
The enum is nonexhaustive so that alternate Zig language implementations may choose a random number as their tag, thereby avoiding conflicts with other implementations, and codebases can interact with these values even if this upstream enum does not have a name for the number. Of course, upstream is happy to accept patches to add additional Zig implementations to this enum.
This data structure is part of the Zig language specification.