Anatomia de um arquivo build.zig
A função de compilação e o Builder.
Anatomia de um arquivo build.zig é uma aula grátis de Zig Academy no CoddyKit. Esta é a aula 1 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 Build Script in Zig
Your project's build is not a config file in another language. It is a real Zig program named build.zig that you can read and debug. 🏗️
It Starts with build
Every build.zig exposes one entry point: a public build function. Zig calls it to discover what your project should produce.
pub fn build(b: *std.Build) void {
_ = b;
}The Builder Object
That single parameter b is a *std.Build. It is the builder: every artifact and step you want is created through it.
b: *std.BuildImport the Standard Library
Like any Zig file, build.zig pulls in std at the top so you can reach std.Build and its helper types.
const std = @import("std");Describe, Don't Run
The build function does not compile anything itself. It describes a graph of steps and artifacts that Zig then executes.
Pick the Target
Use standardTargetOptions to let the command line choose which OS and CPU you build for, defaulting to your own machine.
const target = b.standardTargetOptions(.{});Pick the Optimize Mode
Pair it with standardOptimizeOption so users pass Debug or ReleaseFast on the command line instead of editing the file.
const optimize = b.standardOptimizeOption(.{});Add an Artifact
Inside build you create things to compile, like an executable. Each artifact you add becomes a node in the build graph.
Run It with zig build
From the project root, the command zig build finds build.zig, calls your build function, and executes the resulting graph.
zig buildIt Is Just Code
Because build.zig is ordinary Zig, you can use variables, conditions, and loops to shape the build any way you need.
One File, Whole Project
This one file is the source of truth for your whole project: targets, modes, artifacts, and steps all live in build.zig. ✅
Quick Check
Recall what Zig looks for when you run the build.
Recap
You saw that build.zig is a Zig program with a public build function taking a *std.Build, where you set target, optimize, and artifacts. 🎯
Perguntas Frequentes
A aula “Anatomia de um arquivo build.zig” é grátis?
Sim — o texto completo de “Anatomia de um arquivo build.zig” é 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 “Anatomia de um arquivo build.zig”?
A função de compilação e o Builder. 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 1 de 4.
Quanto tempo leva a aula “Anatomia de um arquivo build.zig”?
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
- Anatomia de um arquivo build.zig
- Declarando executáveis e bibliotecas
- Etapas de compilação e zig build run
- Opções e sinalizadores de compilação