zig icon indicating copy to clipboard operation
zig copied to clipboard

Build/Options: fix for struct array/slice and optional struct options

Open tw4452852 opened this issue 1 year ago • 2 comments

Closes #19656 Closes #19594

tw4452852 avatar Aug 18 '24 07:08 tw4452852

This looks like it fixes #19656 and #19594, can you confirm?

Vexu avatar Aug 18 '24 09:08 Vexu

@Vexu Yes, I confirmed that both of issues can be fixed by this PR.

tw4452852 avatar Aug 19 '24 00:08 tw4452852

Any feedback about this PR?

tw4452852 avatar Aug 27 '24 03:08 tw4452852

Also, there are optional enums that doesn't work. This patch should work (+ some test):

diff --git a/lib/std/Build/Step/Options.zig b/lib/std/Build/Step/Options.zig
index 8348d74..e05255c 100644
--- a/lib/std/Build/Step/Options.zig
+++ b/lib/std/Build/Step/Options.zig
@@ -272,12 +272,17 @@ fn printType(options: *Options, out: anytype, comptime T: type, value: T, indent
             try printEnum(options, out, T, info, indent);
 
             if (name) |some| {
-                try out.print("pub const {}: {} = .{p_};\n", .{
+                try out.print("pub const {}: {} = ", .{
                     std.zig.fmtId(some),
                     std.zig.fmtId(@typeName(T)),
-                    std.zig.fmtId(@tagName(value)),
                 });
             }
+
+            if (indent == 0)
+                try out.print(".{p_};\n", .{std.zig.fmtId(@tagName(value))})
+            else
+                try out.print(".{p_},\n", .{std.zig.fmtId(@tagName(value))});
+
             return;
         },
         .@"struct" => |info| {

Reokodoku avatar Feb 10 '25 20:02 Reokodoku