|
1 | 1 | const std = @import("std"); |
2 | 2 | const Build = std.Build; |
3 | 3 | const LazyPath = Build.LazyPath; |
| 4 | +const assert = std.debug.assert; |
4 | 5 |
|
5 | 6 | const internals = @import("build-internals"); |
6 | 7 | pub const Target = internals.Target; |
@@ -138,25 +139,35 @@ fn generate_release_steps(b: *Build) void { |
138 | 139 | } |
139 | 140 | } |
140 | 141 |
|
141 | | -pub const PortSelect = blk: { |
142 | | - var fields: []const std.builtin.Type.StructField = &.{}; |
143 | | - for (port_list) |port| { |
144 | | - fields = fields ++ [_]std.builtin.Type.StructField{.{ |
145 | | - .name = port.name, |
146 | | - .type = bool, |
147 | | - .default_value_ptr = @as(*const anyopaque, @ptrCast(&false)), |
148 | | - .is_comptime = false, |
149 | | - .alignment = @alignOf(bool), |
150 | | - }}; |
| 142 | +pub const PortSelect = struct { |
| 143 | + esp: bool = false, |
| 144 | + gd32: bool = false, |
| 145 | + atsam: bool = false, |
| 146 | + avr: bool = false, |
| 147 | + nrf5x: bool = false, |
| 148 | + lpc: bool = false, |
| 149 | + mcx: bool = false, |
| 150 | + rp2xxx: bool = false, |
| 151 | + stm32: bool = false, |
| 152 | + ch32v: bool = false, |
| 153 | + |
| 154 | + pub const all: PortSelect = blk: { |
| 155 | + var ret: PortSelect = undefined; |
| 156 | + for (@typeInfo(PortSelect).@"struct".fields) |field| { |
| 157 | + @field(ret, field.name) = true; |
| 158 | + } |
| 159 | + |
| 160 | + break :blk ret; |
| 161 | + }; |
| 162 | + |
| 163 | + comptime { |
| 164 | + // assumes fields are in the same order as the port list |
| 165 | + for (port_list, @typeInfo(PortSelect).@"struct".fields) |port_entry, field| { |
| 166 | + assert(std.mem.eql(u8, port_entry.name, field.name)); |
| 167 | + const default_value_ptr: *const bool = @ptrCast(field.default_value_ptr); |
| 168 | + assert(false == default_value_ptr.*); |
| 169 | + } |
151 | 170 | } |
152 | | - break :blk @Type(.{ |
153 | | - .@"struct" = .{ |
154 | | - .layout = .auto, |
155 | | - .fields = fields, |
156 | | - .decls = &.{}, |
157 | | - .is_tuple = false, |
158 | | - }, |
159 | | - }); |
160 | 171 | }; |
161 | 172 |
|
162 | 173 | // Don't know if this is required but it doesn't hurt either. |
|
0 commit comments