ziglang/zig
Zig
Zig is a general-purpose programming language and toolchain for maintaining robust, optimal, and reusable software. The repository at ziglang/zig (master, commit 738d2be) contains the self-hosted Zig compiler, the standard library shipped with every Zig install, and the cross-compilation toolchain that lets zig act as a drop-in C/C++ compiler, linker, archiver, and resource compiler.
Heads up. The
README.mdin this repository points to a "Moved to Codeberg" notice (README.md). The GitHub repository is no longer the canonical home; ongoing development is mirrored or hosted at Codeberg. The wiki was generated from the snapshot stored at this commit and reflects the code as it is on disk. The content here describes the implementation, not the project's hosting status.
What is in this repository
| Top-level | What lives there |
|---|---|
src/ |
The self-hosted compiler: main.zig (CLI), Compilation.zig (build pipeline), Sema.zig (semantic analysis), Zcu.zig (Zig Compilation Unit / module graph), Air.zig (analyzed IR), link.zig and link/* (linkers), codegen.zig and codegen/* (per-target backends), Package/ (package manager). |
lib/std/ |
The Zig standard library. Used both by user programs and by the compiler itself. |
lib/compiler/ |
Compiler-bundled tools shipped inside zig: aro (a C frontend), resinator (Windows resource compiler), objcopy, reduce, build_runner, test_runner, translate-c, std-docs. |
lib/compiler_rt/ |
Pure-Zig implementation of compiler runtime helpers (__divti3, soft-float, etc.) that LLVM and the self-hosted backends rely on. |
lib/libc/, lib/libcxx/, lib/libcxxabi/, lib/libunwind/, lib/libtsan/ |
Bundled glibc/musl/mingw/wasi/freebsd/netbsd/darwin headers and stubs plus libc++/libunwind/tsan sources used to make zig cc a turnkey cross-compiler. |
lib/include/ |
Bundled clang resource headers. |
lib/init/ |
Templates expanded by zig init. |
doc/ |
The language reference (langref.html.in + langref/ snippets) and the package manager spec (build.zig.zon.md). |
tools/ |
Generators and maintenance scripts (CPU feature tables, glibc/musl updates, GDB pretty printers, incr-check, docgen, doctest). |
test/ |
The end-to-end test suite: behavior/, cases/, compile_errors.zig, link/, standalone/, c_abi/, incremental/, cli/, plus the test driver in tests.zig. |
ci/ |
Per-target build/test shell and PowerShell scripts driven by .forgejo/workflows/ci.yaml. |
cmake/, CMakeLists.txt, bootstrap.c, stage1/ |
The two-stage bootstrap path: build a stage1 zig from C/C++/CMake, then have it build the self-hosted compiler. |
build.zig, build.zig.zon |
The build script for the entire compiler, used once stage1 exists. |
What zig (the binary) actually does
The zig executable is a single multi-tool. The full sub-command list lives in src/main.zig (normal_usage) and includes:
- Compilation:
build-exe,build-lib,build-obj,test,run,test-obj. - Project workflow:
build(runbuild.zig),init,fetch. - Source tooling:
fmt,ast-check,reduce,translate-c. - Drop-in replacements for the C/C++ toolchain:
cc,c++,ar,lib,ranlib,dlltool,objcopy,rc. - Introspection:
env,targets,version,libc,std,zen,help.
Each sub-command is dispatched in src/main.zig (mainArgs) and most of them ultimately funnel into the same Compilation pipeline.
Map of the codebase
graph LR CLI["src/main.zig (CLI)"] --> Comp["src/Compilation.zig"] Comp --> Pkg["src/Package.zig"] Comp --> Zcu["src/Zcu.zig"] Zcu --> AstGen["std.zig.AstGen"] Zcu --> Sema["src/Sema.zig"] Sema --> InternPool["src/InternPool.zig"] Sema --> Air["src/Air.zig"] Air --> Codegen["src/codegen/* + LLVM backend"] Codegen --> Link["src/link/* (ELF/MachO/Coff/Wasm/SpirV/C)"] Link --> Output["Executable / library / object"] CLI --> Build["zig build → lib/compiler/build_runner.zig"] CLI --> CC["zig cc/c++ → clang driver via lib/libcxx, lib/libc, lib/include"] CLI --> Aro["zig translate-c → lib/compiler/aro"] CLI --> Res["zig rc → lib/compiler/resinator"]
Where to go next
- Architecture — the compilation pipeline (source → ZIR → AIR → machine code) and how the pieces connect.
- Getting started — building and testing the compiler from source.
- Glossary — Zig-specific terms (
Zcu,ZIR,AIR,InternPool,comptime, "stage1/2/3"). - How to contribute — workflow, testing, debugging.
- Compiler architecture — drill-down into the pipeline.
- Standard library — what is in
lib/std/. - Build system —
std.Buildandzig build. - Linker — the in-tree ELF/MachO/COFF/Wasm linkers.
- Code generation backends — LLVM, x86_64, AArch64, RISC-V, SPIR-V, Wasm, C.
- Bundled tools —
aro,resinator,build_runner, etc. - By the numbers — codebase statistics.
- Lore — release timeline and history.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.