ziglang/zig
Standard library
Active contributors: andrewrk, alexrp, mlugg, vexu, jacobly
Purpose
lib/std/ is the Zig standard library. It is consumed by every Zig program (including the compiler itself) and is part of every install. It is the largest single namespace in the repository and contains everything from containers and arithmetic to filesystem, networking, threading, the build system, and the language frontend.
The root file is lib/std/std.zig. It just re-exports submodules and types — read it as the table of contents.
Top-level structure
lib/std/
├── std.zig # re-exports
├── builtin.zig # build mode, target, calling conventions
├── builtin/ # generated per-target builtin info
├── start.zig # platform start code (linked into every executable)
├── debug.zig # panic, stack traces, DWARF, addr2line
├── debug/ # DWARF helpers
├── log.zig # std.log
├── testing.zig # std.testing
├── testing/ # testing helpers
│
├── mem.zig # allocators, slices, memcpy, swap, etc. (~195 KB)
├── mem/ # generic allocators
├── heap.zig, heap/ # GeneralPurposeAllocator, ArenaAllocator, etc.
├── array_list.zig # ArrayList (~93 KB)
├── array_hash_map.zig # ArrayHashMap (~120 KB)
├── hash_map.zig # HashMap (~80 KB)
├── multi_array_list.zig # struct-of-arrays
├── bit_set.zig # BitSet (~69 KB)
├── DoublyLinkedList.zig, SinglyLinkedList.zig
├── priority_queue.zig, priority_dequeue.zig
├── deque.zig
├── treap.zig
├── static_string_map.zig
├── enums.zig # EnumArray/EnumMap/EnumSet (~57 KB)
├── meta.zig # comptime reflection helpers
│
├── math.zig, math/ # general math, big-int, complex, etc. (~75 KB)
├── simd.zig # SIMD helpers
├── sort.zig, sort/ # sorting algorithms (~40 KB)
├── ascii.zig
├── unicode.zig # UTF-8/16, normalization tables (~85 KB)
├── base64.zig
├── leb128.zig # LEB128 encoding
├── valgrind.zig # Valgrind client requests
│
├── fs.zig, fs/ # filesystem (~28 KB front, more in subdir)
├── posix.zig, posix/ # POSIX bindings (~263 KB)
├── os.zig, os/ # cross-OS namespace (Linux/Windows/Darwin/...)
├── c.zig, c/ # libc bindings (~371 KB front)
├── process.zig, process/# spawn, env, args (~80 KB)
├── time.zig, time/
├── tz.zig, tz/ # timezone parsing
├── http.zig, http/ # HTTP client/server (~39 KB)
├── Uri.zig # URL parsing (~32 KB)
├── Io.zig, Io/ # I/O traits + Reader/Writer (~66 KB)
├── Progress.zig # progress reporting (~61 KB)
├── Random.zig, Random/ # PRNGs
├── Thread.zig, Thread/ # std.Thread + Pool, mutex, etc. (~72 KB)
├── atomic.zig # std.atomic (~20 KB)
├── once.zig # std.once
├── pie.zig # PIE relocation helpers
│
├── crypto.zig, crypto/ # ciphers, hashes, signatures, TLS (~15 KB front)
├── hash.zig, hash/ # CRC, FNV, Wyhash, City, xx, ...
├── compress.zig, compress/ # gzip, deflate, zstd, xz, lz4, etc.
├── tar.zig, tar/, zip.zig
│
├── json.zig, json/ # JSON parser + serializer
├── zon.zig, zon/ # ZON parser + serializer
├── fmt.zig, fmt/ # std.fmt — string formatting (~58 KB)
│
├── coff.zig # COFF parsing (~77 KB)
├── elf.zig # ELF parsing (~90 KB)
├── macho.zig # Mach-O parsing (~72 KB)
├── pdb.zig # Microsoft PDB
├── dwarf.zig, dwarf/ # DWARF parser (~5 KB front)
├── wasm.zig
├── dynamic_library.zig
│
├── SemanticVersion.zig
├── Target.zig # target descriptor (~116 KB)
├── Target/ # CPU feature tables per arch (generated by tools/update_cpu_features.zig)
├── BitStack.zig
├── buf_map.zig, buf_set.zig
├── gpu.zig
│
├── zig.zig, zig/ # the language frontend (Tokenizer, Ast, AstGen, Zir, ...)
├── Build.zig, Build/ # std.Build — the build system
└── ...The root lib/std/std.zig is the authoritative re-export list; the section above groups by purpose for navigation.
Highlight: Io
lib/std/Io.zig (~66 KB) and lib/std/Io/ define a unified Io interface — an explicit context object for I/O, with Reader and Writer traits that work in both blocking and async (event-loop) modes. This replaced an older std.io shape and is now used by std.fs, std.http, std.process, and most networking code.
Highlight: Build
lib/std/Build.zig (~101 KB) and lib/std/Build/ contain the user-facing build API — std.Build, Step, Module, Cache, Watch. See Build system for details.
Highlight: crypto
lib/std/crypto/ is one of the most actively maintained subsystems and is unusually complete for a non-OpenSSL stdlib: AES, ChaCha, Poly1305, SipHash, BLAKE2/3, SHA-1/2/3, Keccak, x25519/Ed25519/secp256k1/secp256r1, HMAC, HKDF, scrypt, Argon2, TLS 1.3 client. The TLS implementation is what powers std.http.Client HTTPS support (see http_disable_tls in std.Options).
Highlight: zig
lib/std/zig/ is the Zig language frontend (tokenizer, parser, AST, AstGen, ZIR, ZON). It is part of stdlib so external tools (LSPs, formatters, autodoc) can use the same code the compiler does. See Frontend.
Options
lib/std/std.zig exposes a pub const Options = struct { ... };. A user program can override stdlib defaults (panic handler, log level, page size, fmt depth, crypto seed, TLS toggle) by declaring pub const std_options: std.Options = .{ ... } in its root file. This is how src/main.zig configures the compiler's own logging.
Key source files
| File | Purpose |
|---|---|
lib/std/std.zig |
Root re-export. |
lib/std/Io.zig |
Async/blocking I/O traits. |
lib/std/mem.zig |
Allocators and byte-level utilities. |
lib/std/heap.zig |
GeneralPurposeAllocator, ArenaAllocator, c_allocator. |
lib/std/array_list.zig |
ArrayList. |
lib/std/hash_map.zig, lib/std/array_hash_map.zig |
Hash maps. |
lib/std/Target.zig |
Target descriptor. |
lib/std/posix.zig |
POSIX bindings. |
lib/std/c.zig |
libc bindings. |
lib/std/Build.zig |
Build system. |
lib/std/zig/ |
Language frontend (tokenizer/parser/AstGen/ZIR). |
lib/std/crypto/ |
Cryptography. |
lib/std/http.zig |
HTTP client/server. |
lib/std/json.zig, lib/std/zon.zig |
Data formats. |
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.