Compare commits

...

7 Commits

Author SHA1 Message Date
Wooster
9d40667bd8
Merge 88e957e2b1 into b0dcce93f7 2024-11-26 13:14:06 +01:00
Andrew Kelley
b0dcce93f7
Merge pull request #22075 from ziglang/fix-broken-pipe
Some checks are pending
ci / x86_64-linux-debug (push) Waiting to run
ci / x86_64-linux-release (push) Waiting to run
ci / aarch64-linux-debug (push) Waiting to run
ci / aarch64-linux-release (push) Waiting to run
ci / x86_64-macos-release (push) Waiting to run
ci / aarch64-macos-debug (push) Waiting to run
ci / aarch64-macos-release (push) Waiting to run
ci / x86_64-windows-debug (push) Waiting to run
ci / x86_64-windows-release (push) Waiting to run
ci / aarch64-windows (push) Waiting to run
std.io.Poller: handle EPIPE as EOF
2024-11-26 00:36:33 -05:00
Andrew Kelley
f6392b9526 cmake: don't add an unnecessary curses static lib dependency 2024-11-25 15:05:42 -08:00
Andrew Kelley
21f0fce28b CI: update macOS runner to 13
Apple has already dropped support for macOS 12.
GitHub Actions is dropping macOS 12 support now.
The Zig project is also dropping macOS 12 support now.

This commit also bumps default minimum macos version to 13.
2024-11-25 15:00:10 -08:00
Andrew Kelley
775b48dd10 std.io.Poller: handle EPIPE as EOF
closes #17483
2024-11-25 14:18:55 -08:00
Andrew Kelley
aa5341bf85 std.process.Child: explicit error set for wait 2024-11-25 14:18:55 -08:00
wooster0
88e957e2b1 std.io.tty: add setInterruptSignalHandler
Same as #20644 but without usage in the compiler.

The proposing issue #13045 is not marked as accepted but maybe this can
be merged anyway to see how it plays out and then it can still be
removed later.

Closes #13045.
2024-11-19 21:39:46 +09:00
6 changed files with 57 additions and 22 deletions

View File

@ -46,7 +46,7 @@ jobs:
- name: Build and Test
run: sh ci/aarch64-linux-release.sh
x86_64-macos-release:
runs-on: "macos-12"
runs-on: "macos-13"
env:
ARCH: "x86_64"
steps:

View File

