Skip to content

Commit

Permalink
zig build: fix addBuildOption for []const u8 and ?[]const u8
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrk committed Aug 5, 2020
1 parent 316b4bd commit 2139697
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
1 change: 0 additions & 1 deletion build.zig
Expand Up @@ -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);
Expand Down
37 changes: 28 additions & 9 deletions lib/std/build.zig
Expand Up @@ -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| {
Expand Down

0 comments on commit 2139697

Please sign in to comment.