authorgravatar for carl@astholm.seCarl Åstholm <carl@astholm.se> 2026-06-07 18:05:09+02:00
committergravatar for justusk@noreply.codeberg.orgJustus Klausecker <justusk@noreply.codeberg.org> 2026-06-11 16:48:13+02:00
loge636825f01180cd05ee91d540654be65daa6e1d5
tree97072386ec9fe49bacf733749151ae699d6facb0
parentffac200e66a493907270a02404bcd4ee1898eb3a

std.Build.Step.Fmt: dupe lazy path lists


3 files changed, 13 insertions(+), 6 deletions(-)

lib/std/Build.zig+10
......@@ -2567,6 +2567,16 @@ pub const LazyPath = union(enum) {
25672567 return dupeInner(lazy_path, graph.arena);
25682568 }
25692569
2570 /// Copies the slice of paths and all internal strings.
2571 ///
2572 /// The `graph` parameter is only used for the global arena allocator.
2573 pub fn dupeList(lazy_paths: []const LazyPath, graph: *const Graph) []const LazyPath {
2574 const arena = graph.arena;
2575 const result = graph.alloc(LazyPath, lazy_paths.len);
2576 for (result, lazy_paths) |*d, s| d.* = dupeInner(s, arena);
2577 return result;
2578 }
2579
25702580 fn dupeInner(lazy_path: LazyPath, arena: Allocator) LazyPath {
25712581 return switch (lazy_path) {
25722582 .src_path => |sp| .{ .src_path = .{ .owner = sp.owner, .sub_path = sp.owner.dupePath(sp.sub_path) } },
lib/std/Build/Module.zig+1-4
......@@ -146,13 +146,10 @@ pub const RcSourceFile = struct {
146146 include_paths: []const LazyPath = &.{},
147147
148148 pub fn dupe(file: RcSourceFile, graph: *const std.Build.Graph) RcSourceFile {
149 const arena = graph.arena;
150 const include_paths = arena.alloc(LazyPath, file.include_paths.len) catch @panic("OOM");
151 for (include_paths, file.include_paths) |*dest, lazy_path| dest.* = lazy_path.dupe(graph);
152149 return .{
153150 .file = file.file.dupe(graph),
154151 .flags = graph.dupeStrings(file.flags),
155 .include_paths = include_paths,
152 .include_paths = LazyPath.dupeList(file.include_paths, graph),
156153 };
157154 }
158155};
lib/std/Build/Step/Fmt.zig+2-2
......@@ -34,8 +34,8 @@ pub fn create(owner: *std.Build, options: Options) *Fmt {
3434 .name = if (options.check) "zig fmt --check" else "zig fmt",
3535 .owner = owner,
3636 }),
37 .paths = options.paths,
38 .exclude_paths = options.exclude_paths,
37 .paths = LazyPath.dupeList(options.paths, graph),
38 .exclude_paths = LazyPath.dupeList(options.exclude_paths, graph),
3939 .check = options.check,
4040 };
4141