Hello, I wanted to add a build option of type []T
where T
is an enum I made. However, it seems like the Zig build system generated incorrect code for the options.zig
file, resulting in a compile error.
I’m using Zig version 0.12.0-dev.3522+b88ae8dbd
.
Here is the build.zig
code for example:
const std = @import("std");
const Animal = enum {
refrigerator,
sun,
apple,
};
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const opts = b.addOptions();
opts.addOption([]Animal, "animals", @constCast(&[_]Animal{ .sun, .apple, .refrigerator }));
const exe = b.addExecutable(.{
.name = "test",
.root_source_file = .{ .path = "main.zig" },
.target = target,
.optimize = optimize,
});
b.installArtifact(exe);
exe.root_module.addImport("options", opts.createModule());
}
Here is the main.zig
file:
const _ = @import("options");
pub fn main() void {}
Here is the generated options.zig
file:
pub const animals: []build.Animal = &[_]build.Animal {
pub const @"build.Animal" = enum (u2) {
refrigerator = 0,
sun = 1,
apple = 2,
};
};