0Pricing
Zig Academy · Lesson

build.zig.zon and the Package Manager

Declare dependencies in a manifest.

build.zig.zon and the Package Manager is a free Zig Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Zig Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

A Manifest for Your Package

Beside build.zig sits build.zig.zon, the manifest that names your package and lists what it depends on. 📜

ZON Is Zig Object Notation

The file is written in ZON, which looks just like a Zig anonymous struct literal. Dotted field names map to plain Zig values.

.{
    .name = .myapp,
    .version = "0.1.0",
}

Name and Version

Two required fields stand out: name identifies the package and version follows semantic versioning like 1.2.0.

.name = .myapp,
.version = "0.1.0",

List Your Dependencies

The dependencies field is a struct of entries, one per external package you want to pull into your build.

.dependencies = .{
    .mylib = .{},
},

A URL Points to the Source

Each dependency gives a url to a tarball, usually a tagged archive on a code host. Zig fetches and unpacks it for you.

.url = "https://example.com/mylib-1.0.0.tar.gz",

The hash Locks It Down

A hash field pins the exact bytes of that download. If the content ever changes, the hash mismatches and the build refuses it.

.hash = "122012ab...",

Let zig fetch Fill It In

You rarely type a hash by hand. Run zig fetch with the url and it downloads, computes the hash, and writes the entry for you.

zig fetch --save https://example.com/mylib-1.0.0.tar.gz

The Global Cache

Fetched packages land in a shared cache on your machine. Many projects reuse one copy, so the same dependency is not stored twice.

paths Declares What Ships

The paths field lists the files included when your package is itself a dependency. Use .{""} to ship everything in the folder.

.paths = .{ "build.zig", "src" },

Commit the Manifest

Because it carries exact hashes, build.zig.zon makes builds reproducible. Commit it so every teammate fetches the identical code.

build.zig Reads It

The manifest pairs with build.zig, which turns each declared dependency into a usable module. The .zon describes, the build script wires.

const dep = b.dependency("mylib", .{});

Quick Check

Recall what guarantees a dependency download has not been tampered with.

Recap

You met build.zig.zon: a ZON manifest with name, version, and dependencies, where each dep carries a url and a hash that zig fetch can fill in. 🎯

Frequently asked questions

Is the “build.zig.zon and the Package Manager” lesson free?

Yes — the full text of “build.zig.zon and the Package Manager” is free to read here on the web, and the Zig Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Zig Academy course, upgrade to CoddyKit PRO.

What will I learn in “build.zig.zon and the Package Manager”?

Declare dependencies in a manifest. You practise Zig Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Zig Academy?

No prior experience is required. Zig Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “build.zig.zon and the Package Manager” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Zig Academy lesson?

Yes. Every Zig Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Importing Files with @import
  2. Structuring a Multi-File Project
  3. build.zig.zon and the Package Manager
  4. Adding a Third-Party Module
← Back to Zig Academy