authorgravatar for sertonix@posteo.netSertonix <sertonix@posteo.net> 2026-04-23 10:34:08+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-26 09:43:39-07:00
log8455563ed86ddb1fc3157e1bf74dc77c1e6aa6bb
treef71b4ae9cd25ece159a29abd51638465de016a86
parent0ff175b69ef806f421820d33dade7a8163fe3f16

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, ~^~~~~~~~~~~~~~~~~~~~~~~

7 files changed, 15 insertions(+), 15 deletions(-)

lib/compiler/Maker/WebServer.zig+2-2
...@@ -876,8 +876,8 @@ pub fn updateTimeReportRunTest(...@@ -876,8 +876,8 @@ pub fn updateTimeReportRunTest(
876 assert(tests.names.len == ns_per_test.len);876 assert(tests.names.len == ns_per_test.len);
877 const tests_len: u32 = @intCast(tests.names.len);877 const tests_len: u32 = @intCast(tests.names.len);
878878
879 const new_len: u64 = len: {879 const new_len: usize = len: {
880 var names_len: u64 = 0;880 var names_len: usize = 0;
881 for (0..tests_len) |i| {881 for (0..tests_len) |i| {
882 names_len += tests.testName(@intCast(i)).len + 1;882 names_len += tests.testName(@intCast(i)).len + 1;
883 }883 }
lib/std/Build.zig+5-5
...@@ -692,7 +692,7 @@ pub const ExecutableOptions = struct {...@@ -692,7 +692,7 @@ pub const ExecutableOptions = struct {
692 root_module: *Module,692 root_module: *Module,
693 version: ?std.SemanticVersion = null,693 version: ?std.SemanticVersion = null,
694 linkage: ?std.builtin.LinkMode = null,694 linkage: ?std.builtin.LinkMode = null,
695 max_rss: usize = 0,695 max_rss: u64 = 0,
696 use_llvm: ?bool = null,696 use_llvm: ?bool = null,
697 use_lld: ?bool = null,697 use_lld: ?bool = null,
698 zig_lib_dir: ?LazyPath = null,698 zig_lib_dir: ?LazyPath = null,
...@@ -722,7 +722,7 @@ pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile {...@@ -722,7 +722,7 @@ pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile {
722pub const ObjectOptions = struct {722pub const ObjectOptions = struct {
723 name: []const u8,723 name: []const u8,
724 root_module: *Module,724 root_module: *Module,
725 max_rss: usize = 0,725 max_rss: u64 = 0,
726 use_llvm: ?bool = null,726 use_llvm: ?bool = null,
727 use_lld: ?bool = null,727 use_lld: ?bool = null,
728 zig_lib_dir: ?LazyPath = null,728 zig_lib_dir: ?LazyPath = null,
...@@ -745,7 +745,7 @@ pub const LibraryOptions = struct {...@@ -745,7 +745,7 @@ pub const LibraryOptions = struct {
745 name: []const u8,745 name: []const u8,
746 root_module: *Module,746 root_module: *Module,
747 version: ?std.SemanticVersion = null,747 version: ?std.SemanticVersion = null,
748 max_rss: usize = 0,748 max_rss: u64 = 0,
749 use_llvm: ?bool = null,749 use_llvm: ?bool = null,
750 use_lld: ?bool = null,750 use_lld: ?bool = null,
751 zig_lib_dir: ?LazyPath = null,751 zig_lib_dir: ?LazyPath = null,
...@@ -778,7 +778,7 @@ pub fn addLibrary(b: *Build, options: LibraryOptions) *Step.Compile {...@@ -778,7 +778,7 @@ pub fn addLibrary(b: *Build, options: LibraryOptions) *Step.Compile {
778pub const TestOptions = struct {778pub const TestOptions = struct {
779 name: []const u8 = "test",779 name: []const u8 = "test",
780 root_module: *Module,780 root_module: *Module,
781 max_rss: usize = 0,781 max_rss: u64 = 0,
782 filters: []const []const u8 = &.{},782 filters: []const []const u8 = &.{},
783 test_runner: ?Step.Compile.TestRunner = null,783 test_runner: ?Step.Compile.TestRunner = null,
784 use_llvm: ?bool = null,784 use_llvm: ?bool = null,
...@@ -819,7 +819,7 @@ pub const AssemblyOptions = struct {...@@ -819,7 +819,7 @@ pub const AssemblyOptions = struct {
819 /// `host` field of the package's `Build` instance.819 /// `host` field of the package's `Build` instance.
820 target: ResolvedTarget,820 target: ResolvedTarget,
821 optimize: std.builtin.OptimizeMode,821 optimize: std.builtin.OptimizeMode,
822 max_rss: usize = 0,822 max_rss: u64 = 0,
823 zig_lib_dir: ?LazyPath = null,823 zig_lib_dir: ?LazyPath = null,
824};824};
825825
lib/std/Build/Step.zig+2-2
...@@ -30,7 +30,7 @@ dependencies: std.ArrayList(*Step),...@@ -30,7 +30,7 @@ dependencies: std.ArrayList(*Step),
30/// max_rss value that does not exceed the `max_total_rss` value of the build30/// max_rss value that does not exceed the `max_total_rss` value of the build
31/// runner. This value is configurable on the command line, and defaults to the31/// runner. This value is configurable on the command line, and defaults to the
32/// total system memory available.32/// total system memory available.
33max_rss: usize,33max_rss: u64,
3434
35/// The return address associated with creation of this step that can be useful35/// The return address associated with creation of this step that can be useful
36/// to print along with debugging messages.36/// to print along with debugging messages.
...@@ -87,7 +87,7 @@ pub const StepOptions = struct {...@@ -87,7 +87,7 @@ pub const StepOptions = struct {
87 name: []const u8,87 name: []const u8,
88 owner: *Build,88 owner: *Build,
89 first_ret_addr: ?usize = null,89 first_ret_addr: ?usize = null,
90 max_rss: usize = 0,90 max_rss: u64 = 0,
91};91};
9292
93pub fn init(options: StepOptions) Step {93pub fn init(options: StepOptions) Step {
lib/std/Build/Step/Compile.zig+1-1
...@@ -269,7 +269,7 @@ pub const Options = struct {...@@ -269,7 +269,7 @@ pub const Options = struct {
269 kind: Kind,269 kind: Kind,
270 linkage: ?std.builtin.LinkMode = null,270 linkage: ?std.builtin.LinkMode = null,
271 version: ?std.SemanticVersion = null,271 version: ?std.SemanticVersion = null,
272 max_rss: usize = 0,272 max_rss: u64 = 0,
273 filters: []const []const u8 = &.{},273 filters: []const []const u8 = &.{},
274 test_runner: ?TestRunner = null,274 test_runner: ?TestRunner = null,
275 use_llvm: ?bool = null,275 use_llvm: ?bool = null,
lib/std/elf.zig+2-2
...@@ -873,8 +873,8 @@ pub const ProgramHeaderBufferIterator = struct {...@@ -873,8 +873,8 @@ pub const ProgramHeaderBufferIterator = struct {
873 if (it.index >= it.phnum) return null;873 if (it.index >= it.phnum) return null;
874 defer it.index += 1;874 defer it.index += 1;
875875
876 const size: u64 = if (it.is_64) @sizeOf(Elf64_Phdr) else @sizeOf(Elf32_Phdr);876 const size: usize = if (it.is_64) @sizeOf(Elf64_Phdr) else @sizeOf(Elf32_Phdr);
877 const offset = it.phoff + size * it.index;877 const offset = @as(usize, @intCast(it.phoff)) + size * it.index;
878 var reader = Io.Reader.fixed(it.buf[offset..]);878 var reader = Io.Reader.fixed(it.buf[offset..]);
879879
880 return try takeProgramHeader(&reader, it.is_64, it.endian);880 return try takeProgramHeader(&reader, it.is_64, it.endian);
test/src/Libc.zig+1-1
...@@ -11,7 +11,7 @@ pub const Options = struct {...@@ -11,7 +11,7 @@ pub const Options = struct {
11 test_filters: []const []const u8,11 test_filters: []const []const u8,
12 test_target_filters: []const []const u8,12 test_target_filters: []const []const u8,
13 skip_wasm: bool,13 skip_wasm: bool,
14 max_rss: usize,14 max_rss: u64,
15};15};
1616
17const TestCase = struct {17const TestCase = struct {
test/tests.zig+2-2
...@@ -2467,7 +2467,7 @@ pub const ModuleTestOptions = struct {...@@ -2467,7 +2467,7 @@ pub const ModuleTestOptions = struct {
2467 skip_linux: bool,2467 skip_linux: bool,
2468 skip_llvm: bool,2468 skip_llvm: bool,
2469 skip_libc: bool,2469 skip_libc: bool,
2470 max_rss: usize = 0,2470 max_rss: u64 = 0,
2471 no_builtin: bool = false,2471 no_builtin: bool = false,
2472 sanitize_thread: ?bool = null,2472 sanitize_thread: ?bool = null,
2473 build_options: ?*Step.Options = null,2473 build_options: ?*Step.Options = null,
...@@ -2795,7 +2795,7 @@ const CAbiTestOptions = struct {...@@ -2795,7 +2795,7 @@ const CAbiTestOptions = struct {
2795 skip_darwin: bool,2795 skip_darwin: bool,
2796 skip_linux: bool,2796 skip_linux: bool,
2797 skip_llvm: bool,2797 skip_llvm: bool,
2798 max_rss: usize = 0,2798 max_rss: u64 = 0,
2799};2799};
28002800
2801pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step {2801pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step {