diff --git a/lib/compiler/Maker.zig b/lib/compiler/Maker.zig index 8055927d61e7276106d297c5950913e3a0e78980..09877c4fc04b63c55b834fda28d0db9b3bff178a 100644 --- a/lib/compiler/Maker.zig +++ b/lib/compiler/Maker.zig @@ -1385,17 +1385,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 21b7b2597c3e33cf7f10e31c82c82bbf052d2785..32a7b2634a68127e69e460bc2cda53743b49566c 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) {