| ... | @@ -134,7 +134,20 @@ fn printLiteral(out: anytype, val: anytype, indent: u8) !void { | ... | @@ -134,7 +134,20 @@ fn printLiteral(out: anytype, val: anytype, indent: u8) !void { |
| 134 | switch (@typeInfo(T)) { | 134 | switch (@typeInfo(T)) { |
| 135 | .Array => { | 135 | .Array => { |
| 136 | // TODO: non-recursive? | 136 | // TODO: non-recursive? |
| 137 | try out.print("{s}{{\n", .{@typeName(T)}); | 137 | try out.print("{s} {{\n", .{@typeName(T)}); |
| | 138 | for (val) |item| { |
| | 139 | try out.writeByteNTimes(' ', indent + 4); |
| | 140 | try printLiteral(out, item, indent + 4); |
| | 141 | try out.writeAll(",\n"); |
| | 142 | } |
| | 143 | try out.writeByteNTimes(' ', indent); |
| | 144 | try out.writeAll("}"); |
| | 145 | }, |
| | 146 | .Pointer => |p| { |
| | 147 | if (p.size != .Slice) { |
| | 148 | @compileError("Non-slice pointers are not yet supported in build options"); |
| | 149 | } |
| | 150 | try out.print("&[_]{s} {{\n", .{@typeName(p.child)}); |
| 138 | for (val) |item| { | 151 | for (val) |item| { |
| 139 | try out.writeByteNTimes(' ', indent + 4); | 152 | try out.writeByteNTimes(' ', indent + 4); |
| 140 | try printLiteral(out, item, indent + 4); | 153 | try printLiteral(out, item, indent + 4); |
| ... | @@ -262,11 +275,18 @@ test "OptionsStep" { | ... | @@ -262,11 +275,18 @@ test "OptionsStep" { |
| 262 | @"0.8.1", | 275 | @"0.8.1", |
| 263 | }; | 276 | }; |
| 264 | | 277 | |
| | 278 | const nested_array = [2][2]u16{ |
| | 279 | [2]u16{ 300, 200 }, |
| | 280 | [2]u16{ 300, 200 }, |
| | 281 | }; |
| | 282 | const nested_slice: []const []const u16 = &[_][]const u16{ &nested_array[0], &nested_array[1] }; |
| | 283 | |
| 265 | options.addOption(usize, "option1", 1); | 284 | options.addOption(usize, "option1", 1); |
| 266 | options.addOption(?usize, "option2", null); | 285 | options.addOption(?usize, "option2", null); |
| 267 | options.addOption([]const u8, "string", "zigisthebest"); | 286 | options.addOption([]const u8, "string", "zigisthebest"); |
| 268 | options.addOption(?[]const u8, "optional_string", null); | 287 | options.addOption(?[]const u8, "optional_string", null); |
| 269 | options.addOption([2][2]u16, "array", [2][2]u16{ [2]u16{ 300, 200 }, [2]u16{ 300, 200 } }); | 288 | options.addOption([2][2]u16, "nested_array", nested_array); |
| | 289 | options.addOption([]const []const u16, "nested_slice", nested_slice); |
| 270 | options.addOption(KeywordEnum, "keyword_enum", .@"0.8.1"); | 290 | options.addOption(KeywordEnum, "keyword_enum", .@"0.8.1"); |
| 271 | options.addOption(std.builtin.Version, "version", try std.builtin.Version.parse("0.1.2")); | 291 | options.addOption(std.builtin.Version, "version", try std.builtin.Version.parse("0.1.2")); |
| 272 | options.addOption(std.SemanticVersion, "semantic_version", try std.SemanticVersion.parse("0.1.2-foo+bar")); | 292 | options.addOption(std.SemanticVersion, "semantic_version", try std.SemanticVersion.parse("0.1.2-foo+bar")); |
| ... | @@ -276,12 +296,22 @@ test "OptionsStep" { | ... | @@ -276,12 +296,22 @@ test "OptionsStep" { |
| 276 | \\pub const option2: ?usize = null; | 296 | \\pub const option2: ?usize = null; |
| 277 | \\pub const string: []const u8 = "zigisthebest"; | 297 | \\pub const string: []const u8 = "zigisthebest"; |
| 278 | \\pub const optional_string: ?[]const u8 = null; | 298 | \\pub const optional_string: ?[]const u8 = null; |
| 279 | \\pub const array: [2][2]u16 = [2][2]u16{ | 299 | \\pub const nested_array: [2][2]u16 = [2][2]u16 { |
| 280 | \\ [2]u16{ | 300 | \\ [2]u16 { |
| | 301 | \\ 300, |
| | 302 | \\ 200, |
| | 303 | \\ }, |
| | 304 | \\ [2]u16 { |
| | 305 | \\ 300, |
| | 306 | \\ 200, |
| | 307 | \\ }, |
| | 308 | \\}; |
| | 309 | \\pub const nested_slice: []const []const u16 = &[_][]const u16 { |
| | 310 | \\ &[_]u16 { |
| 281 | \\ 300, | 311 | \\ 300, |
| 282 | \\ 200, | 312 | \\ 200, |
| 283 | \\ }, | 313 | \\ }, |
| 284 | \\ [2]u16{ | 314 | \\ &[_]u16 { |
| 285 | \\ 300, | 315 | \\ 300, |
| 286 | \\ 200, | 316 | \\ 200, |
| 287 | \\ }, | 317 | \\ }, |