OOM on zig build
Opus has his idea:
The issue was that build.zig was calling std_compat.process.Child.run(...) which internally used the compat shim's io() — an Io.Threaded initialized with .allocator = .failing (the default for init_single_threaded). In a build script, initProcess() is never called, so the global Io remained in this "failing" state.
The fix at build.zig:120-131 now:
Constructs a real std.process.Environ from the libc environ pointer (so PATH is available for resolving npm)
Creates a properly initialized std.Io.Threaded with the build allocator and the environment
Calls std.process.run directly with this valid Io instance
The raw stderr output is below:
[8:30:17]> $ zig build
thread 12553504 panic: failed to run npm: OutOfMemory
error return context:
/opt/homebrew/Cellar/zig/0.16.0_1/lib/zig/std/mem/Allocator.zig:300:82: 0x1049f63b7 in allocBytesWithAlignment__anon_9206 (build)
const byte_ptr = self.rawAlloc(byte_count, alignment, return_address) orelse return error.OutOfMemory;
^
/opt/homebrew/Cellar/zig/0.16.0_1/lib/zig/std/mem/Allocator.zig:286:5: 0x104a88a3b in allocWithSizeAndAlignment__anon_19251 (build)
return self.allocBytesWithAlignment(alignment, byte_count, return_address);
^
/opt/homebrew/Cellar/zig/0.16.0_1/lib/zig/std/mem/Allocator.zig:274:55: 0x104a89023 in allocAdvancedWithRetAddr (build)
const ptr: []align(a.toByteUnits()) T = @ptrCast(try self.allocWithSizeAndAlignment(@sizeof(T), a, n, return_address));
^
/opt/homebrew/Cellar/zig/0.16.0_1/lib/zig/std/mem/Allocator.zig:222:21: 0x104a890e3 in allocWithOptionsRetAddr__anon_19269 (build)
const ptr = try self.allocAdvancedWithRetAddr(Elem, optional_alignment, n + 1, return_address);
^
/opt/homebrew/Cellar/zig/0.16.0_1/lib/zig/std/mem/Allocator.zig:252:5: 0x104a88bf3 in allocSentinel__anon_18389 (build)
return self.allocWithOptionsRetAddr(Elem, n, null, sentinel, @returnaddress());
^
/opt/homebrew/Cellar/zig/0.16.0_1/lib/zig/std/Io/Threaded.zig:14926:22: 0x104a7c7cf in spawnPosix (build)
const argv_buf = try arena.allocSentinel(?[:0]const u8, options.argv.len, null);
^
/opt/homebrew/Cellar/zig/0.16.0_1/lib/zig/std/Io/Threaded.zig:15098:21: 0x104a7b04f in processSpawnPosix (build)
const spawned = try spawnPosix(t, options);
^
/opt/homebrew/Cellar/zig/0.16.0_1/lib/zig/std/process.zig:443:5: 0x104b682e7 in spawn (build)
return io.vtable.processSpawn(io.userdata, options);
^
/opt/homebrew/Cellar/zig/0.16.0_1/lib/zig/std/process.zig:497:17: 0x104cb30bb in run (build)
var child = try spawn(io, .{
^
/Users/cheleb/projects/cheleb/nullhub/src/compat.zig:180:20: 0x104cb2337 in run (build)
return try std.process.run(options.allocator, io(), .{
^
stack trace:
/Users/cheleb/projects/cheleb/nullhub/build.zig:147:35: 0x104cb2503 in runCommandOrPanic (build)
}) catch |err| std.debug.panic("failed to run {s}: {s}", .{ argv[0], @Errorname(err) });
^
/Users/cheleb/projects/cheleb/nullhub/build.zig:130:26: 0x104cb1fcf in ensureUiBuildReady (build)
runCommandOrPanic(b.allocator, &.{ npmCommand(), "--prefix", "ui", "ci", "--no-audit", "--no-fund" });
^
/Users/cheleb/projects/cheleb/nullhub/build.zig:39:41: 0x104c709b3 in build (build)
if (build_ui) ensureUiBuildReady(b);
^
/opt/homebrew/Cellar/zig/0.16.0_1/lib/zig/std/Build.zig:2264:33: 0x104c700f7 in runBuild__anon_28487 (build)
.void => build_zig.build(b),
^
/opt/homebrew/Cellar/zig/0.16.0_1/lib/zig/compiler/build_runner.zig:463:29: 0x104adbf3f in main (build)
try builder.runBuild(root);
^
/opt/homebrew/Cellar/zig/0.16.0_1/lib/zig/std/start.zig:699:88: 0x104ade1db in callMain (build)
if (fn_info.params[0].type.? == std.process.Init.Minimal) return wrapMain(root.main(.{
^
???:?:?: 0x18f355d53 in start (/usr/lib/dyld)
error: the following build command terminated with signal ABRT:
.zig-cache/o/8a3b1f4e137ffb9f7771b008cd9593a4/build /opt/homebrew/Cellar/zig/0.16.0_1/bin/zig /opt/homebrew/Cellar/zig/0.16.0_1/lib/zig /Users/cheleb/projects/cheleb/nullhub .zig-cache /Users/cheleb/.cache/zig --seed 0xca55575e -Z99f417f13996088d
OOM on zig build
Opus has his idea:
The raw stderr output is below: