authorgravatar for i.am@ceph3.usMichael Holmes <i.am@ceph3.us> 2021-04-05 22:54:04+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-04-06 11:09:54-07:00
log38d8aab4d283efe2f43c7e18411f6df7e1c2d04b
tree48f7cb8ce6b1ce46361b867c6ebe6a5646bea667
parent89df41e5d859fcd53863c9f707e8c697b794148c

std/build: fix ?[:0]const u8 build options

As per the other string types, `?[:0]const u8` needs its own case as otherwise it will raise an error about using `{}` with slices. There's no reasonable workaround for this, as you would have to either discount the use of the empty string value or manually rework the string to be sentinel-terminated at runtime. It's useful for passing build options to code making use of C libraries that make strong use of sentinel-terminated arrays for strings.

1 files changed, 9 insertions(+), 0 deletions(-)

lib/std/build.zig+9
...@@ -1939,6 +1939,15 @@ pub const LibExeObjStep = struct {...@@ -1939,6 +1939,15 @@ pub const LibExeObjStep = struct {
1939 out.print("pub const {}: []const u8 = \"{}\";\n", .{ std.zig.fmtId(name), std.zig.fmtEscapes(value) }) catch unreachable;1939 out.print("pub const {}: []const u8 = \"{}\";\n", .{ std.zig.fmtId(name), std.zig.fmtEscapes(value) }) catch unreachable;
1940 return;1940 return;
1941 },1941 },
1942 ?[:0]const u8 => {
1943 out.print("pub const {}: ?[:0]const u8 = ", .{std.zig.fmtId(name)}) catch unreachable;
1944 if (value) |payload| {
1945 out.print("\"{}\";\n", .{std.zig.fmtEscapes(payload)}) catch unreachable;
1946 } else {
1947 out.writeAll("null;\n") catch unreachable;
1948 }
1949 return;
1950 },
1942 ?[]const u8 => {1951 ?[]const u8 => {
1943 out.print("pub const {}: ?[]const u8 = ", .{std.zig.fmtId(name)}) catch unreachable;1952 out.print("pub const {}: ?[]const u8 = ", .{std.zig.fmtId(name)}) catch unreachable;
1944 if (value) |payload| {1953 if (value) |payload| {