#Getting version from build.zig.zon?

1 messages · Page 1 of 1 (latest)

vestal pine
#

I want to get the version in build.zig.zon from src/main.zig so I can print it if I run main -v. How can I do that?

carmine sun
#

in your build.zig:

var options = b.addOptions();
options.addOption([]const u8, "version", @import("build.zig.zon").version);
exe.root_module.addOptions("options", options);

then in your code you can do:

const version = @import("options").version;
#

i suppose you could even import the build.zig.zon file in your code directly bypassing build.zig entirely, but i think this is probably the standard way to do this