authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-08 13:36:51-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-25 18:54:35-07:00
logf158262b30665b22c571373907a14f11eec809f7
tree2904846106bf262bdfba9ae7e9c5ed7fd670c636
parentd7eab060db6aff326a957e4dbffcd09263f7ffbd

configurer: serialize Step.Options


2 files changed, 28 insertions(+), 15 deletions(-)

lib/compiler/configurer.zig+18-1
......@@ -1066,7 +1066,24 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {
10661066 },
10671067 .config_header => @panic("TODO"),
10681068 .obj_copy => @panic("TODO"),
1069 .options => @panic("TODO"),
1069 .options => e: {
1070 const so: *Step.Options = @fieldParentPtr("step", step);
1071
1072 const args = try arena.alloc(Configuration.Step.Options.Arg, so.args.items.len);
1073 for (args, so.args.items) |*dest, src| dest.* = .{
1074 .name = src.name,
1075 .path = try s.addLazyPath(src.path),
1076 };
1077
1078 break :e @enumFromInt(try wc.addExtra(@as(Configuration.Step.Options, .{
1079 .flags = .{
1080 .args = so.args.items.len != 0,
1081 },
1082 .generated_file = so.generated_file,
1083 .contents = try wc.addBytes(so.contents.items),
1084 .args = .{ .slice = args },
1085 })));
1086 },
10701087 },
10711088 });
10721089 }
lib/std/Build/Step/Options.zig+10-14
......@@ -11,14 +11,14 @@ const Configuration = std.Build.Configuration;
1111
1212step: Step,
1313generated_file: Configuration.GeneratedFileIndex,
14contents: std.ArrayList(u8),
15args: std.ArrayList(Arg),
14contents: std.ArrayList(u8) = .empty,
15args: std.ArrayList(Arg) = .empty,
1616encountered_types: std.StringHashMapUnmanaged(void),
1717
1818pub const base_tag: Step.Tag = .options;
1919
2020pub const Arg = struct {
21 name: []const u8,
21 name: Configuration.String,
2222 path: LazyPath,
2323};
2424
......@@ -34,8 +34,6 @@ pub fn create(owner: *std.Build) *Options {
3434 .owner = owner,
3535 }),
3636 .generated_file = graph.addGeneratedFile(&options.step),
37 .contents = .empty,
38 .args = .empty,
3937 .encountered_types = .empty,
4038 };
4139
......@@ -416,16 +414,14 @@ fn printStructValue(
416414 }
417415}
418416
419/// The value is the path in the cache dir.
420/// Adds a dependency automatically.
421pub fn addOptionPath(
422 options: *Options,
423 name: []const u8,
424 path: LazyPath,
425) void {
426 const arena = options.step.owner.allocator;
417/// The added option has type `[]const u8` and value of the provided path.
418pub fn addOptionPath(options: *Options, name: []const u8, path: LazyPath) void {
419 const graph = options.step.owner.graph;
420 const arena = graph.arena;
421 const wc = &graph.wip_configuration;
422
427423 options.args.append(arena, .{
428 .name = options.step.owner.dupe(name),
424 .name = try wc.addString(name),
429425 .path = path.dupe(options.step.owner),
430426 }) catch @panic("OOM");
431427 path.addStepDependencies(&options.step);