From 8455563ed86ddb1fc3157e1bf74dc77c1e6aa6bb Mon Sep 17 00:00:00 2001 From: Sertonix Date: Thu, 23 Apr 2026 10:34:08 +0200 Subject: [PATCH 1/3] Fix build script compilation when usize is u32 On 32-bit systems usize is not u64 but it was assumed in multiple places of the build script. Sometimes using u64 instead of usize since available and used memory can exceed usize on 32-bit systems (just like totalSystemMemory) Example errors: lib/compiler/build_runner.zig:508:26: error: expected type 'usize', found 'u64' .available_rss = max_rss, ^~~~~~~ lib/compiler/build_runner.zig:508:26: note: unsigned 32-bit int cannot represent all possible unsigned 64-bit values referenced by: callMain [inlined]: lib/std/start.zig:699:88 callMainWithArgs [inlined]: lib/std/start.zig:638:20 posixCallMainAndExit: lib/std/start.zig:590:38 2 reference(s) hidden; use '-freference-trace=5' to see all references lib/std/Build/WebServer.zig:849:38: error: expected type 'usize', found 'u64' const buf = gpa.realloc(old_buf, new_len) catch @panic("out of memory"); ^~~~~~~ lib/std/Build/WebServer.zig:849:38: note: unsigned 32-bit int cannot represent all possible unsigned 64-bit values lib/std/mem/Allocator.zig:399:58: note: parameter type declared here pub fn realloc(self: Allocator, old_mem: anytype, new_n: usize) Error!@TypeOf(old_mem) { ^~~~~ build.zig:548:10: error: type 'usize' cannot represent integer value '9300000000' .max_rss = 9_300_000_000, ~^~~~~~~~~~~~~~~~~~~~~~~ build.zig:778:10: error: type 'usize' cannot represent integer value '8000000000' .max_rss = 8_000_000_000, ~^~~~~~~~~~~~~~~~~~~~~~~ --- lib/compiler/Maker/WebServer.zig | 4 ++-- lib/std/Build.zig | 10 +++++----- lib/std/Build/Step.zig | 4 ++-- lib/std/Build/Step/Compile.zig | 2 +- lib/std/elf.zig | 4 ++-- test/src/Libc.zig | 2 +- test/tests.zig | 4 ++-- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/compiler/Maker/WebServer.zig b/lib/compiler/Maker/WebServer.zig index 943265c9397eb1ce20738171557e9f53134477c7..5191e6ab2d7465de8ff690afd2d904ce48ff6c50 100644 --- a/lib/compiler/Maker/WebServer.zig +++ b/lib/compiler/Maker/WebServer.zig @@ -876,8 +876,8 @@ pub fn updateTimeReportRunTest( assert(tests.names.len == ns_per_test.len); const tests_len: u32 = @intCast(tests.names.len); - const new_len: u64 = len: { - var names_len: u64 = 0; + const new_len: usize = len: { + var names_len: usize = 0; for (0..tests_len) |i| { names_len += tests.testName(@intCast(i)).len + 1; } diff --git a/lib/std/Build.zig b/lib/std/Build.zig index bc77290f131a15926eb9e561bd030658b91ce60c..6cbb820d96229d11f555d506317c54df170fe574 100644 --- a/lib/std/Build.zig +++ b/lib/std/Build.zig @@ -692,7 +692,7 @@ pub const ExecutableOptions = struct { root_module: *Module, version: ?std.SemanticVersion = null, linkage: ?std.builtin.LinkMode = null, - max_rss: usize = 0, + max_rss: u64 = 0, use_llvm: ?bool = null, use_lld: ?bool = null, zig_lib_dir: ?LazyPath = null, @@ -722,7 +722,7 @@ pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile { pub const ObjectOptions = struct { name: []const u8, root_module: *Module, - max_rss: usize = 0, + max_rss: u64 = 0, use_llvm: ?bool = null, use_lld: ?bool = null, zig_lib_dir: ?LazyPath = null, @@ -745,7 +745,7 @@ pub const LibraryOptions = struct { name: []const u8, root_module: *Module, version: ?std.SemanticVersion = null, - max_rss: usize = 0, + max_rss: u64 = 0, use_llvm: ?bool = null, use_lld: ?bool = null, zig_lib_dir: ?LazyPath = null, @@ -778,7 +778,7 @@ pub fn addLibrary(b: *Build, options: LibraryOptions) *Step.Compile { pub const TestOptions = struct { name: []const u8 = "test", root_module: *Module, - max_rss: usize = 0, + max_rss: u64 = 0, filters: []const []const u8 = &.{}, test_runner: ?Step.Compile.TestRunner = null, use_llvm: ?bool = null, @@ -819,7 +819,7 @@ pub const AssemblyOptions = struct { /// `host` field of the package's `Build` instance. target: ResolvedTarget, optimize: std.builtin.OptimizeMode, - max_rss: usize = 0, + max_rss: u64 = 0, zig_lib_dir: ?LazyPath = null, }; diff --git a/lib/std/Build/Step.zig b/lib/std/Build/Step.zig index b35697a2a1bba5896737df3d4375d433934795fb..78c1e3343c23acec72985f2b9d357e52dc3b977f 100644 --- a/lib/std/Build/Step.zig +++ b/lib/std/Build/Step.zig @@ -30,7 +30,7 @@ dependencies: std.ArrayList(*Step), /// max_rss value that does not exceed the `max_total_rss` value of the build /// runner. This value is configurable on the command line, and defaults to the /// total system memory available. -max_rss: usize, +max_rss: u64, /// The return address associated with creation of this step that can be useful /// to print along with debugging messages. @@ -87,7 +87,7 @@ pub const StepOptions = struct { name: []const u8, owner: *Build, first_ret_addr: ?usize = null, - max_rss: usize = 0, + max_rss: u64 = 0, }; pub fn init(options: StepOptions) Step { diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig index 448e3b0dde840fae5d42c2b194fc404b5eb01cd0..f61a55d9214ed096c793e29866cf96bfafab9057 100644 --- a/lib/std/Build/Step/Compile.zig +++ b/lib/std/Build/Step/Compile.zig @@ -269,7 +269,7 @@ pub const Options = struct { kind: Kind, linkage: ?std.builtin.LinkMode = null, version: ?std.SemanticVersion = null, - max_rss: usize = 0, + max_rss: u64 = 0, filters: []const []const u8 = &.{}, test_runner: ?TestRunner = null, use_llvm: ?bool = null, diff --git a/lib/std/elf.zig b/lib/std/elf.zig index fcf5152a2b7ec8a12e9bddb954829d71f5e1bb5b..afcf236c28b4a0e4c0df14efde65620fcd4441e9 100644 --- a/lib/std/elf.zig +++ b/lib/std/elf.zig @@ -873,8 +873,8 @@ pub const ProgramHeaderBufferIterator = struct { if (it.index >= it.phnum) return null; defer it.index += 1; - const size: u64 = if (it.is_64) @sizeOf(Elf64_Phdr) else @sizeOf(Elf32_Phdr); - const offset = it.phoff + size * it.index; + const size: usize = if (it.is_64) @sizeOf(Elf64_Phdr) else @sizeOf(Elf32_Phdr); + const offset = @as(usize, @intCast(it.phoff)) + size * it.index; var reader = Io.Reader.fixed(it.buf[offset..]); return try takeProgramHeader(&reader, it.is_64, it.endian); diff --git a/test/src/Libc.zig b/test/src/Libc.zig index a7cb01c8252edf4ce8b10bab454f95913483a13c..d2113893325821c63a441eba99ea06f1a4610402 100644 --- a/test/src/Libc.zig +++ b/test/src/Libc.zig @@ -11,7 +11,7 @@ pub const Options = struct { test_filters: []const []const u8, test_target_filters: []const []const u8, skip_wasm: bool, - max_rss: usize, + max_rss: u64, }; const TestCase = struct { diff --git a/test/tests.zig b/test/tests.zig index b88dc8e3c57edb1d09497e587dd17f0823e218c4..0bb1b942e72d6829fa5e25929b80118b4d2a7363 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -2467,7 +2467,7 @@ pub const ModuleTestOptions = struct { skip_linux: bool, skip_llvm: bool, skip_libc: bool, - max_rss: usize = 0, + max_rss: u64 = 0, no_builtin: bool = false, sanitize_thread: ?bool = null, build_options: ?*Step.Options = null, @@ -2795,7 +2795,7 @@ const CAbiTestOptions = struct { skip_darwin: bool, skip_linux: bool, skip_llvm: bool, - max_rss: usize = 0, + max_rss: u64 = 0, }; pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step { -- 2.54.0 From 7228dc0ef98633876344c00fbadcef319dd11257 Mon Sep 17 00:00:00 2001 From: Sertonix Date: Fri, 24 Apr 2026 21:20:50 +0200 Subject: [PATCH 2/3] langref: fix compilation if usize is u32 --- doc/langref/test_peer_type_resolution.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/langref/test_peer_type_resolution.zig b/doc/langref/test_peer_type_resolution.zig index de498fc5c80144e4257a3b6ff4dc35a08c0bedb3..f55ae25bcf76e46506d71672ab25b2a46e5bc971 100644 --- a/doc/langref/test_peer_type_resolution.zig +++ b/doc/langref/test_peer_type_resolution.zig @@ -96,8 +96,8 @@ fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 { } test "peer type resolution: *const T and ?*T" { - const a: *const usize = @ptrFromInt(0x123456780); - const b: ?*usize = @ptrFromInt(0x123456780); + const a: *const usize = @ptrFromInt(0x12345678); + const b: ?*usize = @ptrFromInt(0x12345678); try expectEqual(a, b); try expectEqual(b, a); } -- 2.54.0 From fd63f57cd86ebcf1261b10d1a17e62d523e70981 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 26 May 2026 09:50:48 -0700 Subject: [PATCH 3/3] build system: update more usize to u64 for maxrss makes the build system compile on 32 bit systems bonus, also fix incorrectly passing advanced debug options to the maker process which doesn't care about them --- lib/compiler/Maker.zig | 4 ++-- lib/compiler/Maker/Step/Run.zig | 4 ++-- lib/compiler/configurer.zig | 2 +- lib/std/Build/Configuration.zig | 4 ++-- lib/std/Io.zig | 7 +++++++ src/main.zig | 2 ++ 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/compiler/Maker.zig b/lib/compiler/Maker.zig index 07ca3d436352ff001131f7dd79074c5d797ce934..5aaf6e9d13f4255f84323b2d8876065ed094057d 100644 --- a/lib/compiler/Maker.zig +++ b/lib/compiler/Maker.zig @@ -38,7 +38,7 @@ steps: []Step, generated_files: []Path, run_args: ?[]const []const u8, -available_rss: usize, +available_rss: u64, max_rss_is_default: bool, max_rss_mutex: Io.Mutex, skip_oom_steps: bool, @@ -740,7 +740,7 @@ fn prepare(maker: *Maker, step_names: []const []const u8) !void { { // Check that we have enough memory to complete the build. var any_problems = false; - var max_needed: usize = 0; + var max_needed: u64 = 0; for (step_stack.keys()) |step_index| { const make_step = maker.stepByIndex(step_index); const conf_step = step_index.ptr(c); diff --git a/lib/compiler/Maker/Step/Run.zig b/lib/compiler/Maker/Step/Run.zig index e59fec11efd18b5fd714a27b67e90ba4762e5bf3..e8d8f4f2ba56842a8daf7d4fe4ce0fb8da994bf8 100644 --- a/lib/compiler/Maker/Step/Run.zig +++ b/lib/compiler/Maker/Step/Run.zig @@ -1460,7 +1460,7 @@ fn evalGeneric( stderr_bytes = try multi_reader.toOwnedSlice(1); } else { var stdout_reader = stdout.readerStreaming(io, &.{}); - const stdio_limit: Io.Limit = if (conf_run.stdio_limit.value) |x| .limited(x) else .unlimited; + const stdio_limit: Io.Limit = if (conf_run.stdio_limit.value) |x| .limited64(x) else .unlimited; stdout_bytes = stdout_reader.interface.allocRemaining(arena, stdio_limit) catch |err| switch (err) { error.OutOfMemory => |e| return e, error.ReadFailed => return stdout_reader.err.?, @@ -1469,7 +1469,7 @@ fn evalGeneric( } } else if (child.stderr) |stderr| { var stderr_reader = stderr.readerStreaming(io, &.{}); - const stdio_limit: Io.Limit = if (conf_run.stdio_limit.value) |x| .limited(x) else .unlimited; + const stdio_limit: Io.Limit = if (conf_run.stdio_limit.value) |x| .limited64(x) else .unlimited; stderr_bytes = stderr_reader.interface.allocRemaining(arena, stdio_limit) catch |err| switch (err) { error.OutOfMemory => |e| return e, error.ReadFailed => return stderr_reader.err.?, diff --git a/lib/compiler/configurer.zig b/lib/compiler/configurer.zig index 308bf55fe72f4ab881f1168c96b1fc9ae9476bc3..b88c410b22addad55c61a2e26c3ceab17843c28c 100644 --- a/lib/compiler/configurer.zig +++ b/lib/compiler/configurer.zig @@ -1074,7 +1074,7 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void { } else null }, .environ_map = .{ .value = try s.addEnvironMap(run.environ_map) }, .expect_term_value = .{ .value = if (expect_term) |t| t.value else null }, - .stdio_limit = .{ .value = run.stdio_limit.toInt() }, + .stdio_limit = .{ .value = run.stdio_limit.toInt64() }, .producer = .{ .value = if (run.producer) |cs| s.stepIndex(&cs.step) else null }, .expect_stderr_exact = .{ .value = if (expect_stderr_exact) |bytes| bytes else null }, .expect_stdout_exact = .{ .value = if (expect_stdout_exact) |bytes| bytes else null }, diff --git a/lib/std/Build/Configuration.zig b/lib/std/Build/Configuration.zig index a8934415755bed46f7c17bd9addd925ffaddde22..26fb7b68e43e358b8cb3bc2991148b8cda4441fc 100644 --- a/lib/std/Build/Configuration.zig +++ b/lib/std/Build/Configuration.zig @@ -1458,12 +1458,12 @@ pub const MaxRss = enum(u32) { none = 0, _, - pub fn toBytes(mr: MaxRss) usize { + pub fn toBytes(mr: MaxRss) u64 { const x: usize = @intFromEnum(mr); return x << 8; } - pub fn fromBytes(bytes: usize) MaxRss { + pub fn fromBytes(bytes: u64) MaxRss { return @enumFromInt(bytes >> 8); } }; diff --git a/lib/std/Io.zig b/lib/std/Io.zig index f3ef2757acad16f3dc4e548cc25d1172ba47e032..226de91cf7d720d58721f940354490835feba928 100644 --- a/lib/std/Io.zig +++ b/lib/std/Io.zig @@ -689,6 +689,13 @@ pub const Limit = enum(usize) { }; } + pub fn toInt64(l: Limit) ?u64 { + return switch (l) { + else => @intFromEnum(l), + .unlimited => null, + }; + } + /// Reduces a slice to account for the limit, leaving room for one extra /// byte above the limit, allowing for the use case of differentiating /// between end-of-stream and reaching the limit. diff --git a/src/main.zig b/src/main.zig index bd73f5a08a4d36cf65517b161d13b548d6ee19d6..80443b5709c9be7364e7f2439667711c4e4b3b30 100644 --- a/src/main.zig +++ b/src/main.zig @@ -5133,6 +5133,7 @@ fn cmdBuild( } else { warn("Zig was compiled without debug extensions. --debug-target has no effect.", .{}); } + continue; } else if (mem.eql(u8, arg, "--debug-libc")) { if (i + 1 >= args.len) fatal("expected argument after '{s}'", .{arg}); i += 1; @@ -5141,6 +5142,7 @@ fn cmdBuild( } else { warn("Zig was compiled without debug extensions. --debug-libc has no effect.", .{}); } + continue; } else if (mem.eql(u8, arg, "--verbose-link")) { verbose_link = true; } else if (mem.eql(u8, arg, "--verbose-cc")) { -- 2.54.0