@ -89,12 +89,7 @@ set(ZIG_SHARED_LLVM off CACHE BOOL "Prefer linking against shared LLVM libraries
set(ZIG_STATIC_LLVM ${ZIG_STATIC} CACHE BOOL "Prefer linking against static LLVM libraries")
set(ZIG_STATIC_ZLIB ${ZIG_STATIC} CACHE BOOL "Prefer linking against static zlib")
set(ZIG_STATIC_ZSTD ${ZIG_STATIC} CACHE BOOL "Prefer linking against static zstd")
if(APPLE AND ZIG_STATIC)
set(ZIG_STATIC_CURSES on)
else()
set(ZIG_STATIC_CURSES off)
endif()
set(ZIG_STATIC_CURSES ${ZIG_STATIC_CURSES} CACHE BOOL "Prefer linking against static curses")
set(ZIG_STATIC_CURSES OFF CACHE BOOL "Enable static linking against curses")
if (ZIG_SHARED_LLVM AND ZIG_STATIC_LLVM)
message(SEND_ERROR "-DZIG_SHARED_LLVM and -DZIG_STATIC_LLVM cannot both be enabled simultaneously")

View File

@ -531,7 +531,7 @@ pub const Os = struct {
},
.macos => .{
.semver = .{
.min = .{ .major = 11, .minor = 7, .patch = 1 },
.min = .{ .major = 13, .minor = 0, .patch = 0 },
.max = .{ .major = 15, .minor = 2, .patch = 0 },
},
},

View File

@ -646,7 +646,10 @@ pub fn Poller(comptime StreamEnum: type) type {
// always check if there's some data waiting to be read first.
if (poll_fd.revents & posix.POLL.IN != 0) {
const buf = try q.writableWithSize(bump_amt);
const amt = try posix.read(poll_fd.fd, buf);
const amt = posix.read(poll_fd.fd, buf) catch |err| switch (err) {
error.BrokenPipe => 0, // Handle the same as EOF.
else => |e| return e,
};
q.update(amt);
if (amt == 0) {
// Remove the fd when the EOF condition is met.

View File

@ -133,3 +133,43 @@ pub const Config = union(enum) {
};
}
};
/// Registers a global handler function to run if an interrupt signal is catched.
/// An interrupt signal is usually fired if Ctrl+C is pressed in the terminal that controls the process.
///
/// Because this handler won't run if Ctrl+C isn't pressed by the user, registering this handler failed,
/// or the handler was overwritten by another setInterruptSignalHandler call,
/// this should be used only for non-critical cleanups or resets of terminal state and such.
///
/// A program can only have one handler at a time.
///
/// The handler will not exit the program after it runs.
pub fn setInterruptSignalHandler(comptime handler: fn () void) error{Unexpected}!void {
if (builtin.os.tag == .windows) {
const handler_routine = struct {
fn handler_routine(dwCtrlType: windows.DWORD) callconv(windows.WINAPI) windows.BOOL {
if (dwCtrlType == windows.CTRL_C_EVENT) {
handler();
return windows.TRUE;
} else {
// Ignore this event.
return windows.FALSE;
}
}
}.handler_routine;
try windows.SetConsoleCtrlHandler(handler_routine, true);
} else {
const internal_handler = struct {
fn internal_handler(sig: c_int) callconv(.C) void {
std.debug.assert(sig == std.posix.SIG.INT);
handler();
}
}.internal_handler;
const act = std.posix.Sigaction{
.handler = .{ .handler = internal_handler },
.mask = std.posix.empty_sigset,
.flags = 0,
};
std.posix.sigaction(std.posix.SIG.INT, &act, null);
}
}

View File

@ -293,19 +293,16 @@ pub fn killPosix(self: *ChildProcess) !Term {
error.ProcessNotFound => return error.AlreadyTerminated,
else => return err,
};
try self.waitUnwrapped();
self.waitUnwrapped();
return self.term.?;
}
pub const WaitError = SpawnError || std.os.windows.GetProcessMemoryInfoError;
/// Blocks until child process terminates and then cleans up all resources.
pub fn wait(self: *ChildProcess) !Term {
const term = if (native_os == .windows)
try self.waitWindows()
else
try self.waitPosix();
pub fn wait(self: *ChildProcess) WaitError!Term {
const term = if (native_os == .windows) try self.waitWindows() else self.waitPosix();
self.id = undefined;
return term;
}
@ -408,7 +405,7 @@ pub fn run(args: struct {
};
}
fn waitWindows(self: *ChildProcess) !Term {
fn waitWindows(self: *ChildProcess) WaitError!Term {
if (self.term) |term| {
self.cleanupStreams();
return term;
@ -418,17 +415,17 @@ fn waitWindows(self: *ChildProcess) !Term {
return self.term.?;
}
fn waitPosix(self: *ChildProcess) !Term {
fn waitPosix(self: *ChildProcess) SpawnError!Term {
if (self.term) |term| {
self.cleanupStreams();
return term;
}
try self.waitUnwrapped();
self.waitUnwrapped();
return self.term.?;
}
fn waitUnwrappedWindows(self: *ChildProcess) !void {
fn waitUnwrappedWindows(self: *ChildProcess) WaitError!void {
const result = windows.WaitForSingleObjectEx(self.id, windows.INFINITE, false);
self.term = @as(SpawnError!Term, x: {
@ -450,7 +447,7 @@ fn waitUnwrappedWindows(self: *ChildProcess) !void {
return result;
}
fn waitUnwrapped(self: *ChildProcess) !void {
fn waitUnwrapped(self: *ChildProcess) void {
const res: posix.WaitPidResult = res: {
if (self.request_resource_usage_statistics) {
switch (native_os) {