⚡ Zig Guide LiveUnofficialbut fully verified
✓ Zig 0.18.0-dev.624+b7f2c6d8fWhat's newOn an older Zig?Blograylib-zig

The Guide

The guide has 293 chapters in seven tracks, in this order. The arrows at the bottom of every page follow this order. Thus you can start at the top and follow the next arrow each time. If you already know the language, you can also read each track alone.

Start with Installation → or select a reading path for your starting point.

Foundations

The language and its standard library. Start here.

  • Getting StartedInstall a Zig master build, compile and run your first program, run tests, and learn what changed since the last tagged release.
  • LanguageRunnable Zig language chapters: integers, floats, pointers, slices, optionals, error unions, structs, unions, enums, switch, loops, comptime and vectors.
  • ComptimeZig comptime by example: lookup tables that the compiler builds, @typeInfo reflection, @Struct and @Enum, dispatch, @compileError, and three projects: units of measure, an argument parser and an event bus.
  • Standard LibraryZig std by example: allocators, ArrayList, hash maps, JSON, the Io interface, readers and writers, crypto, formatting and sort.
  • Working with FilesHow to read and write files in Zig with std.Io: full files and lines, text and binary formats, seek and positional reads, CSV, directories and errors.
  • Data StructuresBuild containers in Zig: a growable array, a linked list, generic containers, the intrusive lists in std, a binary search tree, AVL and a hash map.
  • ConcurrencyConcurrency in Zig with std.Io: async, Future, Group, cancellation, Select, queues, locks, atomics, OS threads, std.Thread today, and a batch runner.

Groundwork

What the machine does, from zero. The track assumes no C and no earlier systems work.

  • Systems from ScratchSystems programming from zero: bytes and types, overflow, addresses, the stack, memory ownership, struct layout, errors and system calls.

Systems

Zig and the world outside the process: networks, builds, C, wasm and pixels.

  • Operating SystemHow Zig uses the operating system: file descriptors, the standard streams, the environment, child processes, pipes, signals, and exit and defer.
  • NetworkingNetwork programming in Zig, from sockets to protocols: framing, short reads, text and binary protocols, byte order, many clients, TCP, UDP, HTTP and WebSockets.
  • Build Systembuild.zig by example: build modes, cross-compilation, dependencies in build.zig.zon, and documentation from doc comments.
  • Working with CHow to call C from Zig and expose Zig to C: translate-c, C pointer types, C primitive types, and the C ABI.
  • WebAssemblyHow to compile Zig to WebAssembly: freestanding modules, calls from JavaScript, data across the boundary, wasm in the browser, and a WASI command.
  • GraphicsSoftware rendering and image processing in Zig, with no graphics library: framebuffers, PNG, rasterization, blending, antialiasing, filters and scaling.

Cookbook

Recipes for tasks. Each recipe is a complete program that CI compiled and ran.

  • How-ToA Zig cookbook of runnable recipes: JSON, SQLite, the PostgreSQL wire protocol, Redis RESP, threads and atomics, SIMD, compression and binary formats.

From Scratch

Rebuild the tools that you use every day, one program at a time, with only code that you wrote.

  • Survive the TerminalThe primitives that a shell needs: string length, comparison, copy and trim written by hand, a command-line tokenizer, and the read-eval-print loop.
  • Unix ToolsRebuild the standard Unix tools in Zig: cat, wc, grep, sort, cut, printf and make. Each chapter is one complete program that runs in the page.
  • Tiny LanguageBuild a small language from zero: a lexer, a recursive descent parser, a tree-walking interpreter, call frames, a bytecode compiler and a VM.
  • Web ServerParse an HTTP request by hand, format a response, and send it over a real socket. HTTP is text, a blank line ends the headers, and you need no framework.
  • Data and StorageHow storage engines work: an append-only log, the lost update from two writers, indexes that change a scan to a lookup, and a crash-safe write-ahead log.
  • The BrowserThe pipeline behind each web page: an HTML parser that cannot fail, CSS matching, a layout engine that makes boxes, and a renderer that makes pixels.

Projects

One library at a time, designed in public, with one decision in each chapter.

  • An Ecto-Style ORMAn Ecto-style ORM in Zig: schemas as types, a typed query builder, migrations as data, errdefer transactions, and an adapter seam for SQLite and Postgres.
  • A URL ShortenerA CRUD web service in Zig with no framework and no database driver: the PostgreSQL wire protocol, base62 slugs, and HTTP handlers on plain bytes.
  • Lane Dodgerraylib gameA hyper casual game in Zig and raylib that you play in the page: vendored C, a fixed timestep, handles, a derived difficulty curve and synthesised sound.
  • A Paint ProgramA paint program in Zig that runs in the page, with no graphics library: brushes, a 16-bit stroke buffer, layers, undo, flood fill and PNG export.
  • A Chat ServerA WebSocket chat server in Zig with only the standard library: a text protocol, a hub with one outbox for each member, slow clients, and frames.

Practice

The algorithms that a contest problem expects you to know. Each program prints the steps that it took.

  • Competitive ProgrammingContest algorithms in Zig, one complete program per chapter. Each program prints its steps, from binary search and two pointers to knapsack.