From e0b4f359ece7603f4f9d123f7630a0608e9b8381 Mon Sep 17 00:00:00 2001 From: Bingwu Zhang Date: Sat, 15 Mar 2025 09:22:26 +0800 Subject: [PATCH] build: allow overriding RSS limit for zig binary manually The max-RSS value had been bumped for several times during the 0.14.0 release cycle, showing that the current value is very close to the average RSS usage, with few redundant space. This adds a new option to specify the RSS upper bound for compiling Zig executable file. On AOSC OS, Zig 0.14.0 (& 0.13.0) fails to build on AArch64 and RISC-V 64, even when there are enough memory available on the build server. I have not found a minimal repro for this, but compilation does failed when all default settings of AOSC OS were applied. https://buildit.aosc.io/logs/72701-zig-0.14.0-riscv64-Estelle-buildit2-2025-03-15-03:47:45.txt https://buildit.aosc.io/logs/72698-zig-0.14.0-arm64-Zinfandel-2025-03-14-15:27:52.txt Signed-off-by: Bingwu Zhang --- build.zig | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/build.zig b/build.zig index 15762f0ae881..e79bd7f11e9f 100644 --- a/build.zig +++ b/build.zig @@ -179,6 +179,7 @@ pub fn build(b: *std.Build) !void { const pie = b.option(bool, "pie", "Produce a Position Independent Executable"); const value_interpret_mode = b.option(ValueInterpretMode, "value-interpret-mode", "How the compiler translates between 'std.builtin' types and its internal datastructures") orelse .direct; const value_tracing = b.option(bool, "value-tracing", "Enable extra state tracking to help troubleshoot bugs in the compiler (using the std.debug.Trace API)") orelse false; + const zig_max_rss = b.option(usize, "zig-max-rss", "Limit memory usage for compiling Zig binary"); const mem_leak_frames: u32 = b.option(u32, "mem-leak-frames", "How many stack frames to print when a memory leak occurs. Tests get 2x this amount.") orelse blk: { if (strip == true) break :blk @as(u32, 0); @@ -193,6 +194,7 @@ pub fn build(b: *std.Build) !void { .valgrind = valgrind, .sanitize_thread = sanitize_thread, .single_threaded = single_threaded, + .max_rss = zig_max_rss, }); exe.pie = pie; exe.entitlements = entitlements; @@ -662,6 +664,7 @@ const AddCompilerStepOptions = struct { valgrind: ?bool = null, sanitize_thread: ?bool = null, single_threaded: ?bool = null, + max_rss: ?usize = null, }; fn addCompilerStep(b: *std.Build, options: AddCompilerStepOptions) *std.Build.Step.Compile { @@ -707,7 +710,7 @@ fn addCompilerStep(b: *std.Build, options: AddCompilerStepOptions) *std.Build.St const exe = b.addExecutable(.{ .name = "zig", - .max_rss = 7_800_000_000, + .max_rss = options.max_rss orelse 7_800_000_000, .root_module = compiler_mod, }); exe.stack_size = stack_size;