Skip to content

Commit d50f9b8

Browse files
committed
add build graph documentation
1 parent 60d8ffc commit d50f9b8

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

content/en-US/learn/build-system.smd

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,30 @@ The second one, `zig-out`, is an "installation prefix". This maps to the standar
6464

6565
You, as the project maintainer, pick what gets put in this directory, but the user chooses where to install it in their system. The build script cannot hardcode output paths because this would break caching, concurrency, and composability, as well as annoy the final user.
6666

67+
## [The Build Graph]($heading.id('build-graph'))
68+
We previously mentioned that the Zig build system models the build process as a DAG.
69+
We will now discuss how this graph is constructed.
70+
71+
The core of this graph is `std.Build.Step`.
72+
Every `Step` has a name and a list of dependencies, which are other `Step`s.
73+
These `Step`s and the dependencies between them form the build graph.
74+
75+
The most basic way to create a new step is via the `std.Build.step` method.
76+
This method creates a new standalone `Step`, meaning that it does not depend on any other `Step`s, and no other `Step`s depend on it.
77+
You can add this step as a dependency of another step via the dependent step's `std.Build.Step.dependOn` method.
78+
You can also use `dependOn` to add dependencies to _this_ step.
79+
80+
The `std.Build.step` method is generic in the sense that it's agnostic to the contents and purpose of the `Step` that it creates.
81+
However, in many cases there are helper methods to create `Step`s for various purposes.
82+
For instance, the `std.Build.installArtifact` method creates a `std.Build.Step.InstallArtifact` and adds its step as a dependency of the top-level "install" step.
83+
This ensures that some artifact will be installed to `zig-out` when `zig build install` or `zig build` (since "install" is the default step) are run.
84+
It's also possible to use the `std.Build.addInstallArtifact` method to create an `InstallArtifact` step that _isn't_ tied to the top-level "install" step, which gives you the ability to install an artifact as part of some other build step.
85+
86+
Another helper method to be aware of is `std.Build.addExecutable`, which was shown in the previous section.
87+
This helper method creates a `std.Build.Step.Compile`, which is one of the arguments required by the `std.Build.installArtifact` method.
88+
This is why in examples you'll frequently see both `addExecutable` and `installArtifact`.
89+
This may give you the impression that "executable" and "artifact" are different kinds of entities that you need to know about in order to write your `build.zig`, but it really just boils down to `Step`s.
90+
6791
## [Adding a Convenience Step for Running the Application]($heading.id('run-step'))
6892

6993
It is common to add a **Run** step to provide a way to run one's main application directly

0 commit comments

Comments
 (0)