# Build System Tricks

**URL:** <https://ziggit.dev/t/build-system-tricks/3531>\
**Category:** Docs\
**Tags:** build-system, zig-master\
**Created:** [March 11, 2024, 8:51am UTC](https://ziggit.dev/t/build-system-tricks/3531 "2024-03-11T08:51:10Z")\
**Posts on this page:** 12\
**Page:** 2

<div class="post-metadata">

**Author:** ![FObersteiner](https://ziggit.dev/user_avatar/ziggit.dev/fobersteiner/32/1177_2.png) [@FObersteiner](https://ziggit.dev/u/FObersteiner)\
**Post date:** [May 9, 2024, 2:43pm UTC](https://ziggit.dev/t/build-system-tricks/3531/21 "2024-05-09T14:43:16Z")

</div>

done. I wonder if somebody eventually comes up with a gigantic project with all the tricks shown, just because they can ^^

---

<div class="post-metadata">

**Author:** ![ktz\_alias](https://ziggit.dev/user_avatar/ziggit.dev/ktz_alias/32/1202_2.png) [@ktz\_alias](https://ziggit.dev/u/ktz_alias)\
**Post date:** [May 29, 2024, 4:44am UTC](https://ziggit.dev/t/build-system-tricks/3531/22 "2024-05-29T04:44:50Z")

</div>

FYI

For version 0.13.0, It must not use cwd\_relative variant of LazyPath in package build script.  
(but absolute path does not affect)

The cwd\_relative variant is the relative path from root module.  
Using cwd\_relative in package build script lead to occur `File not found` error.

---

<div class="post-metadata">

**Author:** ![AndrewCodeDev](https://ziggit.dev/letter_avatar_proxy/v4/letter/a/278dde/32.png) [@AndrewCodeDev](https://ziggit.dev/u/AndrewCodeDev)\
**Post date:** [May 29, 2024, 5:20am UTC](https://ziggit.dev/t/build-system-tricks/3531/23 "2024-05-29T05:20:14Z")

</div>

Thanks for the feedback - feel free to update the doc if you can. If you can’t, someone can implement your changes if you 'd like to suggest an alternative (just post some code and we’ll work out the details).

---

<div class="post-metadata">

**Author:** ![FObersteiner](https://ziggit.dev/user_avatar/ziggit.dev/fobersteiner/32/1177_2.png) [@FObersteiner](https://ziggit.dev/u/FObersteiner)\
**Post date:** [May 29, 2024, 11:52am UTC](https://ziggit.dev/t/build-system-tricks/3531/24 "2024-05-29T11:52:44Z")

</div>

just changed two more of those, hope we got them all now.

---

<div class="post-metadata">

**Author:** ![ktz\_alias](https://ziggit.dev/user_avatar/ziggit.dev/ktz_alias/32/1202_2.png) [@ktz\_alias](https://ziggit.dev/u/ktz_alias)\
**Post date:** [June 5, 2024, 9:48am UTC](https://ziggit.dev/t/build-system-tricks/3531/25 "2024-06-05T09:48:30Z")

</div>

In " 3) Declare dependencies as well as their artifacts and modules upfront",  
Add description for bundling the dependency artifact.

---

<div class="post-metadata">

**Author:** ![dimdin](https://ziggit.dev/user_avatar/ziggit.dev/dimdin/32/1457_2.png) [@dimdin](https://ziggit.dev/u/dimdin)\
**Post date:** [June 5, 2024, 10:08am UTC](https://ziggit.dev/t/build-system-tricks/3531/26 "2024-06-05T10:08:04Z")

</div>

From [Package Management in 0.11.0 Release Notes](https://ziglang.org/download/0.11.0/release-notes.html#Package-Management)

> any artifact which is installed (for instance, via `std.Build.installArtifact`) is exposed to dependant packages.

---

<div class="post-metadata">

**Author:** ![ktz\_alias](https://ziggit.dev/user_avatar/ziggit.dev/ktz_alias/32/1202_2.png) [@ktz\_alias](https://ziggit.dev/u/ktz_alias)\
**Post date:** [June 5, 2024, 12:36pm UTC](https://ziggit.dev/t/build-system-tricks/3531/27 "2024-06-05T12:36:53Z")

</div>

In following situation, it need calling `installArtifact` for dependency artifact.

```zig
/ (project root)
  |_ owner module (exe)
  |_ child_1 module (exe)
  |_ child_2 module (exe)

```

where `owner module` is depends on `child_1 module` and `child_2 module` because of spawning `these artifacts.

Probably, if dependency artifact is linked only as the static library, it will not need calling `installArtifact`.

* * *

…And in this case, it did not need to call `dependsOn`.

---

<div class="post-metadata">

**Author:** ![dimdin](https://ziggit.dev/user_avatar/ziggit.dev/dimdin/32/1457_2.png) [@dimdin](https://ziggit.dev/u/dimdin)\
**Post date:** [June 5, 2024, 12:44pm UTC](https://ziggit.dev/t/build-system-tricks/3531/28 "2024-06-05T12:44:15Z")

</div>

> [@ktz\_alias](#):
>
> if dependency artifact is linked only as the static library, it will not need calling `installArtifact`.

Why not? Even the `build.zig` from `zig init` calls it:

> <https://github.com/ziglang/zig/blob/332fbb4b027a5529e58b1e46d785718a7faa75e6/lib/init/build.zig#L18-L30>

> [@ktz\_alias](#):
>
> it did not need to call `dependsOn`

[addInstallArtifact](https://ziglang.org/documentation/master/std/#std.Build.addInstallArtifact) is [installArtifact](https://ziglang.org/documentation/master/std/#std.Build.installArtifact) without establishing the install step dependency.

---

<div class="post-metadata">

**Author:** ![haydenridd](https://ziggit.dev/user_avatar/ziggit.dev/haydenridd/32/2375_2.png) [@haydenridd](https://ziggit.dev/u/haydenridd)\
**Post date:** [June 6, 2024, 6:03pm UTC](https://ziggit.dev/t/build-system-tricks/3531/29 "2024-06-06T18:03:57Z")

</div>

Added:

- 
  1. System tool Tricks under “Extra Steps”

- 
  1. Code generation tricks under “Extra Steps”

- 
  1. Code generation tricks under “C Dependencies”

Since I recently had to do some of this stuff! Double checked all I added on `12.0.0` so should be correct but sanity checks are encouraged.

---

<div class="post-metadata">

**Author:** ![Sze](https://ziggit.dev/user_avatar/ziggit.dev/sze/32/496_2.png) [@Sze](https://ziggit.dev/u/Sze)\
**Post date:** [June 10, 2024, 7:23am UTC](https://ziggit.dev/t/build-system-tricks/3531/30 "2024-06-10T07:23:57Z")

</div>

I activated to show the table of contents for this topic.

I don’t know why its only showing the top headings from the docs view,  
but from the forum view it also shows the sub-headings.

---

<div class="post-metadata">

**Author:** ![\_sh](https://ziggit.dev/user_avatar/ziggit.dev/_sh/32/8461_2.png) [@\_sh](https://ziggit.dev/u/_sh)\
**Post date:** [November 25, 2024, 12:12am UTC](https://ziggit.dev/t/build-system-tricks/3531/31 "2024-11-25T00:12:53Z")

</div>

I’m working on a library that requires the use of `addSystemCommand`, where the binary path may need to be changed by the user, since there are many different versions and you may need a specific one to generate bindings.

```zig
    const godot_path = b.option([]const u8, "godot-path", "Path to Godot binary [default: `godot`]") orelse "godot";

    const dump_cmd = b.addSystemCommand(&.{
        godot_path, "--dump-extension-api", "--dump-gdextension-interface", "--headless",
    });

```

When I try to provide a new path as part of a parent `build.zig` where this library is a dependency, it tells me that that option does not exist, and it’s not present in “Project-Specific Options” when running `zig build --help`

---

<div class="post-metadata">

**Author:** ![\_sh](https://ziggit.dev/user_avatar/ziggit.dev/_sh/32/8461_2.png) [@\_sh](https://ziggit.dev/u/_sh)\
**Post date:** [November 25, 2024, 12:47am UTC](https://ziggit.dev/t/build-system-tricks/3531/32 "2024-11-25T00:47:05Z")

</div>

Answering my own question here 😅. If I had just spent 10 more minutes I would have come across the answer.

Answer: You can pass build options from your `build.zig` to a dependency via the `args` parameter. Make sure they actually match.

`build.zig`

```zig
const lib_godot = b.dependency("godot", .{
    .godot_path = godot_path,
});

```

Dependency `build.zig`

```zig
const godot_path = b.option([]const u8, "godot_path", "Path to Godot binary [default: `godot`]") orelse "godot";

```

[Previous page](https://ziggit.dev/t/build-system-tricks/3531.md?page=1)
