authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-06-23 23:10:41-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-06-29 23:50:19-07:00
log74168de68b8ebd6cb40cd9ab1c0c44d2e01012d4
tree7cb1ec8d1c06d22a0074691853adf5ebe72e50f8
parent20e7cc8d88dc1490d8635db0e6f96fff194763e6

Maker: fix lowering of build module on CLI


3 files changed, 18 insertions(+), 27 deletions(-)

lib/compiler/Maker.zig+14-19
...@@ -113,6 +113,15 @@ pub const CliModule = struct {...@@ -113,6 +113,15 @@ pub const CliModule = struct {
113 deps: Deps = .empty,113 deps: Deps = .empty,
114114
115 const Deps = std.array_hash_map.String(*CliModule);115 const Deps = std.array_hash_map.String(*CliModule);
116
117 fn lower(cm: *const CliModule, arena: Allocator, gpa: Allocator, argv: *std.ArrayList([]const u8)) !void {
118 try argv.ensureUnusedCapacity(gpa, 2 * cm.deps.count() + 1);
119 for (cm.deps.values()) |dep| {
120 argv.appendAssumeCapacity("--dep");
121 argv.appendAssumeCapacity(dep.name);
122 }
123 argv.appendAssumeCapacity(try allocPrint(arena, "-M{s}={s}", .{ cm.name, cm.root_path }));
124 }
116};125};
117126
118pub fn main(init: process.Init.Minimal) !void {127pub fn main(init: process.Init.Minimal) !void {
...@@ -691,19 +700,12 @@ pub fn main(init: process.Init.Minimal) !void {...@@ -691,19 +700,12 @@ pub fn main(init: process.Init.Minimal) !void {
691 "--dep", "@build", //700 "--dep", "@build", //
692 "--dep", "@dependencies", //701 "--dep", "@dependencies", //
693 try allocPrint(arena, "-Mroot={f}", .{configurer_root_src_path}), //702 try allocPrint(arena, "-Mroot={f}", .{configurer_root_src_path}), //
694 try allocPrint(arena, "-M@build={f}", .{root_build_src_path}), //
695 });703 });
696704
697 // In the loop below, after doing the fetch operation, the argv will be705 // In the loop below, after doing the fetch operation, the argv will be
698 // truncated at this point, dependencies added, and then the706 // truncated at this point, dependencies added, and then the
699 // "--listen=-" arg appended at the end.707 // "--listen=-" arg appended at the end.
700 const argv_deps_index = build_configurer_argv.items.len - 1;708 const argv_deps_index = build_configurer_argv.items.len;
701
702 //const root_mod = try arena.create(CliModule);
703 //root_mod.* = .{
704 // .name = "root",
705 // .root_path = try configurer_root_src_path.toString(arena),
706 //};
707709
708 const build_mod = try arena.create(CliModule);710 const build_mod = try arena.create(CliModule);
709 build_mod.* = .{711 build_mod.* = .{
...@@ -722,7 +724,6 @@ pub fn main(init: process.Init.Minimal) !void {...@@ -722,7 +724,6 @@ pub fn main(init: process.Init.Minimal) !void {
722 // This loop is re-evaluated when the build script exits with an indication that it724 // This loop is re-evaluated when the build script exits with an indication that it
723 // could not continue due to missing lazy dependencies.725 // could not continue due to missing lazy dependencies.
724 const configuration_path: Path, const poisoned: bool = cp: while (true) {726 const configuration_path: Path, const poisoned: bool = cp: while (true) {
725 //root_mod.deps.clearRetainingCapacity();
726 build_mod.deps.clearRetainingCapacity();727 build_mod.deps.clearRetainingCapacity();
727 deps_mod.deps.clearRetainingCapacity();728 deps_mod.deps.clearRetainingCapacity();
728729
...@@ -923,21 +924,15 @@ pub fn main(init: process.Init.Minimal) !void {...@@ -923,21 +924,15 @@ pub fn main(init: process.Init.Minimal) !void {
923 dep.name, dep.root_path,924 dep.name, dep.root_path,
924 }));925 }));
925 }926 }
926 try build_configurer_argv.ensureUnusedCapacity(gpa, 2 * deps_mod.deps.count() + 1);927 try deps_mod.lower(arena, gpa, &build_configurer_argv);
927 for (deps_mod.deps.values()) |dep| {928 try build_mod.lower(arena, gpa, &build_configurer_argv);
928 build_configurer_argv.appendAssumeCapacity("--dep");929
929 build_configurer_argv.appendAssumeCapacity(dep.name);930 try build_configurer_argv.append(gpa, "--listen=-");
930 }
931 build_configurer_argv.appendAssumeCapacity(try allocPrint(arena, "-M@dependencies={s}", .{
932 deps_mod.root_path,
933 }));
934 }931 }
935932
936 const compile_prog_node = main_progress_node.start("Compile Configure Script", 0);933 const compile_prog_node = main_progress_node.start("Compile Configure Script", 0);
937 defer compile_prog_node.end();934 defer compile_prog_node.end();
938935
939 try build_configurer_argv.append(gpa, "--listen=-");
940
941 const configure_exe_path: Path = if (std.zig.buildExeSubprocess(gpa, io, .{936 const configure_exe_path: Path = if (std.zig.buildExeSubprocess(gpa, io, .{
942 .argv = build_configurer_argv.items,937 .argv = build_configurer_argv.items,
943 .cache_root = graph.local_cache_root,938 .cache_root = graph.local_cache_root,
lib/std/zig.zig+1-3
...@@ -1798,9 +1798,7 @@ pub fn buildExeSubprocess(gpa: Allocator, io: Io, options: BuildExeSubprocessOpt...@@ -1798,9 +1798,7 @@ pub fn buildExeSubprocess(gpa: Allocator, io: Io, options: BuildExeSubprocessOpt
1798 return error.AlreadyReported;1798 return error.AlreadyReported;
1799 },1799 },
1800 };1800 };
1801 log.err("{s} command reported {d} compilation errors: {f}", .{1801 log.err("command reported {d} compilation errors: {f}", .{ result_error_bundle.errorMessageCount(), cmd });
1802 options.argv[0], result_error_bundle.errorMessageCount(), cmd,
1803 });
1804 if (received_fs_inputs) return error.FailedButCacheIntact;1802 if (received_fs_inputs) return error.FailedButCacheIntact;
1805 return error.AlreadyReported;1803 return error.AlreadyReported;
1806 }1804 }
src/Compilation.zig+3-5
...@@ -2766,11 +2766,9 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE...@@ -2766,11 +2766,9 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE
2766 .file_open, .file_stat, .file_read, .file_hash => |op| {2766 .file_open, .file_stat, .file_read, .file_hash => |op| {
2767 const pp = man.files.keys()[op.file_index].prefixed_path;2767 const pp = man.files.keys()[op.file_index].prefixed_path;
2768 const prefix = man.cache.prefixes()[pp.prefix];2768 const prefix = man.cache.prefixes()[pp.prefix];
2769 return comp.setMiscFailure(2769 return comp.setMiscFailure(.check_whole_cache, "failed to check cache: {f}{s} {t} {t}", .{
2770 .check_whole_cache,2770 prefix, pp.sub_path, man.diagnostic, op.err,
2771 "failed to check cache: '{f}{s}' {t} {t}",2771 });
2772 .{ prefix, pp.sub_path, man.diagnostic, op.err },
2773 );
2774 },2772 },
2775 },2773 },
2776 error.OutOfMemory, error.Canceled => |e| return e,2774 error.OutOfMemory, error.Canceled => |e| return e,