authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-31 16:02:44-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-01-04 00:27:08-08:00
log69d07472a12c8ec8f83a43ed63c1ab7e2ab71c14
tree2599e7a3ffecd39f14b8c72c0e51eb29a88fa286
parent3e6d6150d98658e6c46ad5c378f90fb628f97d2a

std lib tests passing on linux


8 files changed, 46 insertions(+), 55 deletions(-)

lib/std/Build/Step.zig+9-10
......@@ -448,7 +448,10 @@ pub fn evalZigProcess(
448448 try handleChildProcUnsupported(s);
449449 try handleVerbose(s.owner, null, argv);
450450
451 var child = std.process.spawn(io, .{
451 const zp = try gpa.create(ZigProcess);
452 defer if (!watch) gpa.destroy(zp);
453
454 zp.child = std.process.spawn(io, .{
452455 .argv = argv,
453456 .env_map = &b.graph.env_map,
454457 .stdin = .pipe,
......@@ -457,22 +460,18 @@ pub fn evalZigProcess(
457460 .request_resource_usage_statistics = true,
458461 .progress_node = prog_node,
459462 }) catch |err| return s.fail("failed to spawn zig compiler {s}: {t}", .{ argv[0], err });
460 defer if (!watch) child.kill(io);
463 defer if (!watch) zp.child.kill(io);
461464
462 const zp = try gpa.create(ZigProcess);
463465 zp.* = .{
464 .child = child,
466 .child = zp.child,
465467 .poller = Io.poll(gpa, ZigProcess.StreamEnum, .{
466 .stdout = child.stdout.?,
467 .stderr = child.stderr.?,
468 .stdout = zp.child.stdout.?,
469 .stderr = zp.child.stderr.?,
468470 }),
469471 .progress_ipc_fd = if (std.Progress.have_ipc) prog_node.getIpcFd() else {},
470472 };
471473 if (watch) s.setZigProcess(zp);
472 defer if (!watch) {
473 zp.poller.deinit();
474 gpa.destroy(zp);
475 };
474 defer if (!watch) zp.poller.deinit();
476475
477476 const result = try zigProcessUpdate(s, zp, watch, web_server, gpa);
478477
lib/std/Io.zig-5
......@@ -2240,8 +2240,3 @@ pub fn tryLockStderr(io: Io, buffer: []u8, terminal_mode: ?Terminal.Mode) Cancel
22402240pub fn unlockStderr(io: Io) void {
22412241 return io.vtable.unlockStderr(io.userdata);
22422242}
2243
2244pub fn environ(io: Io, name: []const u8) ?[]const u8 {
2245 _ = io;
2246 std.debug.panic("TODO: environ query: {s}", .{name});
2247}
lib/std/Io/Threaded.zig+20-30
......@@ -101,6 +101,9 @@ pub const Environ = struct {
101101 .windows, .wasi => struct {},
102102 else => struct {
103103 PATH: ?[:0]const u8 = null,
104 DEBUGINFOD_CACHE_PATH: ?[:0]const u8 = null,
105 XDG_CACHE_HOME: ?[:0]const u8 = null,
106 HOME: ?[:0]const u8 = null,
104107 },
105108 };
106109};
......@@ -12674,27 +12677,6 @@ fn scanEnviron(t: *Threaded) void {
1267412677 }
1267512678 comptime assert(@sizeOf(Environ.String) == 0);
1267612679 }
12677 } else if (builtin.link_libc) {
12678 var ptr = std.c.environ;
12679 while (ptr[0]) |line| : (ptr += 1) {
12680 var line_i: usize = 0;
12681 while (line[line_i] != 0 and line[line_i] != '=') : (line_i += 1) {}
12682 const key = line[0..line_i];
12683
12684 var end_i: usize = line_i;
12685 while (line[end_i] != 0) : (end_i += 1) {}
12686 const value = line[line_i + 1 .. end_i :0];
12687
12688 if (std.mem.eql(u8, key, "NO_COLOR")) {
12689 t.environ.exist.NO_COLOR = true;
12690 } else if (std.mem.eql(u8, key, "CLICOLOR_FORCE")) {
12691 t.environ.exist.CLICOLOR_FORCE = true;
12692 } else if (@hasField(Environ.String, "PATH") and std.mem.eql(u8, key, "PATH")) {
12693 t.environ.string.PATH = value;
12694 } else if (std.mem.eql(u8, key, "ZIG_PROGRESS")) {
12695 t.environ.zig_progress_handle = std.fmt.parseInt(u31, value, 10) catch error.UnrecognizedFormat;
12696 }
12697 }
1269812680 } else {
1269912681 for (t.environ.block) |opt_line| {
1270012682 const line = opt_line.?;
......@@ -12710,10 +12692,10 @@ fn scanEnviron(t: *Threaded) void {
1271012692 t.environ.exist.NO_COLOR = true;
1271112693 } else if (std.mem.eql(u8, key, "CLICOLOR_FORCE")) {
1271212694 t.environ.exist.CLICOLOR_FORCE = true;
12713 } else if (@hasField(Environ.String, "PATH") and std.mem.eql(u8, key, "PATH")) {
12714 t.environ.string.PATH = value;
1271512695 } else if (std.mem.eql(u8, key, "ZIG_PROGRESS")) {
1271612696 t.environ.zig_progress_handle = std.fmt.parseInt(u31, value, 10) catch error.UnrecognizedFormat;
12697 } else inline for (@typeInfo(Environ.String).@"struct".fields) |field| {
12698 if (std.mem.eql(u8, key, field.name)) @field(t.environ.string, field.name) = value;
1271712699 }
1271812700 }
1271912701 }
......@@ -12966,12 +12948,10 @@ fn childKill(userdata: ?*anyopaque, child: *std.process.Child) void {
1296612948 if (is_windows) {
1296712949 childKillWindows(t, child, 1) catch {
1296812950 childCleanupStreams(child);
12969 child.id = null;
1297012951 };
1297112952 } else {
1297212953 childKillPosix(t, child) catch {
1297312954 childCleanupStreams(child);
12974 child.id = null;
1297512955 };
1297612956 }
1297712957}
......@@ -13012,7 +12992,6 @@ fn childWaitWindows(t: *Threaded, child: *process.Child) process.Child.WaitError
1301212992 posix.close(child.id);
1301312993 posix.close(child.thread_handle);
1301412994 childCleanupStreams(child);
13015 child.id = null;
1301612995 return term;
1301712996}
1301812997
......@@ -13028,10 +13007,8 @@ fn childWaitPosix(t: *Threaded, child: *process.Child) process.Child.WaitError!p
1302813007 }
1302913008 break :res posix.waitpid(pid, 0);
1303013009 };
13031 const status = res.status;
1303213010 childCleanupStreams(child);
13033 child.id = null;
13034 return statusToTerm(status);
13011 return statusToTerm(res.status);
1303513012}
1303613013
1303713014fn statusToTerm(status: u32) process.Child.Term {
......@@ -13046,7 +13023,14 @@ fn statusToTerm(status: u32) process.Child.Term {
1304613023}
1304713024
1304813025fn childKillPosix(t: *Threaded, child: *process.Child) !void {
13049 try posix.kill(child.id.?, posix.SIG.TERM);
13026 while (true) switch (posix.errno(posix.system.kill(child.id.?, .TERM))) {
13027 .SUCCESS => break,
13028 .INTR => continue,
13029 .PERM => return error.PermissionDenied,
13030 .INVAL => |err| return errnoBug(err),
13031 .SRCH => |err| return errnoBug(err),
13032 else => |err| return posix.unexpectedErrno(err),
13033 };
1305013034 _ = try childWaitPosix(t, child);
1305113035}
1305213036
......@@ -13063,6 +13047,7 @@ fn childCleanupStreams(child: *process.Child) void {
1306313047 posix.close(stderr.handle);
1306413048 child.stderr = null;
1306513049 }
13050 child.id = null;
1306613051}
1306713052
1306813053/// Errors that can occur between fork() and execv()
......@@ -14367,6 +14352,11 @@ fn progressParentFile(userdata: ?*anyopaque) std.Progress.ParentFileError!File {
1436714352 } };
1436814353}
1436914354
14355pub fn environString(t: *Threaded, comptime name: []const u8) ?[:0]const u8 {
14356 t.scanEnviron();
14357 return @field(t.environ.string, name);
14358}
14359
1437014360test {
1437114361 _ = @import("Threaded/test.zig");
1437214362}
lib/std/debug/ElfFile.zig+7-5
......@@ -66,16 +66,17 @@ pub const DebugInfoSearchPaths = struct {
6666 .exe_dir = null,
6767 };
6868
69 pub fn native(exe_path: []const u8, io: Io) DebugInfoSearchPaths {
70 return .{
69 pub fn native(exe_path: []const u8) DebugInfoSearchPaths {
70 if (std.options.elf_debug_info_search_paths) |f| return f(exe_path);
71 if (std.Options.debug_threaded_io) |t| return .{
7172 .debuginfod_client = p: {
72 if (io.environ("DEBUGINFOD_CACHE_PATH")) |p| {
73 if (t.environString("DEBUGINFOD_CACHE_PATH")) |p| {
7374 break :p .{ p, "" };
7475 }
75 if (io.environ("XDG_CACHE_HOME")) |cache_path| {
76 if (t.environString("XDG_CACHE_HOME")) |cache_path| {
7677 break :p .{ cache_path, "/debuginfod_client" };
7778 }
78 if (io.environ("HOME")) |home_path| {
79 if (t.environString("HOME")) |home_path| {
7980 break :p .{ home_path, "/.cache/debuginfod_client" };
8081 }
8182 break :p null;
......@@ -85,6 +86,7 @@ pub const DebugInfoSearchPaths = struct {
8586 },
8687 .exe_dir = std.fs.path.dirname(exe_path) orelse ".",
8788 };
89 @compileError("std.Options.elf_debug_info_search_paths must be provided");
8890 }
8991};
9092
lib/std/debug/SelfInfo/Elf.zig+2-2
......@@ -327,7 +327,7 @@ const Module = struct {
327327 const load_result = if (mod.name.len > 0) res: {
328328 var file = Io.Dir.cwd().openFile(io, mod.name, .{}) catch return error.MissingDebugInfo;
329329 defer file.close(io);
330 break :res std.debug.ElfFile.load(gpa, io, file, mod.build_id, &.native(mod.name, io));
330 break :res std.debug.ElfFile.load(gpa, io, file, mod.build_id, &.native(mod.name));
331331 } else res: {
332332 const path = std.process.executablePathAlloc(io, gpa) catch |err| switch (err) {
333333 error.OutOfMemory => |e| return e,
......@@ -336,7 +336,7 @@ const Module = struct {
336336 defer gpa.free(path);
337337 var file = Io.Dir.cwd().openFile(io, path, .{}) catch return error.MissingDebugInfo;
338338 defer file.close(io);
339 break :res std.debug.ElfFile.load(gpa, io, file, mod.build_id, &.native(path, io));
339 break :res std.debug.ElfFile.load(gpa, io, file, mod.build_id, &.native(path));
340340 };
341341
342342 var elf_file = load_result catch |err| switch (err) {
lib/std/process/Child.zig+1-1
......@@ -106,7 +106,7 @@ pub const Term = union(enum) {
106106///
107107/// Uncancelable. Ignores unexpected errors from the operating system.
108108pub fn kill(child: *Child, io: Io) void {
109 if (child.id != null) {
109 if (child.id == null) {
110110 assert(child.stdin == null);
111111 assert(child.stdout == null);
112112 assert(child.stderr == null);
lib/std/process/Environ.zig+2-2
......@@ -792,6 +792,6 @@ test "convert from Environ to Map and back again" {
792792 var map2 = try environ.createMap(gpa);
793793 defer map2.deinit();
794794
795 try testing.expectEqualSlices([]const u8, map.keys(), map2.keys());
796 try testing.expectEqualSlices([]const u8, map.values(), map2.values());
795 try testing.expectEqualDeep(map.keys(), map2.keys());
796 try testing.expectEqualDeep(map.values(), map2.values());
797797}
lib/std/std.zig+5
......@@ -173,6 +173,11 @@ pub const Options = struct {
173173 /// stack traces will just print an error to the relevant `Io.Writer` and return.
174174 allow_stack_tracing: bool = !@import("builtin").strip_debug_info,
175175
176 elf_debug_info_search_paths: ?fn (exe_path: []const u8) switch (@import("builtin").object_format) {
177 .elf => debug.ElfFile.DebugInfoSearchPaths,
178 else => void,
179 } = null,
180
176181 pub const debug_threaded_io: ?*Io.Threaded = if (@hasDecl(root, "std_options_debug_threaded_io"))
177182 root.std_options_debug_threaded_io
178183 else