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 {...@@ -1066,7 +1066,24 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {
1066 },1066 },
1067 .config_header => @panic("TODO"),1067 .config_header => @panic("TODO"),
1068 .obj_copy => @panic("TODO"),1068 .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 },
1070 },1087 },
1071 });1088 });
1072 }1089 }
lib/std/Build/Step/Options.zig+10-14
...@@ -11,14 +11,14 @@ const Configuration = std.Build.Configuration;...@@ -11,14 +11,14 @@ const Configuration = std.Build.Configuration;
1111
12step: Step,12step: Step,
13generated_file: Configuration.GeneratedFileIndex,13generated_file: Configuration.GeneratedFileIndex,
14contents: std.ArrayList(u8),14contents: std.ArrayList(u8) = .empty,
15args: std.ArrayList(Arg),15args: std.ArrayList(Arg) = .empty,
16encountered_types: std.StringHashMapUnmanaged(void),16encountered_types: std.StringHashMapUnmanaged(void),
1717
18pub const base_tag: Step.Tag = .options;18pub const base_tag: Step.Tag = .options;
1919
20pub const Arg = struct {20pub const Arg = struct {
21 name: []const u8,21 name: Configuration.String,
22 path: LazyPath,22 path: LazyPath,
23};23};
2424
...@@ -34,8 +34,6 @@ pub fn create(owner: *std.Build) *Options {...@@ -34,8 +34,6 @@ pub fn create(owner: *std.Build) *Options {
34 .owner = owner,34 .owner = owner,
35 }),35 }),
36 .generated_file = graph.addGeneratedFile(&options.step),36 .generated_file = graph.addGeneratedFile(&options.step),
37 .contents = .empty,
38 .args = .empty,
39 .encountered_types = .empty,37 .encountered_types = .empty,
40 };38 };
4139
...@@ -416,16 +414,14 @@ fn printStructValue(...@@ -416,16 +414,14 @@ fn printStructValue(
416 }414 }
417}415}
418416
419/// The value is the path in the cache dir.417/// The added option has type `[]const u8` and value of the provided path.
420/// Adds a dependency automatically.418pub fn addOptionPath(options: *Options, name: []const u8, path: LazyPath) void {
421pub fn addOptionPath(419 const graph = options.step.owner.graph;
422 options: *Options,420 const arena = graph.arena;
423 name: []const u8,421 const wc = &graph.wip_configuration;
424 path: LazyPath,422
425) void {
426 const arena = options.step.owner.allocator;
427 options.args.append(arena, .{423 options.args.append(arena, .{
428 .name = options.step.owner.dupe(name),424 .name = try wc.addString(name),
429 .path = path.dupe(options.step.owner),425 .path = path.dupe(options.step.owner),
430 }) catch @panic("OOM");426 }) catch @panic("OOM");
431 path.addStepDependencies(&options.step);427 path.addStepDependencies(&options.step);