mirror of
https://github.com/ziglang/zig.git
synced 2024-11-27 15:42:49 +00:00
zig build: fix addBuildOption for []const u8
and ?[]const u8
This commit is contained in:
parent
8824491fc7
commit
f23fb3087b
@ -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);
|
||||
|
@ -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| {
|
||||
|
Loading…
Reference in New Issue
Block a user