zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 2139697ce548db8a80cf2999a8196836f2e39aef (tree)
parent 316b4bde6a118c0742eee0d45137268a1dc99a26
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Tue,  4 Aug 2020 22:54:59 -0700

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

Diffstat:
Mbuild.zig | 1-
Mlib/std/build.zig | 37++++++++++++++++++++++++++++---------
2 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/build.zig b/build.zig @@ -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); diff --git a/lib/std/build.zig b/lib/std/build.zig @@ -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| {