| ... | ... | @@ -100,58 +100,58 @@ pub fn create(owner: *std.Build, options: Options) *ConfigHeader { |
| 100 | 100 | return config_header; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | pub fn addValue(config_header: *ConfigHeader, name: []const u8, comptime T: type, value: T) void { |
| 104 | return addValueInner(config_header, name, T, value) catch @panic("OOM"); |
| 105 | } |
| 106 | |
| 103 | 107 | pub fn addValues(config_header: *ConfigHeader, values: anytype) void { |
| 104 | | return addValuesInner(config_header, values) catch @panic("OOM"); |
| 108 | inline for (@typeInfo(@TypeOf(values)).@"struct".fields) |field| { |
| 109 | addValue(config_header, field.name, field.type, @field(values, field.name)); |
| 110 | } |
| 105 | 111 | } |
| 106 | 112 | |
| 107 | 113 | pub fn getOutput(config_header: *ConfigHeader) std.Build.LazyPath { |
| 108 | 114 | return .{ .generated = .{ .file = &config_header.output_file } }; |
| 109 | 115 | } |
| 110 | 116 | |
| 111 | | fn addValuesInner(config_header: *ConfigHeader, values: anytype) !void { |
| 112 | | inline for (@typeInfo(@TypeOf(values)).@"struct".fields) |field| { |
| 113 | | try putValue(config_header, field.name, field.type, @field(values, field.name)); |
| 114 | | } |
| 115 | | } |
| 116 | | |
| 117 | | fn putValue(config_header: *ConfigHeader, field_name: []const u8, comptime T: type, v: T) !void { |
| 117 | fn addValueInner(config_header: *ConfigHeader, name: []const u8, comptime T: type, value: T) !void { |
| 118 | 118 | switch (@typeInfo(T)) { |
| 119 | 119 | .null => { |
| 120 | | try config_header.values.put(field_name, .undef); |
| 120 | try config_header.values.put(name, .undef); |
| 121 | 121 | }, |
| 122 | 122 | .void => { |
| 123 | | try config_header.values.put(field_name, .defined); |
| 123 | try config_header.values.put(name, .defined); |
| 124 | 124 | }, |
| 125 | 125 | .bool => { |
| 126 | | try config_header.values.put(field_name, .{ .boolean = v }); |
| 126 | try config_header.values.put(name, .{ .boolean = value }); |
| 127 | 127 | }, |
| 128 | 128 | .int => { |
| 129 | | try config_header.values.put(field_name, .{ .int = v }); |
| 129 | try config_header.values.put(name, .{ .int = value }); |
| 130 | 130 | }, |
| 131 | 131 | .comptime_int => { |
| 132 | | try config_header.values.put(field_name, .{ .int = v }); |
| 132 | try config_header.values.put(name, .{ .int = value }); |
| 133 | 133 | }, |
| 134 | 134 | .@"enum", .enum_literal => { |
| 135 | | try config_header.values.put(field_name, .{ .ident = @tagName(v) }); |
| 135 | try config_header.values.put(name, .{ .ident = @tagName(value) }); |
| 136 | 136 | }, |
| 137 | 137 | .optional => { |
| 138 | | if (v) |x| { |
| 139 | | return putValue(config_header, field_name, @TypeOf(x), x); |
| 138 | if (value) |x| { |
| 139 | return addValueInner(config_header, name, @TypeOf(x), x); |
| 140 | 140 | } else { |
| 141 | | try config_header.values.put(field_name, .undef); |
| 141 | try config_header.values.put(name, .undef); |
| 142 | 142 | } |
| 143 | 143 | }, |
| 144 | 144 | .pointer => |ptr| { |
| 145 | 145 | switch (@typeInfo(ptr.child)) { |
| 146 | 146 | .array => |array| { |
| 147 | 147 | if (ptr.size == .one and array.child == u8) { |
| 148 | | try config_header.values.put(field_name, .{ .string = v }); |
| 148 | try config_header.values.put(name, .{ .string = value }); |
| 149 | 149 | return; |
| 150 | 150 | } |
| 151 | 151 | }, |
| 152 | 152 | .int => { |
| 153 | 153 | if (ptr.size == .slice and ptr.child == u8) { |
| 154 | | try config_header.values.put(field_name, .{ .string = v }); |
| 154 | try config_header.values.put(name, .{ .string = value }); |
| 155 | 155 | return; |
| 156 | 156 | } |
| 157 | 157 | }, |