New Zig Build System Documentation

https://ziglang.org/learn/build-system/

@kristoff and I have been working together on a guide for the Zig Build System. We plan to eventually merge it into the Zig standard library docs, but in the meantime you can access it directly from the official website.

31 Likes

Something I’ve wondered about and can’t seem to find in any docs is how to access the information inside build.zig.zon from my build.zig

For deps it’s pretty easy, but what about information like the name and version?

2 Likes

Very nice! Just to point out, more as a note to self though, the very last example is a better version of what I was trying to come up with in a past discussion!

1 Like

Thank you Andrew and Loris for such a useful piece of documentation explaining in one place how zig build system works. It would also help to shed some more light on zig modules and packages. Currently the link to Package Management section does not work for me.

5 Likes

I forgot to mention, Package Management and Wrangling Third-Party Software Dependencies sections coming later.

I have this skeleton drafted out, but since they’re not done, they are omitted for now:

Package Management

The Manifest File

In order to fetch code from an external location, all dependencies must be listed in the
build manifest file - build.zig.zon. This way, package-related tooling can have a complete list of possible dependencies without the need to execute arbitrary code.

The Package Hash

Depending on a Zig Module

Making a Release

mention zig fetch

Dealing with Symlinks

Running a Tool from a Dependency

nasm example

Wrangling Third-Party Software Dependencies

When a project that you depend on uses the Zig Build System, you can refer to
the Package Management section. However, there is plenty of useful software out there whose maintainers have no plan to migrate to Zig. Fortunately, even such projects can be added seamlessly to the Zig ecosystem with the following techniques. Note that bullying the maintainers into using Zig is not listed here!!

Building C/C++ Files (.c, .cpp)

Configuring C header files (.h)

Packaging a C Library for the Zig Ecosystem

Pristine Tarball Strategy

Fork Strategy

15 Likes