ziglang/zig
Targets
A "target" in Zig is a (cpu, os, abi, ofmt) tuple plus a feature set. Every part of the compiler routes off this descriptor.
The descriptor
lib/std/Target.zig (~116 KB) defines:
Cpu.Arch— the architecture enum.Cpu.ModelandCpu.Feature— CPU model + feature bits.Os.Tag,Os.Version*— OS plus version range.Abi— gnu/musl/macho/eabi/etc.ObjectFormat—elf,macho,coff,wasm,c,spirv,hex,raw,plan9.
Per-architecture feature tables live in lib/std/Target/<arch>.zig. They are generated from LLVM's tablegen by tools/update_cpu_features.zig.
Triple parsing
lib/std/zig/target.zig parses <arch>-<os>-<abi> triples and resolves them against lib/std/Target.zig. zig targets (src/print_targets.zig) prints the full enumerable space.
Capability gating in the compiler
src/target.zig carries the per-target capability table the compiler uses:
- Which backends are available (
useLlvm,useNonLlvmBackend). - Whether the in-tree linker supports the format.
- Calling-convention flavors.
- C ABI quirks.
src/codegen.zig reads this table to dispatch to the right backend. lib/std/zig/LibCDirs.zig reads it (indirectly via Target) to pick the bundled libc tree.
CPU feature sets
A Cpu is Model + Set(Feature). -mcpu=baseline+feature1-feature2 modifies the base model. The compiler:
- Resolves the model name against
lib/std/Target/<arch>.zig. - Applies
+feature/-featuredeltas. - Validates required combinations.
- Forwards the resolved set to the chosen backend.
What zig env prints
target_arch_subarch_endian: ...
target_os_abi_dynamic_linker: ...
target_dynamic_linker: ...
zig_lib_dir: ...
zig_global_cache_dir: ...(Exact keys vary by version; see src/print_env.zig.)
Cross-references
- Cross compilation for the user-facing story.
- Code generation backends for backend coverage.
- Bundled libraries for the libc/libcxx selection.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.