authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-01-31 14:57:20-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-01-31 15:09:35-07:00
log3c1fc3f566b4a0c4493187c7f07b5c401a3e3a1b
tree8b54851826302914d2b0b77ae733628cea022c69
parent2f5892671e49850070064f689a7d8f93d6a7a0dd

std.Build.ConfigHeaderStep: support more types


1 files changed, 44 insertions(+), 32 deletions(-)

lib/std/Build/ConfigHeaderStep.zig+44-32
...@@ -61,39 +61,51 @@ pub fn addValues(self: *ConfigHeaderStep, values: anytype) void {...@@ -61,39 +61,51 @@ pub fn addValues(self: *ConfigHeaderStep, values: anytype) void {
6161
62fn addValuesInner(self: *ConfigHeaderStep, values: anytype) !void {62fn addValuesInner(self: *ConfigHeaderStep, values: anytype) !void {
63 inline for (@typeInfo(@TypeOf(values)).Struct.fields) |field| {63 inline for (@typeInfo(@TypeOf(values)).Struct.fields) |field| {
64 switch (@typeInfo(field.type)) {64 try putValue(self, field.name, field.type, @field(values, field.name));
65 .Null => {65 }
66 try self.values.put(field.name, .undef);66}
67 },
68 .Void => {
69 try self.values.put(field.name, .defined);
70 },
71 .Bool => {
72 try self.values.put(field.name, .{ .boolean = @field(values, field.name) });
73 },
74 .ComptimeInt => {
75 try self.values.put(field.name, .{ .int = @field(values, field.name) });
76 },
77 .EnumLiteral => {
78 try self.values.put(field.name, .{ .ident = @tagName(@field(values, field.name)) });
79 },
80 .Pointer => |ptr| {
81 switch (@typeInfo(ptr.child)) {
82 .Array => |array| {
83 if (ptr.size == .One and array.child == u8) {
84 try self.values.put(field.name, .{ .string = @field(values, field.name) });
85 continue;
86 }
87 },
88 else => {},
89 }
9067
91 @compileError("unsupported ConfigHeaderStep value type: " ++68fn putValue(self: *ConfigHeaderStep, field_name: []const u8, comptime T: type, v: T) !void {
92 @typeName(field.type));69 switch (@typeInfo(T)) {
93 },70 .Null => {
94 else => @compileError("unsupported ConfigHeaderStep value type: " ++71 try self.values.put(field_name, .undef);
95 @typeName(field.type)),72 },
96 }73 .Void => {
74 try self.values.put(field_name, .defined);
75 },
76 .Bool => {
77 try self.values.put(field_name, .{ .boolean = v });
78 },
79 .Int => {
80 try self.values.put(field_name, .{ .int = v });
81 },
82 .ComptimeInt => {
83 try self.values.put(field_name, .{ .int = v });
84 },
85 .EnumLiteral => {
86 try self.values.put(field_name, .{ .ident = @tagName(v) });
87 },
88 .Optional => {
89 if (v) |x| {
90 return putValue(self, field_name, @TypeOf(x), x);
91 } else {
92 try self.values.put(field_name, .undef);
93 }
94 },
95 .Pointer => |ptr| {
96 switch (@typeInfo(ptr.child)) {
97 .Array => |array| {
98 if (ptr.size == .One and array.child == u8) {
99 try self.values.put(field_name, .{ .string = v });
100 return;
101 }
102 },
103 else => {},
104 }
105
106 @compileError("unsupported ConfigHeaderStep value type: " ++ @typeName(T));
107 },
108 else => @compileError("unsupported ConfigHeaderStep value type: " ++ @typeName(T)),
97 }109 }
98}110}
99111