| ... | @@ -105,6 +105,7 @@ pub const Builder = struct { | ... | @@ -105,6 +105,7 @@ pub const Builder = struct { |
| 105 | Bool, | 105 | Bool, |
| 106 | Int, | 106 | Int, |
| 107 | Float, | 107 | Float, |
| | 108 | Enum, |
| 108 | String, | 109 | String, |
| 109 | List, | 110 | List, |
| 110 | }; | 111 | }; |
| ... | @@ -450,6 +451,27 @@ pub const Builder = struct { | ... | @@ -450,6 +451,27 @@ pub const Builder = struct { |
| 450 | }, | 451 | }, |
| 451 | TypeId.Int => panic("TODO integer options to build script", .{}), | 452 | TypeId.Int => panic("TODO integer options to build script", .{}), |
| 452 | TypeId.Float => panic("TODO float options to build script", .{}), | 453 | TypeId.Float => panic("TODO float options to build script", .{}), |
| | 454 | TypeId.Enum => switch (entry.value.value) { |
| | 455 | UserValue.Flag => { |
| | 456 | warn("Expected -D{} to be a string, but received a boolean.\n", .{name}); |
| | 457 | self.markInvalidUserInput(); |
| | 458 | return null; |
| | 459 | }, |
| | 460 | UserValue.Scalar => |s| { |
| | 461 | if (std.meta.stringToEnum(T, s)) |enum_lit| { |
| | 462 | return enum_lit; |
| | 463 | } else { |
| | 464 | warn("Expected -D{} to be of type {}.\n", .{ name, @typeName(T) }); |
| | 465 | self.markInvalidUserInput(); |
| | 466 | return null; |
| | 467 | } |
| | 468 | }, |
| | 469 | UserValue.List => { |
| | 470 | warn("Expected -D{} to be a string, but received a list.\n", .{name}); |
| | 471 | self.markInvalidUserInput(); |
| | 472 | return null; |
| | 473 | }, |
| | 474 | }, |
| 453 | TypeId.String => switch (entry.value.value) { | 475 | TypeId.String => switch (entry.value.value) { |
| 454 | UserValue.Flag => { | 476 | UserValue.Flag => { |
| 455 | warn("Expected -D{} to be a string, but received a boolean.\n", .{name}); | 477 | warn("Expected -D{} to be a string, but received a boolean.\n", .{name}); |
| ... | @@ -681,6 +703,7 @@ pub const Builder = struct { | ... | @@ -681,6 +703,7 @@ pub const Builder = struct { |
| 681 | .Int => .Int, | 703 | .Int => .Int, |
| 682 | .Float => .Float, | 704 | .Float => .Float, |
| 683 | .Bool => .Bool, | 705 | .Bool => .Bool, |
| | 706 | .Enum => .Enum, |
| 684 | else => switch (T) { | 707 | else => switch (T) { |
| 685 | []const u8 => .String, | 708 | []const u8 => .String, |
| 686 | []const []const u8 => .List, | 709 | []const []const u8 => .List, |
| ... | @@ -698,6 +721,7 @@ pub const Builder = struct { | ... | @@ -698,6 +721,7 @@ pub const Builder = struct { |
| 698 | .Bool => "bool", | 721 | .Bool => "bool", |
| 699 | .Int => "int", | 722 | .Int => "int", |
| 700 | .Float => "float", | 723 | .Float => "float", |
| | 724 | .Enum => "enum", |
| 701 | .String => "string", | 725 | .String => "string", |
| 702 | .List => "list", | 726 | .List => "list", |
| 703 | }; | 727 | }; |
| ... | @@ -1678,6 +1702,16 @@ pub const LibExeObjStep = struct { | ... | @@ -1678,6 +1702,16 @@ pub const LibExeObjStep = struct { |
| 1678 | | 1702 | |
| 1679 | pub fn addBuildOption(self: *LibExeObjStep, comptime T: type, name: []const u8, value: T) void { | 1703 | pub fn addBuildOption(self: *LibExeObjStep, comptime T: type, name: []const u8, value: T) void { |
| 1680 | const out = self.build_options_contents.outStream(); | 1704 | const out = self.build_options_contents.outStream(); |
| | 1705 | switch (@typeInfo(T)) { |
| | 1706 | .Enum => |enum_info| { |
| | 1707 | out.print("const {} = enum {{\n", .{@typeName(T)}) catch unreachable; |
| | 1708 | inline for (enum_info.fields) |field| { |
| | 1709 | out.print(" {},\n", .{ field.name }) catch unreachable; |
| | 1710 | } |
| | 1711 | out.print("}};\n", .{}) catch unreachable; |
| | 1712 | }, |
| | 1713 | else => {}, |
| | 1714 | } |
| 1681 | out.print("pub const {} = {};\n", .{ name, value }) catch unreachable; | 1715 | out.print("pub const {} = {};\n", .{ name, value }) catch unreachable; |
| 1682 | } | 1716 | } |
| 1683 | | 1717 | |