build.zig.zon e o gerenciador de pacotes
Declare as dependências em um manifesto.
build.zig.zon e o gerenciador de pacotes é uma aula grátis de Zig Academy no CoddyKit. Esta é a aula 3 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Zig Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Zig Academy inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
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.gzThe 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. 🎯
Perguntas Frequentes
A aula “build.zig.zon e o gerenciador de pacotes” é grátis?
Sim — o texto completo de “build.zig.zon e o gerenciador de pacotes” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Zig Academy, atualize para CoddyKit PRO. O curso de Zig Academy inclui 4 aulas no total.
O que vou aprender em “build.zig.zon e o gerenciador de pacotes”?
Declare as dependências em um manifesto. Você pratica Zig Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar Zig Academy?
Nenhuma experiência prévia é necessária. Zig Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 3 de 4.
Quanto tempo leva a aula “build.zig.zon e o gerenciador de pacotes”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de Zig Academy?
Sim. Cada aula de Zig Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Importando arquivos com @import
- Estruturando um projeto com vários arquivos
- build.zig.zon e o gerenciador de pacotes
- Adicionando um módulo de terceiros