zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit e636825f01180cd05ee91d540654be65daa6e1d5 (tree)
parent ffac200e66a493907270a02404bcd4ee1898eb3a
Author: Carl Ã…stholm <carl@astholm.se>
Date:   Sun,  7 Jun 2026 18:05:09 +0200

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

Diffstat:
Mlib/std/Build.zig | 10++++++++++
Mlib/std/Build/Module.zig | 5+----
Mlib/std/Build/Step/Fmt.zig | 4++--
3 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/lib/std/Build.zig b/lib/std/Build.zig @@ -2567,6 +2567,16 @@ pub const LazyPath = union(enum) { return dupeInner(lazy_path, graph.arena); } + /// Copies the slice of paths and all internal strings. + /// + /// The `graph` parameter is only used for the global arena allocator. + pub fn dupeList(lazy_paths: []const LazyPath, graph: *const Graph) []const LazyPath { + const arena = graph.arena; + const result = graph.alloc(LazyPath, lazy_paths.len); + for (result, lazy_paths) |*d, s| d.* = dupeInner(s, arena); + return result; + } + fn dupeInner(lazy_path: LazyPath, arena: Allocator) LazyPath { return switch (lazy_path) { .src_path => |sp| .{ .src_path = .{ .owner = sp.owner, .sub_path = sp.owner.dupePath(sp.sub_path) } }, diff --git a/lib/std/Build/Module.zig b/lib/std/Build/Module.zig @@ -146,13 +146,10 @@ pub const RcSourceFile = struct { include_paths: []const LazyPath = &.{}, pub fn dupe(file: RcSourceFile, graph: *const std.Build.Graph) RcSourceFile { - const arena = graph.arena; - const include_paths = arena.alloc(LazyPath, file.include_paths.len) catch @panic("OOM"); - for (include_paths, file.include_paths) |*dest, lazy_path| dest.* = lazy_path.dupe(graph); return .{ .file = file.file.dupe(graph), .flags = graph.dupeStrings(file.flags), - .include_paths = include_paths, + .include_paths = LazyPath.dupeList(file.include_paths, graph), }; } }; diff --git a/lib/std/Build/Step/Fmt.zig b/lib/std/Build/Step/Fmt.zig @@ -34,8 +34,8 @@ pub fn create(owner: *std.Build, options: Options) *Fmt { .name = if (options.check) "zig fmt --check" else "zig fmt", .owner = owner, }), - .paths = options.paths, - .exclude_paths = options.exclude_paths, + .paths = LazyPath.dupeList(options.paths, graph), + .exclude_paths = LazyPath.dupeList(options.exclude_paths, graph), .check = options.check, };