aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDrDeano <ed.dean515@gmail.com>2020-05-16 15:36:18 +0100
committerDrDeano <ed.dean515@gmail.com>2020-05-16 15:36:18 +0100
commit72b72faa0b055f08a01d19ae26180dd4df6fe383 (patch)
treed5cc375852e61bc4cd2c79fcdd362d3040047bd3 /lib
parentb2cb8beed944aa74fba99fd1884dbb625987c9a0 (diff)
downloadzig-72b72faa0b055f08a01d19ae26180dd4df6fe383.tar.gz
zig-72b72faa0b055f08a01d19ae26180dd4df6fe383.zip
Add Enum Option
Diffstat (limited to 'lib')
-rw-r--r--lib/std/build.zig24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/std/build.zig b/lib/std/build.zig
index f3e132a6e1..a2da6315fe 100644
--- a/lib/std/build.zig
+++ b/lib/std/build.zig
@@ -105,6 +105,7 @@ pub const Builder = struct {
Bool,
Int,
Float,
+ Enum,
String,
List,
};
@@ -450,6 +451,27 @@ pub const Builder = struct {
},
TypeId.Int => panic("TODO integer options to build script", .{}),
TypeId.Float => panic("TODO float options to build script", .{}),
+ TypeId.Enum => switch (entry.value.value) {
+ UserValue.Flag => {
+ warn("Expected -D{} to be a string, but received a boolean.\n", .{name});
+ self.markInvalidUserInput();
+ return null;
+ },
+ UserValue.Scalar => |s| {
+ if (std.meta.stringToEnum(T, s)) |enum_lit| {
+ return enum_lit;
+ } else {
+ warn("Expected -D{} to be of type {}.\n", .{ name, @typeName(T) });
+ self.markInvalidUserInput();
+ return null;
+ }
+ },
+ UserValue.List => {
+ warn("Expected -D{} to be a string, but received a list.\n", .{name});
+ self.markInvalidUserInput();
+ return null;
+ },
+ },
TypeId.String => switch (entry.value.value) {
UserValue.Flag => {
warn("Expected -D{} to be a string, but received a boolean.\n", .{name});
@@ -681,6 +703,7 @@ pub const Builder = struct {
.Int => .Int,
.Float => .Float,
.Bool => .Bool,
+ .Enum => .Enum,
else => switch (T) {
[]const u8 => .String,
[]const []const u8 => .List,
@@ -698,6 +721,7 @@ pub const Builder = struct {
.Bool => "bool",
.Int => "int",
.Float => "float",
+ .Enum => "enum",
.String => "string",
.List => "list",
};