diff --git a/lib/std/Build.zig b/lib/std/Build.zig index 2c9427645f71b3285f80115b8248de4add324a77..d6b63b59a0617daa18fa3494b61688b050528b81 100644 --- 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 index 5583b6611b474c8fe07fd5f77492967a532d5edd..f8996ccad050ea9b542a6f37b470a9c33ceb335d 100644 --- 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 index 294afdb9af1c23b1500598afe3f1c4bbc68080a7..4052e21bd08c0c43e66f4e1bae94991f5fcc6b00 100644 --- 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, };