authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-10-14 17:38:43-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-10-14 17:42:15-07:00
log6cecad145d569bf9794760ca13bd2bf479a357c7
tree09d042e0a7f81a85af4b6c2975d219799b5f4cf1
parent5b4e91bc391b7c0f537e3eaeda3beb60b8813ad9

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

2 files changed, 40 insertions(+), 15 deletions(-)

lib/compiler/Maker.zig+28-11
......@@ -1444,17 +1444,34 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig {
14441444 // The first one is a dummy package for the current project.
14451445 continue;
14461446 }
1447 if (!f.has_build_zig)
1448 continue;
1449 const hash_slice = try arena.dupe(u8, hash.toSlice());
1450
1451 const m = try arena.create(CliModule);
1452 m.* = .{
1453 .root_path = try f.package_root.toString(arena),
1454 .name = hash_slice,
1455 };
1456 deps_mod.deps.putAssumeCapacityNoClobber(hash_slice, m);
1457 f.cli_module = m;
1447 if (!f.has_build_zig) continue;
1448
1449 const project_id: Package.ProjectId = .init(f.manifest.name, f.manifest.id);
1450 if (fork_set.getKeyPtrAdapted(project_id, @as(Fetch.JobQueue.Fork.Adapter, .{}))) |fork| {
1451 const path = try fork.path.toString(arena);
1452 const gop = deps_mod.deps.getOrPutAssumeCapacity(path);
1453 if (gop.found_existing) {
1454 assert(fork.uses > 1);
1455 f.cli_module = gop.value_ptr.*;
1456 } else {
1457 const m = try arena.create(CliModule);
1458 m.* = .{
1459 .root_path = try f.package_root.toString(arena),
1460 .name = path,
1461 };
1462 gop.value_ptr.* = m;
1463 f.cli_module = m;
1464 }
1465 } else {
1466 const hash_slice = try arena.dupe(u8, hash.toSlice());
1467 const m = try arena.create(CliModule);
1468 m.* = .{
1469 .root_path = try f.package_root.toString(arena),
1470 .name = hash_slice,
1471 };
1472 deps_mod.deps.putAssumeCapacityNoClobber(hash_slice, m);
1473 f.cli_module = m;
1474 }
14581475 }
14591476
14601477 // Each build.zig module needs access to each of its dependencies' build.zig modules by
lib/compiler/Maker/Fetch.zig+12-4
......@@ -290,10 +290,18 @@ pub const JobQueue = struct {
290290 , .{std.fmt.alt(fetch.package_root, .formatEscapeString)});
291291
292292 if (fetch.has_build_zig) {
293 try w.print(
294 \\ pub const build_zig = @import("{f}");
295 \\
296 , .{std.zig.fmtString(hash_slice)});
293 const project_id: Package.ProjectId = .init(fetch.manifest.name, fetch.manifest.id);
294 if (jq.fork_set.getKeyPtrAdapted(project_id, @as(JobQueue.Fork.Adapter, .{}))) |fork| {
295 try w.print(
296 \\ pub const build_zig = @import({qf});
297 \\
298 , .{fork.path});
299 } else {
300 try w.print(
301 \\ pub const build_zig = @import({q});
302 \\
303 , .{hash_slice});
304 }
297305 }
298306
299307 if (fetch.have_manifest) {