#how to set cli args in build.zig
1 messages · Page 1 of 1 (latest)
-O style options aren't possible
the equivalent is -Dflag and -Dkey=value syntax
you can set up build options with b.option(...)
// this makes it so you can pass `-Dflag`, `-Dflag=false`, or `-Dflag=true`.
// if unspecified the call will return `null`, and in this case that's handled
// by `orelse false`.
const flag = b.option(bool, "flag", "Flag description") orelse false;
// this makes it so you can pass `-Dstring=str`, where `str` is an arbitrary
// string of text. similar behaviour when unspecified.
const string = b.option([]const u8, "string", "String description") orelse "foo";
// this makes it so you can pass `-Dscalar=n`, where `n` is a string parsed
// by `std.fmt.parseInt`. similar behaviour when unspecified.
const scalar = b.option(i64, "scalar", "Scalar description") orelse -1;
// this makes it so you can pass `-Denumeration=bar`, or `-Denumeration=baz`.
// similar behaviour when unspecified.
const enumeration = b.option(enum { bar, baz }, "enumeration", "Enumeration description") orelse .bar;
// where `T` is a type similar to any of the aforementioned types of build options,
// this makes it so you can pass `-Dlist={val}` multiple times with multiple values,
// constructing a list. For example, with `T=u16` `-Dlist=1 -Dlist=2 -Dlist=5` would
// construct a list like `&[]u16{ 1, 2, 5 }`.
// similar behaviour when unspecified.
const list = b.option([]const T, "list", "List description") orelse &.{};
im guessing they meant the equivalent of those flags, optimize and strip
also TIL thats how the list stuff works, i could never figure it out lol
yes
alright yeah, in that case it's quite simple
if you used zig init-exe to start a project it already provides the optimization flag
for the strip flag you have to set the strip field of your exe/lib. best way imo is exe.strip = b.option(bool, "strip", ""); which exposes a strip flag to the cli so you can override it but it still keeps the default behavior of stripping under ReleaseSmall
so the equivalent of your original question after adding that is -Doptimize=ReleaseFast -Dstrip
tysm