0Pricing
Zig Academy · レッスン

build.zigファイルの構造

build関数とBuilderの役割を学びます。

「build.zigファイルの構造」はCoddyKit上の無料Zig Academyレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはZig Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Zig Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

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.Build

Import 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 build

It 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. 🎯

よくある質問

「build.zigファイルの構造」レッスンは無料ですか?

はい。「build.zigファイルの構造」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Zig Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Zig Academyコースには全4レッスンが含まれています。

「build.zigファイルの構造」で何を学びますか?

build関数とBuilderの役割を学びます。 ブラウザで直接実行するハンズオンコードでZig Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Zig Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのZig Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。

「build.zigファイルの構造」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このZig Academyレッスンでコードを書いて実行できますか?

はい。すべてのZig Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. build.zigファイルの構造
  2. 実行ファイルとライブラリを宣言する
  3. ビルドステップとzig build run
  4. ビルドオプションとフラグ
← Zig Academyに戻る