#Copy compile options around
1 messages · Page 1 of 1 (latest)
not sure I understand
if you just want to share a bunch of values from a file, just make a file with a bunch of pub consts
doesn't need to be var
Well for instance, how would I go about querying the build target in a source file?
builtin.os.tag is just the native OS, right?
no, that's the compilation target
though should be noted that in a build.zig, it is always the native target, because that is just compiled into an executable that is executed on your machine
Or, say I want to get a compile option passed via -D, how should I get that value from build.option()
that's, just how you get it?
you say b.option(T, "foo", "bar") orelse ..., store that, and then you make that available through whatever means you want
the most common way is to use b.addOptions()
that returns a build step which will construct a file of values
Okay, I'm probably just overcomplicating it/being picky about how to doit
e.g.
const build_options = b.addOptions();
exe.addOptions("build-options", build_options);
build_options.addOption(bool, "foo", true); // adds `pub const foo = true;`
this then allows you to do @import("build-options").foo in your exe
the value passed as the third parameter can be whatever you want, including the result of a call to b.option(...)
Oh okay, great, exactly what I was looking for. I'd just been doing build.option and storing the return in a local variable, and getting annoyed that I had to copy it to a var elsewhere