From 8455563ed86ddb1fc3157e1bf74dc77c1e6aa6bb Mon Sep 17 00:00:00 2001 From: Sertonix Date: Thu, 23 Apr 2026 10:34:08 +0200 Subject: [PATCH] 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