authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-22 18:49:10-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-23 22:15:12-08:00
log691afee786d095fef2a7abed73efa035feef3f4e
treed8bf25bd5d2c833bd0b277d16228dec4eb6670fd
parent33e302d67a80fe7d213b4c461dc41c91813db869

langref: fix build failure


6 files changed, 61 insertions(+), 50 deletions(-)

doc/langref/bad_default_value.zig+1-1
......@@ -17,7 +17,7 @@ pub fn main() !void {
1717 .maximum = 0.20,
1818 };
1919 const category = threshold.categorize(0.90);
20 try std.fs.File.stdout().writeAll(@tagName(category));
20 std.log.info("category: {t}", .{category});
2121}
2222
2323const std = @import("std");
doc/langref/hello.zig+11-1
......@@ -1,7 +1,17 @@
11const std = @import("std");
22
3// See https://github.com/ziglang/zig/issues/24510
4// for the plan to simplify this code.
35pub fn main() !void {
4 try std.fs.File.stdout().writeAll("Hello, World!\n");
6 var debug_allocator: std.heap.DebugAllocator(.{}) = .init;
7 defer _ = debug_allocator.deinit();
8 const gpa = debug_allocator.allocator();
9
10 var threaded: std.Io.Threaded = .init(gpa, .{});
11 defer threaded.deinit();
12 const io = threaded.io();
13
14 try std.Io.File.stdout().writeStreamingAll(io, "Hello, World!\n");
515}
616
717// exe=succeed
lib/compiler/aro/aro/Compilation.zig+2-1
......@@ -1713,7 +1713,8 @@ pub fn initSearchPath(comp: *Compilation, includes: []const Include, verbose: bo
17131713 }
17141714}
17151715fn addToSearchPath(comp: *Compilation, include: Include, verbose: bool) !void {
1716 comp.cwd.access(include.path, .{}) catch {
1716 const io = comp.io;
1717 comp.cwd.access(io, include.path, .{}) catch {
17171718 if (verbose) {
17181719 std.debug.print("ignoring nonexistent directory \"{s}\"\n", .{include.path});
17191720 return;
lib/compiler/translate-c/main.zig+9-6
......@@ -34,11 +34,14 @@ pub fn main() u8 {
3434 zig_integration = true;
3535 }
3636
37 const NO_COLOR = std.zig.EnvVar.NO_COLOR.isSet();
38 const CLICOLOR_FORCE = std.zig.EnvVar.CLICOLOR_FORCE.isSet();
39
3740 var stderr_buf: [1024]u8 = undefined;
3841 var stderr = Io.File.stderr().writer(io, &stderr_buf);
3942 var diagnostics: aro.Diagnostics = switch (zig_integration) {
4043 false => .{ .output = .{ .to_writer = .{
41 .color = .detect(stderr.file),
44 .mode = Io.Terminal.Mode.detect(io, stderr.file, NO_COLOR, CLICOLOR_FORCE) catch unreachable,
4245 .writer = &stderr.interface,
4346 } } },
4447 true => .{ .output = .{ .to_list = .{
......@@ -69,7 +72,7 @@ pub fn main() u8 {
6972 return 1;
7073 },
7174 error.FatalError => if (zig_integration) {
72 serveErrorBundle(arena, &diagnostics) catch |bundle_err| {
75 serveErrorBundle(arena, io, &diagnostics) catch |bundle_err| {
7376 std.debug.print("unable to serve error bundle: {}\n", .{bundle_err});
7477 if (fast_exit) process.exit(1);
7578 return 1;
......@@ -93,14 +96,14 @@ pub fn main() u8 {
9396 return @intFromBool(comp.diagnostics.errors != 0);
9497}
9598
96fn serveErrorBundle(arena: std.mem.Allocator, diagnostics: *const aro.Diagnostics) !void {
99fn serveErrorBundle(arena: std.mem.Allocator, io: Io, diagnostics: *const aro.Diagnostics) !void {
97100 const error_bundle = try compiler_util.aroDiagnosticsToErrorBundle(
98101 diagnostics,
99102 arena,
100103 "translation failure",
101104 );
102105 var stdout_buffer: [1024]u8 = undefined;
103 var stdout_writer = Io.File.stdout().writer(&stdout_buffer);
106 var stdout_writer = Io.File.stdout().writer(io, &stdout_buffer);
104107 var server: std.zig.Server = .{
105108 .out = &stdout_writer.interface,
106109 .in = undefined,
......@@ -130,13 +133,13 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: [][:0]u8, zig_integration
130133 args[i] = arg;
131134 if (mem.eql(u8, arg, "--help")) {
132135 var stdout_buf: [512]u8 = undefined;
133 var stdout = Io.File.stdout().writer(&stdout_buf);
136 var stdout = Io.File.stdout().writer(io, &stdout_buf);
134137 try stdout.interface.print(usage, .{args[0]});
135138 try stdout.interface.flush();
136139 return;
137140 } else if (mem.eql(u8, arg, "--version")) {
138141 var stdout_buf: [512]u8 = undefined;
139 var stdout = Io.File.stdout().writer(&stdout_buf);
142 var stdout = Io.File.stdout().writer(io, &stdout_buf);
140143 // TODO add version
141144 try stdout.interface.writeAll("0.0.0-dev\n");
142145 try stdout.interface.flush();
tools/docgen.zig+14-12
......@@ -1,6 +1,8 @@
1const std = @import("std");
21const builtin = @import("builtin");
3const fs = std.fs;
2
3const std = @import("std");
4const Io = std.Io;
5const Dir = std.Io.Dir;
46const process = std.process;
57const Progress = std.Progress;
68const print = std.debug.print;
......@@ -8,7 +10,6 @@ const mem = std.mem;
810const testing = std.testing;
911const Allocator = std.mem.Allocator;
1012const ArrayList = std.ArrayList;
11const getExternalExecutor = std.zig.system.getExternalExecutor;
1213const fatal = std.process.fatal;
1314const Writer = std.Io.Writer;
1415
......@@ -49,7 +50,7 @@ pub fn main() !void {
4950 while (args_it.next()) |arg| {
5051 if (mem.startsWith(u8, arg, "-")) {
5152 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
52 try fs.File.stdout().writeAll(usage);
53 try Io.File.stdout().writeStreamingAll(io, usage);
5354 process.exit(0);
5455 } else if (mem.eql(u8, arg, "--code-dir")) {
5556 if (args_it.next()) |param| {
......@@ -72,15 +73,15 @@ pub fn main() !void {
7273 const output_path = opt_output orelse fatal("missing output file", .{});
7374 const code_dir_path = opt_code_dir orelse fatal("missing --code-dir argument", .{});
7475
75 var in_file = try fs.cwd().openFile(input_path, .{});
76 var in_file = try Dir.cwd().openFile(io, input_path, .{});
7677 defer in_file.close(io);
7778
78 var out_file = try fs.cwd().createFile(output_path, .{});
79 var out_file = try Dir.cwd().createFile(io, output_path, .{});
7980 defer out_file.close(io);
8081 var out_file_buffer: [4096]u8 = undefined;
81 var out_file_writer = out_file.writer(&out_file_buffer);
82 var out_file_writer = out_file.writer(io, &out_file_buffer);
8283
83 var code_dir = try fs.cwd().openDir(code_dir_path, .{});
84 var code_dir = try Dir.cwd().openDir(io, code_dir_path, .{});
8485 defer code_dir.close(io);
8586
8687 var in_file_reader = in_file.reader(io, &.{});
......@@ -89,7 +90,7 @@ pub fn main() !void {
8990 var tokenizer = Tokenizer.init(input_path, input_file_bytes);
9091 var toc = try genToc(arena, &tokenizer);
9192
92 try genHtml(arena, &tokenizer, &toc, code_dir, &out_file_writer.interface);
93 try genHtml(arena, io, &tokenizer, &toc, code_dir, &out_file_writer.interface);
9394 try out_file_writer.end();
9495}
9596
......@@ -988,9 +989,10 @@ fn printShell(out: *Writer, shell_content: []const u8, escape: bool) !void {
988989
989990fn genHtml(
990991 allocator: Allocator,
992 io: Io,
991993 tokenizer: *Tokenizer,
992994 toc: *Toc,
993 code_dir: std.fs.Dir,
995 code_dir: Dir,
994996 out: *Writer,
995997) !void {
996998 for (toc.nodes) |node| {
......@@ -1042,11 +1044,11 @@ fn genHtml(
10421044 },
10431045 .Code => |code| {
10441046 const out_basename = try std.fmt.allocPrint(allocator, "{s}.out", .{
1045 fs.path.stem(code.name),
1047 Dir.path.stem(code.name),
10461048 });
10471049 defer allocator.free(out_basename);
10481050
1049 const contents = code_dir.readFileAlloc(out_basename, allocator, .limited(std.math.maxInt(u32))) catch |err| {
1051 const contents = code_dir.readFileAlloc(io, out_basename, allocator, .limited(std.math.maxInt(u32))) catch |err| {
10501052 return parseError(tokenizer, code.token, "unable to open '{s}': {t}", .{ out_basename, err });
10511053 };
10521054 defer allocator.free(contents);
tools/doctest.zig+24-29
......@@ -2,10 +2,10 @@ const builtin = @import("builtin");
22
33const std = @import("std");
44const Io = std.Io;
5const Dir = std.Io.Dir;
56const Writer = std.Io.Writer;
67const fatal = std.process.fatal;
78const mem = std.mem;
8const fs = std.fs;
99const process = std.process;
1010const Allocator = std.mem.Allocator;
1111const testing = std.testing;
......@@ -53,7 +53,7 @@ pub fn main() !void {
5353 while (args_it.next()) |arg| {
5454 if (mem.startsWith(u8, arg, "-")) {
5555 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
56 try std.fs.File.stdout().writeAll(usage);
56 try Io.File.stdout().writeStreamingAll(io, usage);
5757 process.exit(0);
5858 } else if (mem.eql(u8, arg, "-i")) {
5959 opt_input = args_it.next() orelse fatal("expected parameter after -i", .{});
......@@ -78,37 +78,37 @@ pub fn main() !void {
7878 const zig_path = opt_zig orelse fatal("missing zig compiler path (--zig)", .{});
7979 const cache_root = opt_cache_root orelse fatal("missing cache root path (--cache-root)", .{});
8080
81 const source_bytes = try fs.cwd().readFileAlloc(input_path, arena, .limited(std.math.maxInt(u32)));
81 const source_bytes = try Dir.cwd().readFileAlloc(io, input_path, arena, .limited(std.math.maxInt(u32)));
8282 const code = try parseManifest(arena, source_bytes);
8383 const source = stripManifest(source_bytes);
8484
8585 const tmp_dir_path = try std.fmt.allocPrint(arena, "{s}/tmp/{x}", .{
8686 cache_root, std.crypto.random.int(u64),
8787 });
88 fs.cwd().createDirPath(io, tmp_dir_path) catch |err|
88 Dir.cwd().createDirPath(io, tmp_dir_path) catch |err|
8989 fatal("unable to create tmp dir '{s}': {t}", .{ tmp_dir_path, err });
90 defer fs.cwd().deleteTree(io, tmp_dir_path) catch |err| std.log.err("unable to delete '{s}': {t}", .{
90 defer Dir.cwd().deleteTree(io, tmp_dir_path) catch |err| std.log.err("unable to delete '{s}': {t}", .{
9191 tmp_dir_path, err,
9292 });
9393
94 var out_file = try fs.cwd().createFile(io, output_path, .{});
94 var out_file = try Dir.cwd().createFile(io, output_path, .{});
9595 defer out_file.close(io);
9696 var out_file_buffer: [4096]u8 = undefined;
9797 var out_file_writer = out_file.writer(io, &out_file_buffer);
9898
9999 const out = &out_file_writer.interface;
100100
101 try printSourceBlock(arena, out, source, fs.path.basename(input_path));
101 try printSourceBlock(arena, out, source, Dir.path.basename(input_path));
102102 try printOutput(
103103 arena,
104104 io,
105105 out,
106106 code,
107107 tmp_dir_path,
108 try std.fs.path.relative(arena, tmp_dir_path, zig_path),
109 try std.fs.path.relative(arena, tmp_dir_path, input_path),
108 try Dir.path.relative(arena, tmp_dir_path, zig_path),
109 try Dir.path.relative(arena, tmp_dir_path, input_path),
110110 if (opt_zig_lib_dir) |zig_lib_dir|
111 try std.fs.path.relative(arena, tmp_dir_path, zig_lib_dir)
111 try Dir.path.relative(arena, tmp_dir_path, zig_lib_dir)
112112 else
113113 null,
114114 );
......@@ -141,7 +141,7 @@ fn printOutput(
141141 defer shell_buffer.deinit();
142142 const shell_out = &shell_buffer.writer;
143143
144 const code_name = std.fs.path.stem(input_path);
144 const code_name = Dir.path.stem(input_path);
145145
146146 switch (code.id) {
147147 .exe => |expected_outcome| code_block: {
......@@ -201,8 +201,7 @@ fn printOutput(
201201 try shell_out.print("\n", .{});
202202
203203 if (expected_outcome == .build_fail) {
204 const result = try process.Child.run(.{
205 .allocator = arena,
204 const result = try process.Child.run(arena, io, .{
206205 .argv = build_args.items,
207206 .cwd = tmp_dir_path,
208207 .env_map = &env_map,
......@@ -227,7 +226,7 @@ fn printOutput(
227226 try shell_out.writeAll(colored_stderr);
228227 break :code_block;
229228 }
230 const exec_result = run(arena, &env_map, tmp_dir_path, build_args.items) catch
229 const exec_result = run(arena, io, &env_map, tmp_dir_path, build_args.items) catch
231230 fatal("example failed to compile", .{});
232231
233232 if (code.verbose_cimport) {
......@@ -258,8 +257,7 @@ fn printOutput(
258257 var exited_with_signal = false;
259258
260259 const result = if (expected_outcome == .fail) blk: {
261 const result = try process.Child.run(.{
262 .allocator = arena,
260 const result = try process.Child.run(arena, io, .{
263261 .argv = run_args,
264262 .env_map = &env_map,
265263 .cwd = tmp_dir_path,
......@@ -278,7 +276,7 @@ fn printOutput(
278276 }
279277 break :blk result;
280278 } else blk: {
281 break :blk run(arena, &env_map, tmp_dir_path, run_args) catch
279 break :blk run(arena, io, &env_map, tmp_dir_path, run_args) catch
282280 fatal("example crashed", .{});
283281 };
284282
......@@ -327,7 +325,7 @@ fn printOutput(
327325 .arch_os_abi = triple,
328326 });
329327 const target = try std.zig.system.resolveTargetQuery(io, target_query);
330 switch (getExternalExecutor(&host, &target, .{
328 switch (getExternalExecutor(io, &host, &target, .{
331329 .link_libc = code.link_libc,
332330 })) {
333331 .native => {},
......@@ -347,7 +345,7 @@ fn printOutput(
347345 }
348346 }
349347
350 const result = run(arena, &env_map, tmp_dir_path, test_args.items) catch
348 const result = run(arena, io, &env_map, tmp_dir_path, test_args.items) catch
351349 fatal("test failed", .{});
352350 const escaped_stderr = try escapeHtml(arena, result.stderr);
353351 const escaped_stdout = try escapeHtml(arena, result.stdout);
......@@ -378,8 +376,7 @@ fn printOutput(
378376 try test_args.append("-lc");
379377 try shell_out.print("-lc ", .{});
380378 }
381 const result = try process.Child.run(.{
382 .allocator = arena,
379 const result = try process.Child.run(arena, io, .{
383380 .argv = test_args.items,
384381 .env_map = &env_map,
385382 .cwd = tmp_dir_path,
......@@ -435,8 +432,7 @@ fn printOutput(
435432 },
436433 }
437434
438 const result = try process.Child.run(.{
439 .allocator = arena,
435 const result = try process.Child.run(arena, io, .{
440436 .argv = test_args.items,
441437 .env_map = &env_map,
442438 .cwd = tmp_dir_path,
......@@ -512,8 +508,7 @@ fn printOutput(
512508 }
513509
514510 if (maybe_error_match) |error_match| {
515 const result = try process.Child.run(.{
516 .allocator = arena,
511 const result = try process.Child.run(arena, io, .{
517512 .argv = build_args.items,
518513 .env_map = &env_map,
519514 .cwd = tmp_dir_path,
......@@ -541,7 +536,7 @@ fn printOutput(
541536 const colored_stderr = try termColor(arena, escaped_stderr);
542537 try shell_out.print("\n{s} ", .{colored_stderr});
543538 } else {
544 _ = run(arena, &env_map, tmp_dir_path, build_args.items) catch fatal("example failed to compile", .{});
539 _ = run(arena, io, &env_map, tmp_dir_path, build_args.items) catch fatal("example failed to compile", .{});
545540 }
546541 try shell_out.writeAll("\n");
547542 },
......@@ -600,7 +595,7 @@ fn printOutput(
600595 try test_args.append(option);
601596 try shell_out.print("{s} ", .{option});
602597 }
603 const result = run(arena, &env_map, tmp_dir_path, test_args.items) catch fatal("test failed", .{});
598 const result = run(arena, io, &env_map, tmp_dir_path, test_args.items) catch fatal("test failed", .{});
604599 const escaped_stderr = try escapeHtml(arena, result.stderr);
605600 const escaped_stdout = try escapeHtml(arena, result.stdout);
606601 try shell_out.print("\n{s}{s}\n", .{ escaped_stderr, escaped_stdout });
......@@ -1132,12 +1127,12 @@ fn in(slice: []const u8, number: u8) bool {
11321127
11331128fn run(
11341129 allocator: Allocator,
1130 io: Io,
11351131 env_map: *process.EnvMap,
11361132 cwd: []const u8,
11371133 args: []const []const u8,
11381134) !process.Child.RunResult {
1139 const result = try process.Child.run(.{
1140 .allocator = allocator,
1135 const result = try process.Child.run(allocator, io, .{
11411136 .argv = args,
11421137 .env_map = env_map,
11431138 .cwd = cwd,