From f158262b30665b22c571373907a14f11eec809f7 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 8 May 2026 13:36:51 -0700 Subject: [PATCH] configurer: serialize Step.Options --- lib/compiler/configurer.zig | 19 ++++++++++++++++++- lib/std/Build/Step/Options.zig | 24 ++++++++++-------------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/lib/compiler/configurer.zig b/lib/compiler/configurer.zig index 10d1875d0d49ab385ae120ac4aa29d259abbaae5..6b7c2a982d439f056dcd22f20bb3fd77dc064a38 100644 --- a/lib/compiler/configurer.zig +++ b/lib/compiler/configurer.zig @@ -1066,7 +1066,24 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void { }, .config_header => @panic("TODO"), .obj_copy => @panic("TODO"), - .options => @panic("TODO"), + .options => e: { + const so: *Step.Options = @fieldParentPtr("step", step); + + const args = try arena.alloc(Configuration.Step.Options.Arg, so.args.items.len); + for (args, so.args.items) |*dest, src| dest.* = .{ + .name = src.name, + .path = try s.addLazyPath(src.path), + }; + + break :e @enumFromInt(try wc.addExtra(@as(Configuration.Step.Options, .{ + .flags = .{ + .args = so.args.items.len != 0, + }, + .generated_file = so.generated_file, + .contents = try wc.addBytes(so.contents.items), + .args = .{ .slice = args }, + }))); + }, }, }); } diff --git a/lib/std/Build/Step/Options.zig b/lib/std/Build/Step/Options.zig index 935aec618c3bc54f25970f7ef16b40afd0edc55a..e78baff95f83862c85b175b7fe1a10328fcd4b2b 100644 --- a/lib/std/Build/Step/Options.zig +++ b/lib/std/Build/Step/Options.zig @@ -11,14 +11,14 @@ const Configuration = std.Build.Configuration; step: Step, generated_file: Configuration.GeneratedFileIndex, -contents: std.ArrayList(u8), -args: std.ArrayList(Arg), +contents: std.ArrayList(u8) = .empty, +args: std.ArrayList(Arg) = .empty, encountered_types: std.StringHashMapUnmanaged(void), pub const base_tag: Step.Tag = .options; pub const Arg = struct { - name: []const u8, + name: Configuration.String, path: LazyPath, }; @@ -34,8 +34,6 @@ pub fn create(owner: *std.Build) *Options { .owner = owner, }), .generated_file = graph.addGeneratedFile(&options.step), - .contents = .empty, - .args = .empty, .encountered_types = .empty, }; @@ -416,16 +414,14 @@ fn printStructValue( } } -/// The value is the path in the cache dir. -/// Adds a dependency automatically. -pub fn addOptionPath( - options: *Options, - name: []const u8, - path: LazyPath, -) void { - const arena = options.step.owner.allocator; +/// The added option has type `[]const u8` and value of the provided path. +pub fn addOptionPath(options: *Options, name: []const u8, path: LazyPath) void { + const graph = options.step.owner.graph; + const arena = graph.arena; + const wc = &graph.wip_configuration; + options.args.append(arena, .{ - .name = options.step.owner.dupe(name), + .name = try wc.addString(name), .path = path.dupe(options.step.owner), }) catch @panic("OOM"); path.addStepDependencies(&options.step); -- 2.54.0