From 6cecad145d569bf9794760ca13bd2bf479a357c7 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 14 Oct 2026 17:38:43 -0700 Subject: [PATCH] Maker: fix use case when --fork matches 2 or more pkgs Previously this always caused a compilation failure because it would correctly substitute multiple packages with the provided forked package, however, this ends up constructing a zig build-exe command line for the configurer that included multiple differnt modules that used the same files. Closes #31677 --- lib/compiler/Maker.zig | 37 ++++++++++++++++++++++++++---------- lib/compiler/Maker/Fetch.zig | 16 ++++++++++++---- 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/lib/compiler/Maker.zig b/lib/compiler/Maker.zig index d0f8117ce8eaf9a1f7e34f84ba97b6740abad397..829c28ff55bcd4e71bc336caca0c7623fe4a4c04 100644 --- a/lib/compiler/Maker.zig +++ b/lib/compiler/Maker.zig @@ -1444,17 +1444,34 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig { // The first one is a dummy package for the current project. continue; } - if (!f.has_build_zig) - continue; - const hash_slice = try arena.dupe(u8, hash.toSlice()); + if (!f.has_build_zig) continue; - const m = try arena.create(CliModule); - m.* = .{ - .root_path = try f.package_root.toString(arena), - .name = hash_slice, - }; - deps_mod.deps.putAssumeCapacityNoClobber(hash_slice, m); - f.cli_module = m; + const project_id: Package.ProjectId = .init(f.manifest.name, f.manifest.id); + if (fork_set.getKeyPtrAdapted(project_id, @as(Fetch.JobQueue.Fork.Adapter, .{}))) |fork| { + const path = try fork.path.toString(arena); + const gop = deps_mod.deps.getOrPutAssumeCapacity(path); + if (gop.found_existing) { + assert(fork.uses > 1); + f.cli_module = gop.value_ptr.*; + } else { + const m = try arena.create(CliModule); + m.* = .{ + .root_path = try f.package_root.toString(arena), + .name = path, + }; + gop.value_ptr.* = m; + f.cli_module = m; + } + } else { + const hash_slice = try arena.dupe(u8, hash.toSlice()); + const m = try arena.create(CliModule); + m.* = .{ + .root_path = try f.package_root.toString(arena), + .name = hash_slice, + }; + deps_mod.deps.putAssumeCapacityNoClobber(hash_slice, m); + f.cli_module = m; + } } // Each build.zig module needs access to each of its dependencies' build.zig modules by diff --git a/lib/compiler/Maker/Fetch.zig b/lib/compiler/Maker/Fetch.zig index 0da66401f92fb09d61961db830ad4a0a7776630d..9fa9b121399b55d5745172bda914b1dc3a87a206 100644 --- a/lib/compiler/Maker/Fetch.zig +++ b/lib/compiler/Maker/Fetch.zig @@ -290,10 +290,18 @@ pub const JobQueue = struct { , .{std.fmt.alt(fetch.package_root, .formatEscapeString)}); if (fetch.has_build_zig) { - try w.print( - \\ pub const build_zig = @import("{f}"); - \\ - , .{std.zig.fmtString(hash_slice)}); + const project_id: Package.ProjectId = .init(fetch.manifest.name, fetch.manifest.id); + if (jq.fork_set.getKeyPtrAdapted(project_id, @as(JobQueue.Fork.Adapter, .{}))) |fork| { + try w.print( + \\ pub const build_zig = @import({qf}); + \\ + , .{fork.path}); + } else { + try w.print( + \\ pub const build_zig = @import({q}); + \\ + , .{hash_slice}); + } } if (fetch.have_manifest) { -- 2.54.0