Skip to content

Commit 9573495

Browse files
committed
fix: pass process environ to Io backend, fixing AppDataDirUnavailable
runtime.init() was calling Threaded.init(gpa, .{}) without passing the process environ. The default environ in InitOptions is .empty, so all child processes spawned via std.process.run/spawn received zero environment variables. This caused 'mer dev', 'mer build', and 'mer update' to fail on Linux with 'unable to resolve zig cache directory: AppDataDirUnavailable' because the child zig process had no HOME variable. Fix: accept environ as a parameter in runtime.init() and forward it to the Io backend (Threaded or Evented). All callsites now pass init.environ from the Init.Minimal entry point. Fixes child process environment inheritance on all platforms.
1 parent fe5b35c commit 9573495

6 files changed

Lines changed: 10 additions & 10 deletions

File tree

cli.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub fn main(init: std.process.Init.Minimal) !void {
5353
const alloc = gpa.allocator();
5454

5555
// Initialize std.Io runtime (Auto-selects Evented on Linux, Threaded elsewhere)
56-
try runtime.init(alloc);
56+
try runtime.init(alloc, init.environ);
5757
defer runtime.deinit();
5858

5959
var arena_state: std.heap.ArenaAllocator = .init(std.heap.page_allocator);

examples/ui-showcase/src/main.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub fn main(init: std.process.Init.Minimal) !void {
1616
const alloc = gpa.allocator();
1717

1818
// Initialize std.Io runtime (Auto-selects Evented on Linux, Threaded elsewhere)
19-
try runtime.init(alloc);
19+
try runtime.init(alloc, init.environ);
2020
defer runtime.deinit();
2121

2222
var arena_state: std.heap.ArenaAllocator = .init(std.heap.page_allocator);

src/main.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub fn main(init: std.process.Init.Minimal) !void {
1616
const alloc = gpa.allocator();
1717

1818
// Initialize std.Io runtime (Auto-selects Evented on Linux, Threaded elsewhere)
19-
try runtime.init(alloc);
19+
try runtime.init(alloc, init.environ);
2020
defer runtime.deinit();
2121

2222
// 0.16: args come through init parameter.

src/runtime.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ const use_evented = blk: {
2121
// Evented storage only exists when supported
2222
var evented: if (use_evented) std.Io.Evented else void = undefined;
2323

24-
pub fn init(gpa: std.mem.Allocator) !void {
24+
pub fn init(gpa: std.mem.Allocator, environ: std.process.Environ) !void {
2525
if (use_evented) {
2626
// Linux: Use Evented (io_uring)
2727
evented = undefined;
28-
try std.Io.Evented.init(&evented, gpa, .{});
28+
try std.Io.Evented.init(&evented, gpa, .{ .environ = environ });
2929
io = evented.io();
3030
} else {
3131
// macOS/Other: Use Threaded (Evented has bugs or isn't available)
32-
threaded = std.Io.Threaded.init(gpa, .{});
32+
threaded = std.Io.Threaded.init(gpa, .{ .environ = environ });
3333
io = threaded.io();
3434
}
3535
}

src/runtime_threaded.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ const std = @import("std");
66
/// This lets us flip between Threaded (today) and Evented (tomorrow for io_uring)
77
/// without touching call sites.
88
///
9-
/// Initialize once in main(): runtime.init(gpa);
9+
/// Initialize once in main(): runtime.init(gpa, init.environ);
1010
/// Clean up on exit: defer runtime.deinit();
1111
pub var threaded: std.Io.Threaded = undefined;
1212
pub var io: std.Io = undefined;
1313

14-
pub fn init(gpa: std.mem.Allocator) void {
15-
threaded = std.Io.Threaded.init(gpa, .{});
14+
pub fn init(gpa: std.mem.Allocator, environ: std.process.Environ) void {
15+
threaded = std.Io.Threaded.init(gpa, .{ .environ = environ });
1616
io = threaded.io();
1717
}
1818

tools/codegen.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub fn main() !void {
1010
const alloc = gpa.allocator();
1111

1212
// Initialize std.Io runtime (Auto-selects Evented on Linux, Threaded elsewhere)
13-
try runtime.init(alloc);
13+
try runtime.init(alloc, .empty);
1414
defer runtime.deinit();
1515

1616
// Each entry stores the full relative path from the project root.

0 commit comments

Comments
 (0)