#how do I add a compile option to my build system?

1 messages · Page 1 of 1 (latest)

solemn wedge
#

Hi, How do I add someting like zig build -DCustomOption in my zig build? this custom option must be also be visible inside the code, I was trying the addOptions function but I'm not getting nowhere...

#

how do I add a compile option to my build system?

full wyvern
#

something like this. i haven't tested this code, but adapted it from another project which works.

pub fn build(b: *Builder) !void {
    const exe = ...
    const options = b.addOptions();
    const option = b.option(bool, "name", "description") orelse false;
    options.addOption(bool, "name", option);
    exe.addModule("build_options", options.createModule());
}
#

after this, you can pass this option like

zig build -Dname
#

i think for booleans adding =true is optional

#

and in your code,

const build_options = @import"build_options");
const name = build_options.name:
solemn wedge
#

thanks!

full wyvern
#

note that you'll have to add the module to any other tests or exe/libs you want to use it in

#

*note

#

and after this, the option will show up in zig build --help