Optional Build Flags For Software Built from Source

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?

1 Like

@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 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 at the moment) after -D: zig build -Doption.

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

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:

1 Like

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.

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

$ zig build run -- foo bar

is the same as doing

$ zig build 
$ ./zig-out/bin/your_program foo bar
2 Likes

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