How to pass compiler flags with `zig build`?

Might be a noob question here, but I’ve searched online without any answers.

But when I tried this:

zig build run -Doptimize=ReleaseFast -- -fsingle-threaded

it seems not working.

Why?

Those are options that you should pass to addExecutable Documentation - Zig in your build.zig file.

Not all options are available in addExecutable, but you can also set the options afterwards:

exe.single_threaded = true;
exe.strip = true; // Not available in addExecutable
1 Like

Thanks friends. It looks build.zig is a completely different approach to zig build-exe.

just a related question

Note that you can expose options to the user with b.option(). These will show up in the zig build --help menu, and then you can use normal branching logic on the values to do whatever you want with them.

2 Likes