authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-08-29 20:49:18-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-08-30 00:48:50-07:00
log9adcc31ca3dafa4799984ceb3409a85501417288
tree7ba7345c6a1d92d7e1eef2197c8759afac2c8e87
parentfadd268a609aefa155bbe5c7fe9d7c07956e9cda

update tools and other miscellaneous things to new APIs


20 files changed, 55 insertions(+), 53 deletions(-)

lib/compiler/resinator/main.zig+7-3
......@@ -164,13 +164,14 @@ pub fn main() !void {
164164 } else {
165165 switch (options.input_source) {
166166 .stdio => |file| {
167 break :full_input file.readToEndAlloc(allocator, std.math.maxInt(usize)) catch |err| {
167 var file_reader = file.reader(&.{});
168 break :full_input file_reader.interface.allocRemaining(allocator, .unlimited) catch |err| {
168169 try error_handler.emitMessage(allocator, .err, "unable to read input from stdin: {s}", .{@errorName(err)});
169170 std.process.exit(1);
170171 };
171172 },
172173 .filename => |input_filename| {
173 break :full_input std.fs.cwd().readFileAlloc(allocator, input_filename, std.math.maxInt(usize)) catch |err| {
174 break :full_input std.fs.cwd().readFileAlloc(input_filename, allocator, .unlimited) catch |err| {
174175 try error_handler.emitMessage(allocator, .err, "unable to read input file path '{s}': {s}", .{ input_filename, @errorName(err) });
175176 std.process.exit(1);
176177 };
......@@ -462,7 +463,10 @@ const IoStream = struct {
462463 pub fn readAll(self: Source, allocator: std.mem.Allocator) !Data {
463464 return switch (self) {
464465 inline .file, .stdio => |file| .{
465 .bytes = try file.readToEndAlloc(allocator, std.math.maxInt(usize)),
466 .bytes = b: {
467 var file_reader = file.reader(&.{});
468 break :b try file_reader.interface.allocRemaining(allocator, .unlimited);
469 },
466470 .needs_free = true,
467471 },
468472 .memory => |list| .{ .bytes = list.items, .needs_free = false },
test/src/check-stack-trace.zig+1-1
......@@ -13,7 +13,7 @@ pub fn main() !void {
1313 const input_path = args[1];
1414 const optimize_mode_text = args[2];
1515
16 const input_bytes = try std.fs.cwd().readFileAlloc(arena, input_path, 5 * 1024 * 1024);
16 const input_bytes = try std.fs.cwd().readFileAlloc(input_path, arena, .limited(5 * 1024 * 1024));
1717 const optimize_mode = std.meta.stringToEnum(std.builtin.OptimizeMode, optimize_mode_text).?;
1818
1919 var stderr = input_bytes;
test/standalone/child_process/main.zig+2-1
......@@ -32,7 +32,8 @@ pub fn main() !void {
3232
3333 const hello_stdout = "hello from stdout";
3434 var buf: [hello_stdout.len]u8 = undefined;
35 const n = try child.stdout.?.deprecatedReader().readAll(&buf);
35 var stdout_reader = child.stdout.?.reader(&.{});
36 const n = try stdout_reader.interface.readSliceShort(&buf);
3637 if (!std.mem.eql(u8, buf[0..n], hello_stdout)) {
3738 testError("child stdout: '{s}'; want '{s}'", .{ buf[0..n], hello_stdout });
3839 }
test/standalone/cmakedefine/check.zig+2-2
......@@ -9,8 +9,8 @@ pub fn main() !void {
99 const actual_path = args[1];
1010 const expected_path = args[2];
1111
12 const actual = try std.fs.cwd().readFileAlloc(arena, actual_path, 1024 * 1024);
13 const expected = try std.fs.cwd().readFileAlloc(arena, expected_path, 1024 * 1024);
12 const actual = try std.fs.cwd().readFileAlloc(actual_path, arena, .limited(1024 * 1024));
13 const expected = try std.fs.cwd().readFileAlloc(expected_path, arena, .limited(1024 * 1024));
1414
1515 // The actual output starts with a comment which we should strip out before comparing.
1616 const comment_str = "/* This file was generated by ConfigHeader using the Zig Build System. */\n";
test/standalone/entry_point/check_differ.zig+2-2
......@@ -6,8 +6,8 @@ pub fn main() !void {
66 const args = try std.process.argsAlloc(arena);
77 if (args.len != 3) return error.BadUsage; // usage: 'check_differ <path a> <path b>'
88
9 const contents_1 = try std.fs.cwd().readFileAlloc(arena, args[1], 1024 * 1024 * 64); // 64 MiB ought to be plenty
10 const contents_2 = try std.fs.cwd().readFileAlloc(arena, args[2], 1024 * 1024 * 64); // 64 MiB ought to be plenty
9 const contents_1 = try std.fs.cwd().readFileAlloc(args[1], arena, .limited(1024 * 1024 * 64)); // 64 MiB ought to be plenty
10 const contents_2 = try std.fs.cwd().readFileAlloc(args[2], arena, .limited(1024 * 1024 * 64)); // 64 MiB ought to be plenty
1111
1212 if (std.mem.eql(u8, contents_1, contents_2)) {
1313 return error.FilesMatch;
tools/docgen.zig+4-5
......@@ -77,7 +77,8 @@ pub fn main() !void {
7777 var code_dir = try fs.cwd().openDir(code_dir_path, .{});
7878 defer code_dir.close();
7979
80 const input_file_bytes = try in_file.deprecatedReader().readAllAlloc(arena, max_doc_file_size);
80 var in_file_reader = in_file.reader(&.{});
81 const input_file_bytes = try in_file_reader.interface.allocRemaining(arena, .limited(max_doc_file_size));
8182
8283 var tokenizer = Tokenizer.init(input_path, input_file_bytes);
8384 var toc = try genToc(arena, &tokenizer);
......@@ -1039,10 +1040,8 @@ fn genHtml(
10391040 });
10401041 defer allocator.free(out_basename);
10411042
1042 const contents = code_dir.readFileAlloc(allocator, out_basename, std.math.maxInt(u32)) catch |err| {
1043 return parseError(tokenizer, code.token, "unable to open '{s}': {s}", .{
1044 out_basename, @errorName(err),
1045 });
1043 const contents = code_dir.readFileAlloc(out_basename, allocator, .limited(std.math.maxInt(u32))) catch |err| {
1044 return parseError(tokenizer, code.token, "unable to open '{s}': {t}", .{ out_basename, err });
10461045 };
10471046 defer allocator.free(contents);
10481047
tools/doctest.zig+1-1
......@@ -70,7 +70,7 @@ pub fn main() !void {
7070 const zig_path = opt_zig orelse fatal("missing zig compiler path (--zig)", .{});
7171 const cache_root = opt_cache_root orelse fatal("missing cache root path (--cache-root)", .{});
7272
73 const source_bytes = try fs.cwd().readFileAlloc(arena, input_path, std.math.maxInt(u32));
73 const source_bytes = try fs.cwd().readFileAlloc(input_path, arena, .limited(std.math.maxInt(u32)));
7474 const code = try parseManifest(arena, source_bytes);
7575 const source = stripManifest(source_bytes);
7676
tools/dump-cov.zig+2-3
......@@ -38,10 +38,9 @@ pub fn main() !void {
3838 defer debug_info.deinit(gpa);
3939
4040 const cov_bytes = cov_path.root_dir.handle.readFileAllocOptions(
41 arena,
4241 cov_path.sub_path,
43 1 << 30,
44 null,
42 arena,
43 .limited(1 << 30),
4544 .of(SeenPcsHeader),
4645 null,
4746 ) catch |err| {
tools/fetch_them_macos_headers.zig+3-3
......@@ -1,6 +1,5 @@
11const std = @import("std");
22const fs = std.fs;
3const io = std.io;
43const mem = std.mem;
54const process = std.process;
65const assert = std.debug.assert;
......@@ -93,7 +92,7 @@ pub fn main() anyerror!void {
9392
9493 var sdk_dir = try std.fs.cwd().openDir(sysroot_path, .{});
9594 defer sdk_dir.close();
96 const sdk_info = try sdk_dir.readFileAlloc(allocator, "SDKSettings.json", std.math.maxInt(u32));
95 const sdk_info = try sdk_dir.readFileAlloc("SDKSettings.json", allocator, .limited(std.math.maxInt(u32)));
9796
9897 const parsed_json = try std.json.parseFromSlice(struct {
9998 DefaultProperties: struct { MACOSX_DEPLOYMENT_TARGET: []const u8 },
......@@ -198,7 +197,8 @@ fn fetchTarget(
198197 var dirs = std.StringHashMap(fs.Dir).init(arena);
199198 try dirs.putNoClobber(".", dest_dir);
200199
201 const headers_list_str = try headers_list_file.deprecatedReader().readAllAlloc(arena, std.math.maxInt(usize));
200 var headers_list_file_reader = headers_list_file.reader(&.{});
201 const headers_list_str = try headers_list_file_reader.interface.allocRemaining(arena, .unlimited);
202202 const prefix = "/usr/include";
203203
204204 var it = mem.splitScalar(u8, headers_list_str, '\n');
tools/gen_spirv_spec.zig+15-15
......@@ -136,7 +136,7 @@ fn readExtRegistry(exts: *std.array_list.Managed(Extension), dir: std.fs.Dir, su
136136}
137137
138138fn readRegistry(comptime RegistryType: type, dir: std.fs.Dir, path: []const u8) !RegistryType {
139 const spec = try dir.readFileAlloc(allocator, path, std.math.maxInt(usize));
139 const spec = try dir.readFileAlloc(path, allocator, .unlimited);
140140 // Required for json parsing.
141141 // TODO: ALI
142142 @setEvalBranchQuota(10000);
......@@ -189,7 +189,7 @@ fn tagPriorityScore(tag: []const u8) usize {
189189}
190190
191191fn render(
192 writer: *std.io.Writer,
192 writer: *std.Io.Writer,
193193 registry: CoreRegistry,
194194 extensions: []const Extension,
195195) !void {
......@@ -214,7 +214,7 @@ fn render(
214214 \\ none,
215215 \\ _,
216216 \\
217 \\ pub fn format(self: Id, writer: *std.io.Writer) std.io.Writer.Error!void {
217 \\ pub fn format(self: Id, writer: *std.Io.Writer) std.Io.Writer.Error!void {
218218 \\ switch (self) {
219219 \\ .none => try writer.writeAll("(none)"),
220220 \\ else => try writer.print("%{d}", .{@intFromEnum(self)}),
......@@ -327,7 +327,7 @@ fn render(
327327}
328328
329329fn renderInstructionSet(
330 writer: *std.io.Writer,
330 writer: *std.Io.Writer,
331331 core: CoreRegistry,
332332 extensions: []const Extension,
333333 all_operand_kinds: OperandKindMap,
......@@ -362,7 +362,7 @@ fn renderInstructionSet(
362362}
363363
364364fn renderInstructionsCase(
365 writer: *std.io.Writer,
365 writer: *std.Io.Writer,
366366 set_name: []const u8,
367367 instructions: []const Instruction,
368368 all_operand_kinds: OperandKindMap,
......@@ -409,7 +409,7 @@ fn renderInstructionsCase(
409409 );
410410}
411411
412fn renderClass(writer: *std.io.Writer, instructions: []const Instruction) !void {
412fn renderClass(writer: *std.Io.Writer, instructions: []const Instruction) !void {
413413 var class_map = std.StringArrayHashMap(void).init(allocator);
414414
415415 for (instructions) |inst| {
......@@ -427,7 +427,7 @@ fn renderClass(writer: *std.io.Writer, instructions: []const Instruction) !void
427427const Formatter = struct {
428428 data: []const u8,
429429
430 fn format(f: Formatter, writer: *std.Io.Writer) std.io.Writer.Error!void {
430 fn format(f: Formatter, writer: *std.Io.Writer) std.Io.Writer.Error!void {
431431 var id_buf: [128]u8 = undefined;
432432 var fw: std.Io.Writer = .fixed(&id_buf);
433433 for (f.data, 0..) |c, i| {
......@@ -457,7 +457,7 @@ fn formatId(identifier: []const u8) std.fmt.Alt(Formatter, Formatter.format) {
457457 return .{ .data = .{ .data = identifier } };
458458}
459459
460fn renderOperandKind(writer: *std.io.Writer, operands: []const OperandKind) !void {
460fn renderOperandKind(writer: *std.Io.Writer, operands: []const OperandKind) !void {
461461 try writer.writeAll(
462462 \\pub const OperandKind = enum {
463463 \\ opcode,
......@@ -513,7 +513,7 @@ fn renderOperandKind(writer: *std.io.Writer, operands: []const OperandKind) !voi
513513 try writer.writeAll("};\n}\n};\n");
514514}
515515
516fn renderEnumerant(writer: *std.io.Writer, enumerant: Enumerant) !void {
516fn renderEnumerant(writer: *std.Io.Writer, enumerant: Enumerant) !void {
517517 try writer.print(".{{.name = \"{s}\", .value = ", .{enumerant.enumerant});
518518 switch (enumerant.value) {
519519 .bitflag => |flag| try writer.writeAll(flag),
......@@ -530,7 +530,7 @@ fn renderEnumerant(writer: *std.io.Writer, enumerant: Enumerant) !void {
530530}
531531
532532fn renderOpcodes(
533 writer: *std.io.Writer,
533 writer: *std.Io.Writer,
534534 opcode_type_name: []const u8,
535535 want_operands: bool,
536536 instructions: []const Instruction,
......@@ -629,7 +629,7 @@ fn renderOpcodes(
629629}
630630
631631fn renderOperandKinds(
632 writer: *std.io.Writer,
632 writer: *std.Io.Writer,
633633 kinds: []const OperandKind,
634634 extended_structs: ExtendedStructSet,
635635) !void {
......@@ -643,7 +643,7 @@ fn renderOperandKinds(
643643}
644644
645645fn renderValueEnum(
646 writer: *std.io.Writer,
646 writer: *std.Io.Writer,
647647 enumeration: OperandKind,
648648 extended_structs: ExtendedStructSet,
649649) !void {
......@@ -721,7 +721,7 @@ fn renderValueEnum(
721721}
722722
723723fn renderBitEnum(
724 writer: *std.io.Writer,
724 writer: *std.Io.Writer,
725725 enumeration: OperandKind,
726726 extended_structs: ExtendedStructSet,
727727) !void {
......@@ -804,7 +804,7 @@ fn renderBitEnum(
804804}
805805
806806fn renderOperand(
807 writer: *std.io.Writer,
807 writer: *std.Io.Writer,
808808 kind: enum {
809809 @"union",
810810 instruction,
......@@ -888,7 +888,7 @@ fn renderOperand(
888888 try writer.writeAll(",\n");
889889}
890890
891fn renderFieldName(writer: *std.io.Writer, operands: []const Operand, field_index: usize) !void {
891fn renderFieldName(writer: *std.Io.Writer, operands: []const Operand, field_index: usize) !void {
892892 const operand = operands[field_index];
893893
894894 derive_from_kind: {
tools/gen_stubs.zig+2-3
......@@ -299,10 +299,9 @@ pub fn main() !void {
299299
300300 // Read the ELF header.
301301 const elf_bytes = build_all_dir.readFileAllocOptions(
302 arena,
303302 libc_so_path,
304 100 * 1024 * 1024,
305 1 * 1024 * 1024,
303 arena,
304 .limited(100 * 1024 * 1024),
306305 .of(elf.Elf64_Ehdr),
307306 null,
308307 ) catch |err| {
tools/generate_JSONTestSuite.zig+1-1
......@@ -32,7 +32,7 @@ pub fn main() !void {
3232 }).lessThan);
3333
3434 for (names.items) |name| {
35 const contents = try std.fs.cwd().readFileAlloc(allocator, name, 250001);
35 const contents = try std.fs.cwd().readFileAlloc(name, allocator, .limited(250001));
3636 try output.writeAll("test ");
3737 try writeString(output, name);
3838 try output.writeAll(" {\n try ");
tools/generate_linux_syscalls.zig+1-1
......@@ -248,7 +248,7 @@ pub fn main() !void {
248248 try Io.Writer.flush(stdout);
249249}
250250
251fn usage(w: *std.io.Writer, arg0: []const u8) std.io.Writer.Error!void {
251fn usage(w: *std.Io.Writer, arg0: []const u8) std.Io.Writer.Error!void {
252252 try w.print(
253253 \\Usage: {s} /path/to/zig /path/to/linux
254254 \\Alternative Usage: zig run /path/to/git/zig/tools/generate_linux_syscalls.zig -- /path/to/zig /path/to/linux
tools/incr-check.zig+2-2
......@@ -52,7 +52,7 @@ pub fn main() !void {
5252 const zig_exe = opt_zig_exe orelse fatal("missing path to zig\n{s}", .{usage});
5353 const input_file_name = opt_input_file_name orelse fatal("missing input file\n{s}", .{usage});
5454
55 const input_file_bytes = try std.fs.cwd().readFileAlloc(arena, input_file_name, std.math.maxInt(u32));
55 const input_file_bytes = try std.fs.cwd().readFileAlloc(input_file_name, arena, .limited(std.math.maxInt(u32)));
5656 const case = try Case.parse(arena, input_file_bytes);
5757
5858 // Check now: if there are any targets using the `cbe` backend, we need the lib dir.
......@@ -226,7 +226,7 @@ const Eval = struct {
226226 cc_child_args: *std.ArrayListUnmanaged([]const u8),
227227
228228 const StreamEnum = enum { stdout, stderr };
229 const Poller = std.io.Poller(StreamEnum);
229 const Poller = std.Io.Poller(StreamEnum);
230230
231231 /// Currently this function assumes the previous updates have already been written.
232232 fn write(eval: *Eval, update: Case.Update) void {
tools/migrate_langref.zig+2-2
......@@ -1,6 +1,5 @@
11const std = @import("std");
22const builtin = @import("builtin");
3const io = std.io;
43const fs = std.fs;
54const print = std.debug.print;
65const mem = std.mem;
......@@ -29,7 +28,8 @@ pub fn main() !void {
2928 var out_dir = try fs.cwd().openDir(fs.path.dirname(output_file).?, .{});
3029 defer out_dir.close();
3130
32 const input_file_bytes = try in_file.deprecatedReader().readAllAlloc(arena, std.math.maxInt(u32));
31 var in_file_reader = in_file.reader(&.{});
32 const input_file_bytes = try in_file_reader.interface.allocRemaining(arena, .unlimited);
3333
3434 var tokenizer = Tokenizer.init(input_file, input_file_bytes);
3535
tools/process_headers.zig+1-1
......@@ -254,7 +254,7 @@ pub fn main() !void {
254254 .file, .sym_link => {
255255 const rel_path = try std.fs.path.relative(allocator, target_include_dir, full_path);
256256 const max_size = 2 * 1024 * 1024 * 1024;
257 const raw_bytes = try std.fs.cwd().readFileAlloc(allocator, full_path, max_size);
257 const raw_bytes = try std.fs.cwd().readFileAlloc(full_path, allocator, .limited(max_size));
258258 const trimmed = std.mem.trim(u8, raw_bytes, " \r\n\t");
259259 total_bytes += raw_bytes.len;
260260 const hash = try allocator.alloc(u8, 32);
tools/update-linux-headers.zig+1-1
......@@ -206,7 +206,7 @@ pub fn main() !void {
206206 .file => {
207207 const rel_path = try std.fs.path.relative(arena, target_include_dir, full_path);
208208 const max_size = 2 * 1024 * 1024 * 1024;
209 const raw_bytes = try std.fs.cwd().readFileAlloc(arena, full_path, max_size);
209 const raw_bytes = try std.fs.cwd().readFileAlloc(full_path, arena, .limited(max_size));
210210 const trimmed = std.mem.trim(u8, raw_bytes, " \r\n\t");
211211 total_bytes += raw_bytes.len;
212212 const hash = try arena.alloc(u8, 32);
tools/update_clang_options.zig+1-1
......@@ -965,7 +965,7 @@ fn printUsageAndExit(arg0: []const u8) noreturn {
965965 std.process.exit(1);
966966}
967967
968fn printUsage(w: *std.io.Writer, arg0: []const u8) std.io.Writer.Error!void {
968fn printUsage(w: *std.Io.Writer, arg0: []const u8) std.Io.Writer.Error!void {
969969 try w.print(
970970 \\Usage: {s} /path/to/llvm-tblgen /path/to/git/llvm/llvm-project
971971 \\Alternative Usage: zig run /path/to/git/zig/tools/update_clang_options.zig -- /path/to/llvm-tblgen /path/to/git/llvm/llvm-project
tools/update_crc_catalog.zig+1-1
......@@ -194,7 +194,7 @@ fn printUsageAndExit(arg0: []const u8) noreturn {
194194 std.process.exit(1);
195195}
196196
197fn printUsage(w: *std.io.Writer, arg0: []const u8) std.io.Writer.Error!void {
197fn printUsage(w: *std.Io.Writer, arg0: []const u8) std.Io.Writer.Error!void {
198198 return w.print(
199199 \\Usage: {s} /path/git/zig
200200 \\
tools/update_glibc.zig+4-4
......@@ -116,9 +116,9 @@ pub fn main() !void {
116116 const max_file_size = 10 * 1024 * 1024;
117117
118118 const generic_glibc_contents = generic_glibc_dir.readFileAlloc(
119 arena,
120119 entry.path,
121 max_file_size,
120 arena,
121 .limited(max_file_size),
122122 ) catch |err| switch (err) {
123123 error.FileNotFound => continue,
124124 else => |e| fatal("unable to load '{s}/include/{s}': {s}", .{
......@@ -126,9 +126,9 @@ pub fn main() !void {
126126 }),
127127 };
128128 const glibc_include_contents = include_dir.readFileAlloc(
129 arena,
130129 entry.path,
131 max_file_size,
130 arena,
131 .limited(max_file_size),
132132 ) catch |err| {
133133 fatal("unable to load '{s}/include/{s}': {s}", .{
134134 dest_dir_path, entry.path, @errorName(err),