diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2025-06-28 06:59:11 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2025-07-07 22:43:51 -0700 |
| commit | 0b3f0124dc33403d329fb8ee63a93215d9af1f1e (patch) | |
| tree | 3a94c321398ab21810b73c55411523d005b503fa /lib/compiler | |
| parent | 7c42517151cf06b67268aec3be715b3e303e014a (diff) | |
| download | zig-0b3f0124dc33403d329fb8ee63a93215d9af1f1e.tar.gz zig-0b3f0124dc33403d329fb8ee63a93215d9af1f1e.zip | |
std.io: move getStdIn, getStdOut, getStdErr functions to fs.File
preparing to rearrange std.io namespace into an interface
how to upgrade:
std.io.getStdIn() -> std.fs.File.stdin()
std.io.getStdOut() -> std.fs.File.stdout()
std.io.getStdErr() -> std.fs.File.stderr()
Diffstat (limited to 'lib/compiler')
| -rw-r--r-- | lib/compiler/aro/aro/Diagnostics.zig | 2 | ||||
| -rw-r--r-- | lib/compiler/aro/aro/Driver.zig | 14 | ||||
| -rw-r--r-- | lib/compiler/aro/aro/Preprocessor.zig | 2 | ||||
| -rw-r--r-- | lib/compiler/aro_translate_c.zig | 4 | ||||
| -rw-r--r-- | lib/compiler/build_runner.zig | 4 | ||||
| -rw-r--r-- | lib/compiler/libc.zig | 6 | ||||
| -rw-r--r-- | lib/compiler/objcopy.zig | 6 | ||||
| -rw-r--r-- | lib/compiler/reduce.zig | 2 | ||||
| -rw-r--r-- | lib/compiler/resinator/cli.zig | 2 | ||||
| -rw-r--r-- | lib/compiler/resinator/errors.zig | 4 | ||||
| -rw-r--r-- | lib/compiler/resinator/main.zig | 12 | ||||
| -rw-r--r-- | lib/compiler/std-docs.zig | 4 | ||||
| -rw-r--r-- | lib/compiler/test_runner.zig | 8 |
13 files changed, 35 insertions, 35 deletions
diff --git a/lib/compiler/aro/aro/Diagnostics.zig b/lib/compiler/aro/aro/Diagnostics.zig index eb3bb31ee8..f3ae4be38a 100644 --- a/lib/compiler/aro/aro/Diagnostics.zig +++ b/lib/compiler/aro/aro/Diagnostics.zig @@ -541,7 +541,7 @@ const MsgWriter = struct { fn init(config: std.io.tty.Config) MsgWriter { std.debug.lockStdErr(); return .{ - .w = std.io.bufferedWriter(std.io.getStdErr().writer()), + .w = std.io.bufferedWriter(std.fs.File.stderr().writer()), .config = config, }; } diff --git a/lib/compiler/aro/aro/Driver.zig b/lib/compiler/aro/aro/Driver.zig index c89dafe002..91bf06573a 100644 --- a/lib/compiler/aro/aro/Driver.zig +++ b/lib/compiler/aro/aro/Driver.zig @@ -519,7 +519,7 @@ fn option(arg: []const u8, name: []const u8) ?[]const u8 { fn addSource(d: *Driver, path: []const u8) !Source { if (mem.eql(u8, "-", path)) { - const stdin = std.io.getStdIn().reader(); + const stdin = std.fs.File.stdin().reader(); const input = try stdin.readAllAlloc(d.comp.gpa, std.math.maxInt(u32)); defer d.comp.gpa.free(input); return d.comp.addSourceFromBuffer("<stdin>", input); @@ -541,7 +541,7 @@ pub fn fatal(d: *Driver, comptime fmt: []const u8, args: anytype) error{ FatalEr } pub fn renderErrors(d: *Driver) void { - Diagnostics.render(d.comp, d.detectConfig(std.io.getStdErr())); + Diagnostics.render(d.comp, d.detectConfig(std.fs.File.stderr())); } pub fn detectConfig(d: *Driver, file: std.fs.File) std.io.tty.Config { @@ -591,7 +591,7 @@ pub fn main(d: *Driver, tc: *Toolchain, args: []const []const u8, comptime fast_ var macro_buf = std.ArrayList(u8).init(d.comp.gpa); defer macro_buf.deinit(); - const std_out = std.io.getStdOut().writer(); + const std_out = std.fs.File.stdout().writer(); if (try parseArgs(d, std_out, macro_buf.writer(), args)) return; const linking = !(d.only_preprocess or d.only_syntax or d.only_compile or d.only_preprocess_and_compile); @@ -686,7 +686,7 @@ fn processSource( std.fs.cwd().createFile(some, .{}) catch |er| return d.fatal("unable to create output file '{s}': {s}", .{ some, errorDescription(er) }) else - std.io.getStdOut(); + std.fs.File.stdout(); defer if (d.output_name != null) file.close(); var buf_w = std.io.bufferedWriter(file.writer()); @@ -704,7 +704,7 @@ fn processSource( defer tree.deinit(); if (d.verbose_ast) { - const stdout = std.io.getStdOut(); + const stdout = std.fs.File.stdout(); var buf_writer = std.io.bufferedWriter(stdout.writer()); tree.dump(d.detectConfig(stdout), buf_writer.writer()) catch {}; buf_writer.flush() catch {}; @@ -734,7 +734,7 @@ fn processSource( defer ir.deinit(d.comp.gpa); if (d.verbose_ir) { - const stdout = std.io.getStdOut(); + const stdout = std.fs.File.stdout(); var buf_writer = std.io.bufferedWriter(stdout.writer()); ir.dump(d.comp.gpa, d.detectConfig(stdout), buf_writer.writer()) catch {}; buf_writer.flush() catch {}; @@ -806,7 +806,7 @@ fn processSource( } fn dumpLinkerArgs(items: []const []const u8) !void { - const stdout = std.io.getStdOut().writer(); + const stdout = std.fs.File.stdout().writer(); for (items, 0..) |item, i| { if (i > 0) try stdout.writeByte(' '); try stdout.print("\"{}\"", .{std.zig.fmtEscapes(item)}); diff --git a/lib/compiler/aro/aro/Preprocessor.zig b/lib/compiler/aro/aro/Preprocessor.zig index e45f6eabc6..220ca4f7dd 100644 --- a/lib/compiler/aro/aro/Preprocessor.zig +++ b/lib/compiler/aro/aro/Preprocessor.zig @@ -811,7 +811,7 @@ fn verboseLog(pp: *Preprocessor, raw: RawToken, comptime fmt: []const u8, args: const source = pp.comp.getSource(raw.source); const line_col = source.lineCol(.{ .id = raw.source, .line = raw.line, .byte_offset = raw.start }); - const stderr = std.io.getStdErr().writer(); + const stderr = std.fs.File.stderr().writer(); var buf_writer = std.io.bufferedWriter(stderr); const writer = buf_writer.writer(); defer buf_writer.flush() catch {}; diff --git a/lib/compiler/aro_translate_c.zig b/lib/compiler/aro_translate_c.zig index e064cfa345..8d3bbbd84b 100644 --- a/lib/compiler/aro_translate_c.zig +++ b/lib/compiler/aro_translate_c.zig @@ -1781,7 +1781,7 @@ test "Macro matching" { fn renderErrorsAndExit(comp: *aro.Compilation) noreturn { defer std.process.exit(1); - var writer = aro.Diagnostics.defaultMsgWriter(std.io.tty.detectConfig(std.io.getStdErr())); + var writer = aro.Diagnostics.defaultMsgWriter(std.io.tty.detectConfig(std.fs.File.stderr())); defer writer.deinit(); // writer deinit must run *before* exit so that stderr is flushed var saw_error = false; @@ -1824,6 +1824,6 @@ pub fn main() !void { defer tree.deinit(gpa); const formatted = try tree.render(arena); - try std.io.getStdOut().writeAll(formatted); + try std.fs.File.stdout().writeAll(formatted); return std.process.cleanExit(); } diff --git a/lib/compiler/build_runner.zig b/lib/compiler/build_runner.zig index d73fb6d29d..c2ecea1cf4 100644 --- a/lib/compiler/build_runner.zig +++ b/lib/compiler/build_runner.zig @@ -330,7 +330,7 @@ pub fn main() !void { } } - const stderr = std.io.getStdErr(); + const stderr = std.fs.File.stderr(); const ttyconf = get_tty_conf(color, stderr); switch (ttyconf) { .no_color => try graph.env_map.put("NO_COLOR", "1"), @@ -378,7 +378,7 @@ pub fn main() !void { validateSystemLibraryOptions(builder); - const stdout_writer = io.getStdOut().writer(); + const stdout_writer = std.fs.File.stdout().writer(); if (help_menu) return usage(builder, stdout_writer); diff --git a/lib/compiler/libc.zig b/lib/compiler/libc.zig index 2f4c26b0cc..6bd47d15ea 100644 --- a/lib/compiler/libc.zig +++ b/lib/compiler/libc.zig @@ -40,7 +40,7 @@ pub fn main() !void { const arg = args[i]; if (mem.startsWith(u8, arg, "-")) { if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) { - const stdout = std.io.getStdOut().writer(); + const stdout = std.fs.File.stdout().writer(); try stdout.writeAll(usage_libc); return std.process.cleanExit(); } else if (mem.eql(u8, arg, "-target")) { @@ -97,7 +97,7 @@ pub fn main() !void { fatal("no include dirs detected for target {s}", .{zig_target}); } - var bw = std.io.bufferedWriter(std.io.getStdOut().writer()); + var bw = std.io.bufferedWriter(std.fs.File.stdout().writer()); var writer = bw.writer(); for (libc_dirs.libc_include_dir_list) |include_dir| { try writer.writeAll(include_dir); @@ -125,7 +125,7 @@ pub fn main() !void { }; defer libc.deinit(gpa); - var bw = std.io.bufferedWriter(std.io.getStdOut().writer()); + var bw = std.io.bufferedWriter(std.fs.File.stdout().writer()); try libc.render(bw.writer()); try bw.flush(); } diff --git a/lib/compiler/objcopy.zig b/lib/compiler/objcopy.zig index bcd3a69a0c..0c256c9796 100644 --- a/lib/compiler/objcopy.zig +++ b/lib/compiler/objcopy.zig @@ -54,7 +54,7 @@ fn cmdObjCopy( fatal("unexpected positional argument: '{s}'", .{arg}); } } else if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) { - return std.io.getStdOut().writeAll(usage); + return std.fs.File.stdout().writeAll(usage); } else if (mem.eql(u8, arg, "-O") or mem.eql(u8, arg, "--output-target")) { i += 1; if (i >= args.len) fatal("expected another argument after '{s}'", .{arg}); @@ -227,8 +227,8 @@ fn cmdObjCopy( if (listen) { var server = try Server.init(.{ .gpa = gpa, - .in = std.io.getStdIn(), - .out = std.io.getStdOut(), + .in = .stdin(), + .out = .stdout(), .zig_version = builtin.zig_version_string, }); defer server.deinit(); diff --git a/lib/compiler/reduce.zig b/lib/compiler/reduce.zig index 57b4fd5b1b..746e0d363d 100644 --- a/lib/compiler/reduce.zig +++ b/lib/compiler/reduce.zig @@ -68,7 +68,7 @@ pub fn main() !void { const arg = args[i]; if (mem.startsWith(u8, arg, "-")) { if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) { - const stdout = std.io.getStdOut().writer(); + const stdout = std.fs.File.stdout().writer(); try stdout.writeAll(usage); return std.process.cleanExit(); } else if (mem.eql(u8, arg, "--")) { diff --git a/lib/compiler/resinator/cli.zig b/lib/compiler/resinator/cli.zig index f27775d6af..61c88b2ec0 100644 --- a/lib/compiler/resinator/cli.zig +++ b/lib/compiler/resinator/cli.zig @@ -127,7 +127,7 @@ pub const Diagnostics = struct { pub fn renderToStdErr(self: *Diagnostics, args: []const []const u8, config: std.io.tty.Config) void { std.debug.lockStdErr(); defer std.debug.unlockStdErr(); - const stderr = std.io.getStdErr().writer(); + const stderr = std.fs.File.stderr().writer(); self.renderToWriter(args, stderr, config) catch return; } diff --git a/lib/compiler/resinator/errors.zig b/lib/compiler/resinator/errors.zig index 9727872367..72156beff2 100644 --- a/lib/compiler/resinator/errors.zig +++ b/lib/compiler/resinator/errors.zig @@ -63,14 +63,14 @@ pub const Diagnostics = struct { pub fn renderToStdErr(self: *Diagnostics, cwd: std.fs.Dir, source: []const u8, tty_config: std.io.tty.Config, source_mappings: ?SourceMappings) void { std.debug.lockStdErr(); defer std.debug.unlockStdErr(); - const stderr = std.io.getStdErr().writer(); + const stderr = std.fs.File.stderr().writer(); for (self.errors.items) |err_details| { renderErrorMessage(stderr, tty_config, cwd, err_details, source, self.strings.items, source_mappings) catch return; } } pub fn renderToStdErrDetectTTY(self: *Diagnostics, cwd: std.fs.Dir, source: []const u8, source_mappings: ?SourceMappings) void { - const tty_config = std.io.tty.detectConfig(std.io.getStdErr()); + const tty_config = std.io.tty.detectConfig(std.fs.File.stderr()); return self.renderToStdErr(cwd, source, tty_config, source_mappings); } diff --git a/lib/compiler/resinator/main.zig b/lib/compiler/resinator/main.zig index 772f837e09..e1f229a88e 100644 --- a/lib/compiler/resinator/main.zig +++ b/lib/compiler/resinator/main.zig @@ -22,7 +22,7 @@ pub fn main() !void { defer arena_state.deinit(); const arena = arena_state.allocator(); - const stderr = std.io.getStdErr(); + const stderr = std.fs.File.stderr(); const stderr_config = std.io.tty.detectConfig(stderr); const args = try std.process.argsAlloc(allocator); @@ -44,7 +44,7 @@ pub fn main() !void { var error_handler: ErrorHandler = switch (zig_integration) { true => .{ .server = .{ - .out = std.io.getStdOut(), + .out = std.fs.File.stdout(), .in = undefined, // won't be receiving messages .receive_fifo = undefined, // won't be receiving messages }, @@ -81,7 +81,7 @@ pub fn main() !void { defer options.deinit(); if (options.print_help_and_exit) { - const stdout = std.io.getStdOut(); + const stdout = std.fs.File.stdout(); try cli.writeUsage(stdout.writer(), "zig rc"); return; } @@ -89,7 +89,7 @@ pub fn main() !void { // Don't allow verbose when integrating with Zig via stdout options.verbose = false; - const stdout_writer = std.io.getStdOut().writer(); + const stdout_writer = std.fs.File.stdout().writer(); if (options.verbose) { try options.dumpVerbose(stdout_writer); try stdout_writer.writeByte('\n'); @@ -645,7 +645,7 @@ const ErrorHandler = union(enum) { }, .tty => { // extra newline to separate this line from the aro errors - try renderErrorMessage(std.io.getStdErr().writer(), self.tty, .err, "{s}\n", .{fail_msg}); + try renderErrorMessage(std.fs.File.stderr().writer(), self.tty, .err, "{s}\n", .{fail_msg}); aro.Diagnostics.render(comp, self.tty); }, } @@ -690,7 +690,7 @@ const ErrorHandler = union(enum) { try server.serveErrorBundle(error_bundle); }, .tty => { - try renderErrorMessage(std.io.getStdErr().writer(), self.tty, msg_type, format, args); + try renderErrorMessage(std.fs.File.stderr().writer(), self.tty, msg_type, format, args); }, } } diff --git a/lib/compiler/std-docs.zig b/lib/compiler/std-docs.zig index 6247077527..b5bc742717 100644 --- a/lib/compiler/std-docs.zig +++ b/lib/compiler/std-docs.zig @@ -7,7 +7,7 @@ const assert = std.debug.assert; const Cache = std.Build.Cache; fn usage() noreturn { - io.getStdOut().writeAll( + std.fs.File.stdout().writeAll( \\Usage: zig std [options] \\ \\Options: @@ -63,7 +63,7 @@ pub fn main() !void { var http_server = try address.listen(.{}); const port = http_server.listen_address.in.getPort(); const url_with_newline = try std.fmt.allocPrint(arena, "http://127.0.0.1:{d}/\n", .{port}); - std.io.getStdOut().writeAll(url_with_newline) catch {}; + std.fs.File.stdout().writeAll(url_with_newline) catch {}; if (should_open_browser) { openBrowserTab(gpa, url_with_newline[0 .. url_with_newline.len - 1 :'\n']) catch |err| { std.log.err("unable to open browser: {s}", .{@errorName(err)}); diff --git a/lib/compiler/test_runner.zig b/lib/compiler/test_runner.zig index f9adc002ad..d21d86b40a 100644 --- a/lib/compiler/test_runner.zig +++ b/lib/compiler/test_runner.zig @@ -69,8 +69,8 @@ fn mainServer() !void { @disableInstrumentation(); var server = try std.zig.Server.init(.{ .gpa = fba.allocator(), - .in = std.io.getStdIn(), - .out = std.io.getStdOut(), + .in = .stdin(), + .out = .stdout(), .zig_version = builtin.zig_version_string, }); defer server.deinit(); @@ -191,7 +191,7 @@ fn mainTerminal() void { .root_name = "Test", .estimated_total_items = test_fn_list.len, }); - const have_tty = std.io.getStdErr().isTty(); + const have_tty = std.fs.File.stderr().isTty(); var async_frame_buffer: []align(builtin.target.stackAlignment()) u8 = undefined; // TODO this is on the next line (using `undefined` above) because otherwise zig incorrectly @@ -301,7 +301,7 @@ pub fn mainSimple() anyerror!void { var failed: u64 = 0; // we don't want to bring in File and Writer if the backend doesn't support it - const stderr = if (comptime enable_print) std.io.getStdErr() else {}; + const stderr = if (comptime enable_print) std.fs.File.stderr() else {}; for (builtin.test_functions) |test_fn| { if (test_fn.func()) |_| { |
