# Optional Build Flags For Software Built from Source

**URL:** <https://ziggit.dev/t/optional-build-flags-for-software-built-from-source/1209>\
**Category:** Help\
**Tags:** build-system\
**Created:** [July 18, 2023, 3:56am UTC](https://ziggit.dev/t/optional-build-flags-for-software-built-from-source/1209 "2023-07-18T03:56:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cebidaez](https://ziggit.dev/user_avatar/ziggit.dev/cebidaez/32/721_2.png) [@cebidaez](https://ziggit.dev/u/cebidaez)\
**Post date:** [July 18, 2023, 3:56am UTC](https://ziggit.dev/t/optional-build-flags-for-software-built-from-source/1209/1 "2023-07-18T03:56:13Z")

</div>

Zig Showtime made a video on the process of building code from source. I thought it was really good, but one thing I began considering was how would someone build in a similar manner in zig?

For instance the video mentions `./configure` as a means of enabling or disabling flags to enable or disable parts of the software. How would one do a similar thing within projects that are built from build.zig? I know that zig build has options but aren’t those all pertaining to the optimizations for a specific OS/CPU? As far as I know these zig build flags are exposed to all programs that leverage build.zig. But there isn’t a way to add application specific flags. What about optional program features like to compile with say Wayland support or X11 support for instance?

---

<div class="post-metadata">

**Author:** ![tensorush](https://ziggit.dev/letter_avatar_proxy/v4/letter/t/6a8cbe/32.png) [@tensorush](https://ziggit.dev/u/tensorush)\
**Post date:** [July 18, 2023, 12:22pm UTC](https://ziggit.dev/t/optional-build-flags-for-software-built-from-source/1209/2 "2023-07-18T12:22:51Z")

</div>

@cebidaez Correct me if I’m misunderstanding your questions, but the way Zig build system provides the configure phase for the “building from source” scenario is by enabling to specify the build graph through many different [steps](https://github.com/ziglang/zig/tree/master/lib/std/Build/Step) that may depend on each other in any arbitrary (but non-cyclic) way.

So, for instance, after defining the necessary steps you are able to pass arguments to run artifacts after `--` like so: `zig build -- arg = 1`, or compile only parts of the software by providing flags (they are called [options](https://github.com/ziglang/zig/blob/master/lib/std/Build.zig#L808) at the moment) after ` -D`: `zig build -Doption`.

By the way, here’s the discussed video for anyone wondering:

[![](https://ziggit.dev/uploads/default/original/1X/1275f550f04155155ac9ff8837b0deffafdaf8e7.jpeg "How to Build Software From Source - Andrew Kelley - Software You Can Love Vancouver 2023") ](https://www.youtube.com/watch?v=CwXixVcliP0)

---

<div class="post-metadata">

**Author:** ![kristoff](https://ziggit.dev/user_avatar/ziggit.dev/kristoff/32/9_2.png) [@kristoff](https://ziggit.dev/u/kristoff)\
**Post date:** [July 18, 2023, 12:29pm UTC](https://ziggit.dev/t/optional-build-flags-for-software-built-from-source/1209/3 "2023-07-18T12:29:38Z")

</div>

The way understood the post, I think OP was asking about options.

Here’s for example how zls adds extra build options to its build commands:

> <https://github.com/zigtools/zls/blob/8da21e159e3dec9bc6fe01320313cf8108ce4d0b/build.zig#L26-L43>

---

<div class="post-metadata">

**Author:** ![cebidaez](https://ziggit.dev/user_avatar/ziggit.dev/cebidaez/32/721_2.png) [@cebidaez](https://ziggit.dev/u/cebidaez)\
**Post date:** [July 18, 2023, 5:43pm UTC](https://ziggit.dev/t/optional-build-flags-for-software-built-from-source/1209/4 "2023-07-18T17:43:32Z")

</div>

Would these exe options be added at runtime or passed at build time to add in optional functionality to the final executable/library? Sorry for the ambiguity but the nature of the flags I was talking about was similar to that of USE Flags of Gentoo I guess. I hope that clears things up. I think @tensorrush response is similar to what I was envisioning.

---

<div class="post-metadata">

**Author:** ![kristoff](https://ziggit.dev/user_avatar/ziggit.dev/kristoff/32/9_2.png) [@kristoff](https://ziggit.dev/u/kristoff)\
**Post date:** [July 18, 2023, 6:16pm UTC](https://ziggit.dev/t/optional-build-flags-for-software-built-from-source/1209/5 "2023-07-18T18:16:53Z")

</div>

options in the build system are passed at build time, what you put after `--` is passed at runtime when the application runs

```sh
$ zig build run -- foo bar

```

is the same as doing

```sh
$ zig build 
$ ./zig-out/bin/your_program foo bar

```

---

<div class="post-metadata">

**Author:** ![cebidaez](https://ziggit.dev/user_avatar/ziggit.dev/cebidaez/32/721_2.png) [@cebidaez](https://ziggit.dev/u/cebidaez)\
**Post date:** [July 18, 2023, 10:54pm UTC](https://ziggit.dev/t/optional-build-flags-for-software-built-from-source/1209/6 "2023-07-18T22:54:47Z")

</div>

Alright thank you for the clarification! I realize now that the Options are what I was talking about.
