# zig build: support dependencies · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/cfcf9771c1bde357ad64d81cda9d61ba72d80b15)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: cfcf9771c1bde357ad64d81cda9d61ba72d80b15

Requested commit: cfcf9771c1bde357ad64d81cda9d61ba72d80b15

Commit: cfcf9771c1bde357ad64d81cda9d61ba72d80b15

Tree: 143a7434666e186bc79989c9108fdc3ab1c16741

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

````
zig build: support dependencies

The `zig build` command now makes `@import("@dependencies")` available
to the build runner package. It contains all the dependencies in a
generated file that looks something like this:

```zig
pub const imports = struct {
    pub const foo = @import("foo");
    pub const @"bar.baz" = @import("bar.baz");
};
pub const build_root = struct {
    pub const foo = "<path>";
    pub const @"bar.baz" = "<path>";
};
```

The build runner exports this import so that `std.build.Builder` can
access it. `std.build.Builder` uses it to implement the new `dependency`
function which can be used like so:

```zig
const libz_dep = b.dependency("libz", .{});
const libmp3lame_dep = b.dependency("libmp3lame", .{});
// ...
lib.linkLibrary(libz_dep.artifact("z"));
lib.linkLibrary(libmp3lame_dep.artifact("mp3lame"));
```

The `dependency` function calls the build.zig file of the dependency as
a child Builder, and then can be ransacked for its build steps via the
`artifact` function.

This commit also renames `dependency.id` to `dependency.name` in the
`build.zig.ini` file.

````

## Parents

- [a0f2e6a29f4d5c084a248d24b25fae9f30707001](https://git.cafe/gitcafe/zig/commit/a0f2e6a29f4d5c084a248d24b25fae9f30707001?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/cfcf9771c1bde357ad64d81cda9d61ba72d80b15?format=markdown)
