#Switch on zig version within build.zig to deal with breaking changes in std.build.Builder

1 messages · Page 1 of 1 (latest)

untold marsh
#

Hey, dumb question, is it possible to switch on the zig compiler version within build.zig? exe.addLibPath was renamed to exe.addLibraryPath. exe.addIncludeDir was renamed to exe.addIncludePath. I have different environments running different zig versions and I was wondering if I could comptime switch on the function to call. Maybe that's not how comptime works.

wild trail
#

i think you can use @import("builtin").zig_version, which is an std.SemanticVersion

#

or you can use @hasDecl

untold marsh
#

Again, dumb question, sorry. It looks like I can use hasDecl but then inside the comptime section it wants to evaluate the addLibraryPath call at comptime (which makes sense).

comptime if (@hasDecl(@TypeOf(exe.*), "addLibPath")) {
  exe.addLibPath("./rocksdb");
  exe.addIncludeDir("./rocksdb/include");
} else {
  exe.addLibraryPath("./rocksdb");
  exe.addIncludePath("./rocksdb/include");
};
#

I want to comptime switch but have the if body not be run at comptime

wild trail
#

i don't think you need the comptime keyword if you're using if or switch. if the argument is compile-time known, i think it'll automatically ignore the unused branches

untold marsh
#

oh, duh! Yeah that works

#

thank you!