diff --git a/lib/compiler/build_runner.zig b/lib/compiler/build_runner.zig index b760fd0c4cda782d61b74c42251d2a5b534de4f1..f156a47d8c7c71c78397583433ac91ee2c9a8a58 100644 --- a/lib/compiler/build_runner.zig +++ b/lib/compiler/build_runner.zig @@ -532,7 +532,7 @@ pub fn main(init: process.Init.Minimal) !void { } prepare(arena, builder, targets.items, &run, graph.random_seed) catch |err| switch (err) { - error.DependencyLoopDetected => { + error.DependencyLoopDetected, error.InsufficientMemory => { // Perhaps in the future there could be an Advanced Options flag // such as --debug-build-runner-leaks which would make this code // return instead of calling exit. @@ -696,8 +696,8 @@ fn prepare( for (0..step_names.len) |i| { const step_name = step_names[step_names.len - i - 1]; const s = b.top_level_steps.get(step_name) orelse { - std.debug.print("no step named '{s}'\n access the help menu with 'zig build -h'\n", .{step_name}); - process.exit(1); + std.log.info("access the help menu with \"zig build -h\"", .{}); + fatal("no step named '{s}'", .{step_name}); }; step_stack.putAssumeCapacity(&s.step, {}); } @@ -716,8 +716,10 @@ fn prepare( { // Check that we have enough memory to complete the build. var any_problems = false; + var max_needed: usize = 0; for (step_stack.keys()) |s| { if (s.max_rss == 0) continue; + max_needed = @max(max_needed, s.max_rss); if (s.max_rss > run.available_rss) { if (run.skip_oom_steps) { s.state = .skipped_oom; @@ -725,7 +727,7 @@ fn prepare( dependant.pending_deps -= 1; } } else { - std.debug.print("{s}{s}: this step declares an upper bound of {d} bytes of memory, exceeding the available {d} bytes of memory\n", .{ + std.log.err("{s}{s}: this step declares an upper bound of {d} bytes of memory, exceeding the available {d} bytes of memory", .{ s.owner.dep_prefix, s.name, s.max_rss, run.available_rss, }); any_problems = true; @@ -734,8 +736,11 @@ fn prepare( } if (any_problems) { if (run.max_rss_is_default) { - std.debug.print("note: use --maxrss to override the default", .{}); + std.log.info("use --maxrss {d} to proceed, risking system memory exhaustion", .{ + max_needed, + }); } + return error.InsufficientMemory; } } }