commit ec56696503e702e063af8740a77376b2e7694c29 (tree)
parent e68ae8d7a1e78a25392e271d7ca894e0f09aa218
Author: Andrew Kelley <andrew@ziglang.org>
Date: Fri, 12 Dec 2025 17:20:18 -0800
std.process.cleanExit: take an Io parameter
In case exit(0) will be called, this provides the opportunity for the
application's Io instance to be the one to clear the terminal in case
std.Progress or similar was used.
Diffstat:
5 files changed, 33 insertions(+), 33 deletions(-)
diff --git a/lib/compiler/libc.zig b/lib/compiler/libc.zig
@@ -50,7 +50,7 @@ pub fn main() !void {
if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
try stdout.writeAll(usage_libc);
try stdout.flush();
- return std.process.cleanExit();
+ return std.process.cleanExit(io);
} else if (mem.eql(u8, arg, "-target")) {
if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg});
i += 1;
@@ -110,7 +110,7 @@ pub fn main() !void {
try stdout.writeByte('\n');
}
try stdout.flush();
- return std.process.cleanExit();
+ return std.process.cleanExit(io);
}
if (input_file) |libc_file| {
diff --git a/lib/compiler/objcopy.zig b/lib/compiler/objcopy.zig
@@ -235,7 +235,7 @@ fn cmdObjCopy(gpa: Allocator, arena: Allocator, args: []const []const u8) !void
const hdr = try server.receiveMessage();
switch (hdr.tag) {
.exit => {
- return std.process.cleanExit();
+ return std.process.cleanExit(io);
},
.update => {
if (seen_update) fatal("zig objcopy only supports 1 update for now", .{});
@@ -250,7 +250,7 @@ fn cmdObjCopy(gpa: Allocator, arena: Allocator, args: []const []const u8) !void
}
}
}
- return std.process.cleanExit();
+ return std.process.cleanExit(io);
}
const usage =
diff --git a/lib/compiler/reduce.zig b/lib/compiler/reduce.zig
@@ -75,7 +75,7 @@ pub fn main() !void {
if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
const stdout = Io.File.stdout();
try stdout.writeAll(usage);
- return std.process.cleanExit();
+ return std.process.cleanExit(io);
} else if (mem.eql(u8, arg, "--")) {
argv = args[i + 1 ..];
break;
@@ -278,10 +278,10 @@ pub fn main() !void {
try tree.render(gpa, &rendered.writer, fixups);
try Io.Dir.cwd().writeFile(io, .{ .sub_path = root_source_file_path, .data = rendered.written() });
- return std.process.cleanExit();
+ return std.process.cleanExit(io);
}
std.debug.print("no more transformations found\n", .{});
- return std.process.cleanExit();
+ return std.process.cleanExit(io);
}
fn sortTransformations(transformations: []Walk.Transformation, rng: std.Random) void {
diff --git a/src/fmt.zig b/src/fmt.zig
@@ -60,7 +60,7 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
if (mem.startsWith(u8, arg, "-")) {
if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
try Io.File.stdout().writeStreamingAll(io, usage_fmt);
- return process.cleanExit();
+ return process.cleanExit(io);
} else if (mem.eql(u8, arg, "--color")) {
if (i + 1 >= args.len) {
fatal("expected [auto|on|off] after --color", .{});
diff --git a/src/main.zig b/src/main.zig
@@ -1038,7 +1038,7 @@ fn buildOutputType(
} else if (mem.startsWith(u8, arg, "-")) {
if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
try Io.File.stdout().writeStreamingAll(io, usage_build_generic);
- return cleanExit();
+ return cleanExit(io);
} else if (mem.eql(u8, arg, "--")) {
if (arg_mode == .run) {
// args_iter.i is 1, referring the next arg after "--" in ["--", ...]
@@ -3646,7 +3646,7 @@ fn buildOutputType(
all_args,
runtime_args_start,
);
- return cleanExit();
+ return cleanExit(io);
},
.ip4 => |ip4_addr| {
const addr: Io.net.IpAddress = .{ .ip4 = ip4_addr };
@@ -3672,7 +3672,7 @@ fn buildOutputType(
all_args,
runtime_args_start,
);
- return cleanExit();
+ return cleanExit(io);
},
}
@@ -3755,7 +3755,7 @@ fn buildOutputType(
}
// Skip resource deallocation in release builds; let the OS do it.
- return cleanExit();
+ return cleanExit(io);
}
const CreateModule = struct {
@@ -4176,7 +4176,7 @@ fn serve(
defer if (comp.debugIncremental()) ids.mutex.unlock(io);
switch (hdr.tag) {
- .exit => return cleanExit(),
+ .exit => return cleanExit(io),
.update => {
tracy.frameMark();
file_system_inputs.clearRetainingCapacity();
@@ -4462,7 +4462,7 @@ fn runOrTest(
switch (term) {
.Exited => |code| {
if (code == 0) {
- return cleanExit();
+ return cleanExit(io);
} else {
process.exit(code);
}
@@ -4476,7 +4476,7 @@ fn runOrTest(
switch (term) {
.Exited => |code| {
if (code == 0) {
- return cleanExit();
+ return cleanExit(io);
} else {
const cmd = try std.mem.join(arena, " ", argv.items);
fatal("the following test command failed with exit code {d}:\n{s}", .{ code, cmd });
@@ -4688,7 +4688,7 @@ fn cmdTranslateC(
var file_reader = zig_file.reader(io, &.{});
_ = try stdout_writer.interface.sendFileAll(&file_reader, .unlimited);
try stdout_writer.interface.flush();
- return cleanExit();
+ return cleanExit(io);
}
}
@@ -4735,7 +4735,7 @@ fn cmdInit(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
template = .minimal;
} else if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
try Io.File.stdout().writeStreamingAll(io, usage_init);
- return cleanExit();
+ return cleanExit(io);
} else {
fatal("unrecognized parameter: '{s}'", .{arg});
}
@@ -4780,7 +4780,7 @@ fn cmdInit(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
if (ok_count == template_paths.len) {
std.log.info("see `zig build --help` for a menu of options", .{});
}
- return cleanExit();
+ return cleanExit(io);
},
.minimal => {
writeSimpleTemplateFile(io, Package.Manifest.basename,
@@ -4813,11 +4813,11 @@ fn cmdInit(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
// their `build.zig.zon` *after* writing their `build.zig`. So this one isn't fatal.
error.PathAlreadyExists => {
std.log.info("successfully populated '{s}', preserving existing '{s}'", .{ Package.Manifest.basename, Package.build_zig_basename });
- return cleanExit();
+ return cleanExit(io);
},
};
std.log.info("successfully populated '{s}' and '{s}'", .{ Package.Manifest.basename, Package.build_zig_basename });
- return cleanExit();
+ return cleanExit(io);
},
}
}
@@ -5284,7 +5284,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)
process.exit(1);
}
- if (fetch_only) return cleanExit();
+ if (fetch_only) return cleanExit(io);
var source_buf = std.array_list.Managed(u8).init(gpa);
defer source_buf.deinit();
@@ -5420,7 +5420,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)
switch (term) {
.Exited => |code| {
- if (code == 0) return cleanExit();
+ if (code == 0) return cleanExit(io);
// Indicates that the build runner has reported compile errors
// and this parent process does not need to report any further
// diagnostics.
@@ -5691,7 +5691,7 @@ fn jitCmd(
.Exited => |code| {
if (code == 0) {
if (options.capture != null) return;
- return cleanExit();
+ return cleanExit(io);
}
const cmd = try std.mem.join(arena, " ", child_argv.items);
fatal("the following build command failed with exit code {d}:\n{s}", .{ code, cmd });
@@ -6151,7 +6151,7 @@ fn cmdAstCheck(arena: Allocator, io: Io, args: []const []const u8) !void {
if (mem.startsWith(u8, arg, "-")) {
if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
try Io.File.stdout().writeStreamingAll(io, usage_ast_check);
- return cleanExit();
+ return cleanExit(io);
} else if (mem.eql(u8, arg, "-t")) {
want_output_text = true;
} else if (mem.eql(u8, arg, "--zon")) {
@@ -6222,7 +6222,7 @@ fn cmdAstCheck(arena: Allocator, io: Io, args: []const []const u8) !void {
if (zir.hasCompileErrors()) {
process.exit(1);
} else {
- return cleanExit();
+ return cleanExit(io);
}
}
if (!build_options.enable_debug_extensions) {
@@ -6273,7 +6273,7 @@ fn cmdAstCheck(arena: Allocator, io: Io, args: []const []const u8) !void {
if (zir.hasCompileErrors()) {
process.exit(1);
} else {
- return cleanExit();
+ return cleanExit(io);
}
},
.zon => {
@@ -6288,7 +6288,7 @@ fn cmdAstCheck(arena: Allocator, io: Io, args: []const []const u8) !void {
}
if (!want_output_text) {
- return cleanExit();
+ return cleanExit(io);
}
if (!build_options.enable_debug_extensions) {
@@ -6297,7 +6297,7 @@ fn cmdAstCheck(arena: Allocator, io: Io, args: []const []const u8) !void {
try @import("print_zoir.zig").renderToWriter(zoir, arena, stdout_bw);
try stdout_bw.flush();
- return cleanExit();
+ return cleanExit(io);
},
}
}
@@ -6325,7 +6325,7 @@ fn cmdDetectCpu(io: Io, args: []const []const u8) !void {
if (mem.startsWith(u8, arg, "-")) {
if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
try Io.File.stdout().writeStreamingAll(io, detect_cpu_usage);
- return cleanExit();
+ return cleanExit(io);
} else if (mem.eql(u8, arg, "--llvm")) {
use_llvm = true;
} else {
@@ -6475,7 +6475,7 @@ fn cmdDumpLlvmInts(
}
try stdout_bw.flush();
- return cleanExit();
+ return cleanExit(io);
}
/// This is only enabled for debug builds.
@@ -6909,7 +6909,7 @@ fn cmdFetch(
if (mem.startsWith(u8, arg, "-")) {
if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
try Io.File.stdout().writeStreamingAll(io, usage_fetch);
- return cleanExit();
+ return cleanExit(io);
} else if (mem.eql(u8, arg, "--global-cache-dir")) {
if (i + 1 >= args.len) fatal("expected argument after '{s}'", .{arg});
i += 1;
@@ -7020,7 +7020,7 @@ fn cmdFetch(
var stdout = Io.File.stdout().writerStreaming(io, &stdout_buffer);
try stdout.interface.print("{s}\n", .{package_hash_slice});
try stdout.interface.flush();
- return cleanExit();
+ return cleanExit(io);
},
.yes, .exact => |name| name: {
if (name) |n| break :name n;
@@ -7159,7 +7159,7 @@ fn cmdFetch(
fatal("unable to write {s} file: {t}", .{ Package.Manifest.basename, err });
};
- return cleanExit();
+ return cleanExit(io);
}
fn createEmptyDependenciesModule(