0Pricing
Zig Academy · درس

بنية ملف build.zig

تعرّفوا إلى دالة build وعنصر Builder

بنية ملف build.zig درس مجاني في Zig Academy على CoddyKit. هذا هو الدرس 1 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في 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/7) وفتح باقي دورة Zig Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Zig Academy 4 دروس في المجموع.

ماذا ستتعلم في «بنية ملف build.zig»؟

تعرّفوا إلى دالة build وعنصر Builder تتمرن على Zig Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Zig Academy؟

لا تُشترط خبرة سابقة. Zig Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 4.

كم من الوقت يستغرق درس «بنية ملف build.zig»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Zig Academy هذا؟

نعم. كل درس في Zig Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. بنية ملف build.zig
  2. التصريح عن الملفات التنفيذية والمكتبات
  3. خطوات البناء وzig build run
  4. خيارات البناء والرايات
← العودة إلى Zig Academy