zig build: fix addBuildOption for []const u8 and ?[]const u8

This commit is contained in:
Andrew Kelley 2020-08-04 22:54:59 -07:00
parent 8824491fc7
commit f23fb3087b
2 changed files with 28 additions and 10 deletions

View File

@ -107,7 +107,6 @@ pub fn build(b: *Builder) !void {
const is_wasmtime_enabled = b.option(bool, "enable-wasmtime", "Use Wasmtime to enable and run WASI libstd tests") orelse false;
const glibc_multi_dir = b.option([]const u8, "enable-foreign-glibc", "Provide directory with glibc installations to run cross compiled tests that link glibc");
test_stage2.addBuildOption(bool, "enable_qemu", is_qemu_enabled);
test_stage2.addBuildOption(bool, "enable_wine", is_wine_enabled);
test_stage2.addBuildOption(bool, "enable_wasmtime", is_wasmtime_enabled);

View File

@ -1708,15 +1708,34 @@ pub const LibExeObjStep = struct {
pub fn addBuildOption(self: *LibExeObjStep, comptime T: type, name: []const u8, value: T) void {
const out = self.build_options_contents.outStream();
if (T == []const []const u8) {
out.print("pub const {}: []const []const u8 = &[_][]const u8{{\n", .{name}) catch unreachable;
for (value) |slice| {
out.writeAll(" ") catch unreachable;
std.zig.renderStringLiteral(slice, out) catch unreachable;
out.writeAll(",\n") catch unreachable;
}
out.writeAll("};\n") catch unreachable;
return;
switch (T) {
[]const []const u8 => {
out.print("pub const {}: []const []const u8 = &[_][]const u8{{\n", .{name}) catch unreachable;
for (value) |slice| {
out.writeAll(" ") catch unreachable;
std.zig.renderStringLiteral(slice, out) catch unreachable;
out.writeAll(",\n") catch unreachable;
}
out.writeAll("};\n") catch unreachable;
return;
},
[]const u8 => {
out.print("pub const {}: []const u8 = ", .{name}) catch unreachable;
std.zig.renderStringLiteral(value, out) catch unreachable;
out.writeAll(";\n") catch unreachable;
return;
},
?[]const u8 => {
out.print("pub const {}: ?[]const u8 = ", .{name}) catch unreachable;
if (value) |payload| {
std.zig.renderStringLiteral(payload, out) catch unreachable;
out.writeAll(";\n") catch unreachable;
} else {
out.writeAll("null;\n") catch unreachable;
}
return;
},
else => {},
}
switch (@typeInfo(T)) {
.Enum => |enum_info| {