authorgravatar for carl@astholm.seCarl Åstholm <carl@astholm.se> 2025-03-24 00:14:25+01:00
committergravatar for carl@astholm.seCarl Åstholm <carl@astholm.se> 2025-07-20 18:28:36+02:00
log2c1a349fb9bc9965e309257262665564cff64a79
tree6278a5e5d733b4b1339f1c64e2a3072625b56a51
parentfd5eba9358ebf2f498b7c35bae34267f06d070d2

Support passing enum slices to `b.dependency()`


2 files changed, 27 insertions(+), 17 deletions(-)

lib/std/Build.zig+23-12
...@@ -530,18 +530,29 @@ fn addUserInputOptionFromArg(...@@ -530,18 +530,29 @@ fn addUserInputOptionFromArg(
530 },530 },
531 else => {},531 else => {},
532 },532 },
533 .slice => {533 .slice => switch (@typeInfo(ptr_info.child)) {
534 comptime var slice_info = ptr_info;534 .@"enum" => return if (maybe_value) |v| {
535 slice_info.is_const = true;535 var list = ArrayList([]const u8).initCapacity(arena, v.len) catch @panic("OOM");
536 slice_info.sentinel_ptr = null;536 for (v) |tag| list.appendAssumeCapacity(@tagName(tag));
537 addUserInputOptionFromArg(537 map.put(field.name, .{
538 arena,538 .name = field.name,
539 map,539 .value = .{ .list = list },
540 field,540 .used = false,
541 @Type(.{ .pointer = slice_info }),541 }) catch @panic("OOM");
542 maybe_value orelse null,542 },
543 );543 else => {
544 return;544 comptime var slice_info = ptr_info;
545 slice_info.is_const = true;
546 slice_info.sentinel_ptr = null;
547 addUserInputOptionFromArg(
548 arena,
549 map,
550 field,
551 @Type(.{ .pointer = slice_info }),
552 maybe_value orelse null,
553 );
554 return;
555 },
545 },556 },
546 else => {},557 else => {},
547 },558 },
test/standalone/dependency_options/build.zig+4-5
...@@ -50,7 +50,7 @@ pub fn build(b: *std.Build) !void {...@@ -50,7 +50,7 @@ pub fn build(b: *std.Build) !void {
50 .{ .cwd_relative = "c.txt" },50 .{ .cwd_relative = "c.txt" },
51 }),51 }),
52 .@"enum" = @as(Enum, .alfa),52 .@"enum" = @as(Enum, .alfa),
53 //.enum_list = @as([]const Enum, &.{ .alfa, .bravo, .charlie }),53 .enum_list = @as([]const Enum, &.{ .alfa, .bravo, .charlie }),
54 //.build_id = @as(std.zig.BuildId, .uuid),54 //.build_id = @as(std.zig.BuildId, .uuid),
55 });55 });
5656
...@@ -75,7 +75,7 @@ pub fn build(b: *std.Build) !void {...@@ -75,7 +75,7 @@ pub fn build(b: *std.Build) !void {
75 .{ .cwd_relative = "c.txt" },75 .{ .cwd_relative = "c.txt" },
76 }),76 }),
77 .@"enum" = @as(?Enum, .alfa),77 .@"enum" = @as(?Enum, .alfa),
78 //.enum_list = @as(?[]const Enum, &.{ .alfa, .bravo, .charlie }),78 .enum_list = @as(?[]const Enum, &.{ .alfa, .bravo, .charlie }),
79 //.build_id = @as(?std.zig.BuildId, .uuid),79 //.build_id = @as(?std.zig.BuildId, .uuid),
80 });80 });
8181
...@@ -96,7 +96,7 @@ pub fn build(b: *std.Build) !void {...@@ -96,7 +96,7 @@ pub fn build(b: *std.Build) !void {
96 .{ .cwd_relative = "c.txt" },96 .{ .cwd_relative = "c.txt" },
97 },97 },
98 .@"enum" = .alfa,98 .@"enum" = .alfa,
99 //.enum_list = &[_]Enum{ .alfa, .bravo, .charlie },99 .enum_list = &[_]Enum{ .alfa, .bravo, .charlie },
100 //.build_id = @as(std.zig.BuildId, .uuid),100 //.build_id = @as(std.zig.BuildId, .uuid),
101 });101 });
102102
...@@ -114,7 +114,6 @@ pub fn build(b: *std.Build) !void {...@@ -114,7 +114,6 @@ pub fn build(b: *std.Build) !void {
114 const mut_lazy_path_list: []std.Build.LazyPath = &mut_lazy_path_list_buf;114 const mut_lazy_path_list: []std.Build.LazyPath = &mut_lazy_path_list_buf;
115 var mut_enum_list_buf = [_]Enum{ .alfa, .bravo, .charlie };115 var mut_enum_list_buf = [_]Enum{ .alfa, .bravo, .charlie };
116 const mut_enum_list: []Enum = &mut_enum_list_buf;116 const mut_enum_list: []Enum = &mut_enum_list_buf;
117 _ = mut_enum_list;
118117
119 // Most supported option types are serialized to a string representation,118 // Most supported option types are serialized to a string representation,
120 // so alternative representations of the same option value should resolve119 // so alternative representations of the same option value should resolve
...@@ -130,7 +129,7 @@ pub fn build(b: *std.Build) !void {...@@ -130,7 +129,7 @@ pub fn build(b: *std.Build) !void {
130 .lazy_path = @as(std.Build.LazyPath, .{ .cwd_relative = "abc.txt" }),129 .lazy_path = @as(std.Build.LazyPath, .{ .cwd_relative = "abc.txt" }),
131 .lazy_path_list = mut_lazy_path_list,130 .lazy_path_list = mut_lazy_path_list,
132 .@"enum" = "alfa",131 .@"enum" = "alfa",
133 //.enum_list = mut_enum_list,132 .enum_list = mut_enum_list,
134 //.build_id = @as(std.zig.BuildId, .uuid),133 //.build_id = @as(std.zig.BuildId, .uuid),
135 });134 });
136135