authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-08-04 22:54:59-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-08-04 22:54:59-07:00
log2139697ce548db8a80cf2999a8196836f2e39aef
treea1bb0ae206c6fd32d6ae054b086ea44c7e10499b
parent316b4bde6a118c0742eee0d45137268a1dc99a26

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


2 files changed, 28 insertions(+), 10 deletions(-)

build.zig-1
...@@ -107,7 +107,6 @@ pub fn build(b: *Builder) !void {...@@ -107,7 +107,6 @@ pub fn build(b: *Builder) !void {
107 const is_wasmtime_enabled = b.option(bool, "enable-wasmtime", "Use Wasmtime to enable and run WASI libstd tests") orelse false;107 const is_wasmtime_enabled = b.option(bool, "enable-wasmtime", "Use Wasmtime to enable and run WASI libstd tests") orelse false;
108 const glibc_multi_dir = b.option([]const u8, "enable-foreign-glibc", "Provide directory with glibc installations to run cross compiled tests that link glibc");108 const glibc_multi_dir = b.option([]const u8, "enable-foreign-glibc", "Provide directory with glibc installations to run cross compiled tests that link glibc");
109109
110
111 test_stage2.addBuildOption(bool, "enable_qemu", is_qemu_enabled);110 test_stage2.addBuildOption(bool, "enable_qemu", is_qemu_enabled);
112 test_stage2.addBuildOption(bool, "enable_wine", is_wine_enabled);111 test_stage2.addBuildOption(bool, "enable_wine", is_wine_enabled);
113 test_stage2.addBuildOption(bool, "enable_wasmtime", is_wasmtime_enabled);112 test_stage2.addBuildOption(bool, "enable_wasmtime", is_wasmtime_enabled);
lib/std/build.zig+28-9
...@@ -1708,15 +1708,34 @@ pub const LibExeObjStep = struct {...@@ -1708,15 +1708,34 @@ pub const LibExeObjStep = struct {
17081708
1709 pub fn addBuildOption(self: *LibExeObjStep, comptime T: type, name: []const u8, value: T) void {1709 pub fn addBuildOption(self: *LibExeObjStep, comptime T: type, name: []const u8, value: T) void {
1710 const out = self.build_options_contents.outStream();1710 const out = self.build_options_contents.outStream();
1711 if (T == []const []const u8) {1711 switch (T) {
1712 out.print("pub const {}: []const []const u8 = &[_][]const u8{{\n", .{name}) catch unreachable;1712 []const []const u8 => {
1713 for (value) |slice| {1713 out.print("pub const {}: []const []const u8 = &[_][]const u8{{\n", .{name}) catch unreachable;
1714 out.writeAll(" ") catch unreachable;1714 for (value) |slice| {
1715 std.zig.renderStringLiteral(slice, out) catch unreachable;1715 out.writeAll(" ") catch unreachable;
1716 out.writeAll(",\n") catch unreachable;1716 std.zig.renderStringLiteral(slice, out) catch unreachable;
1717 }1717 out.writeAll(",\n") catch unreachable;
1718 out.writeAll("};\n") catch unreachable;1718 }
1719 return;1719 out.writeAll("};\n") catch unreachable;
1720 return;
1721 },
1722 []const u8 => {
1723 out.print("pub const {}: []const u8 = ", .{name}) catch unreachable;
1724 std.zig.renderStringLiteral(value, out) catch unreachable;
1725 out.writeAll(";\n") catch unreachable;
1726 return;
1727 },
1728 ?[]const u8 => {
1729 out.print("pub const {}: ?[]const u8 = ", .{name}) catch unreachable;
1730 if (value) |payload| {
1731 std.zig.renderStringLiteral(payload, out) catch unreachable;
1732 out.writeAll(";\n") catch unreachable;
1733 } else {
1734 out.writeAll("null;\n") catch unreachable;
1735 }
1736 return;
1737 },
1738 else => {},
1720 }1739 }
1721 switch (@typeInfo(T)) {1740 switch (@typeInfo(T)) {
1722 .Enum => |enum_info| {1741 .Enum => |enum_info| {