Skip to content

Commit 73edbe7

Browse files
mitchellhSythivo
authored andcommitted
tweaks, up to Zig 0.14.1
1 parent 377fd11 commit 73edbe7

File tree

5 files changed

+35
-15
lines changed

5 files changed

+35
-15
lines changed

flake.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
# Other overlays
2525
(final: prev: rec {
2626
zigpkgs = inputs.zig.packages.${prev.system};
27-
zig = inputs.zig.packages.${prev.system}."master";
27+
zig = inputs.zig.packages.${prev.system}."0.14.1";
2828

2929
# Latest versions
3030
wasmtime = inputs.nixpkgs-unstable.legacyPackages.${prev.system}.wasmtime;

src/backend/kqueue.zig

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ const log = std.log.scoped(.libxev_kqueue);
1717
/// True if this backend is available on this platform.
1818
pub fn available() bool {
1919
return switch (builtin.os.tag) {
20-
.freebsd, .ios, .macos => true,
20+
// macOS uses kqueue
21+
.ios, .macos => true,
22+
23+
// BSDs use kqueue, but we only test on FreeBSD for now.
24+
// kqueue isn't exactly the same here as it is on Apple platforms.
25+
.freebsd => true,
2126

2227
// Technically other BSDs support kqueue but our implementation
2328
// below hard requires mach ports currently. That's not a fundamental
@@ -28,9 +33,7 @@ pub fn available() bool {
2833
}
2934

3035
pub const NOTE_EXIT_FLAGS = switch (builtin.os.tag) {
31-
.ios,
32-
.macos,
33-
=> std.c.NOTE.EXIT | std.c.NOTE.EXITSTATUS,
36+
.ios, .macos => std.c.NOTE.EXIT | std.c.NOTE.EXITSTATUS,
3437
.freebsd => std.c.NOTE.EXIT,
3538
else => @compileError("kqueue not supported yet for target OS"),
3639
};

src/main.zig

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ pub const Backend = enum {
4949
pub fn default() Backend {
5050
return switch (builtin.os.tag) {
5151
.linux => .io_uring,
52-
.ios, .macos, .freebsd => .kqueue,
52+
.ios, .macos => .kqueue,
53+
.freebsd => .kqueue,
5354
.wasi => .wasi_poll,
5455
.windows => .iocp,
5556
else => {
@@ -63,7 +64,8 @@ pub const Backend = enum {
6364
pub fn candidates() []const Backend {
6465
return switch (builtin.os.tag) {
6566
.linux => &.{ .io_uring, .epoll },
66-
.freebsd, .ios, .macos => &.{.kqueue},
67+
.ios, .macos => &.{.kqueue},
68+
.freebsd => &.{.kqueue},
6769
.wasi => &.{.wasi_poll},
6870
.windows => &.{.iocp},
6971
else => {

src/watcher/async.zig

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ const assert = std.debug.assert;
55
const posix = std.posix;
66
const common = @import("common.zig");
77

8-
pub extern "c" fn eventfd(initval: c_uint, flags: c_uint) c_int;
9-
108
pub fn Async(comptime xev: type) type {
119
if (xev.dynamic) return AsyncDynamic(xev);
1210

@@ -19,7 +17,7 @@ pub fn Async(comptime xev: type) type {
1917
// Supported, uses the backend API
2018
.wasi_poll => AsyncLoopState(xev, xev.Loop.threaded),
2119

22-
// Supported, uses mach port on Mac and eventfd on BSD
20+
// Supported, uses mach port on Darwin and eventfd on BSD.
2321
.kqueue => if (comptime builtin.target.os.tag.isDarwin())
2422
AsyncMachPort(xev)
2523
else
@@ -40,12 +38,29 @@ fn AsyncEventFd(comptime xev: type) type {
4038
/// eventfd file descriptor
4139
fd: posix.fd_t,
4240

41+
/// This is only used for FreeBSD currently.
42+
extern "c" fn eventfd(initval: c_uint, flags: c_uint) c_int;
43+
4344
/// Create a new async. An async can be assigned to exactly one loop
4445
/// to be woken up. The completion must be allocated in advance.
4546
pub fn init() !Self {
4647
return .{
47-
//.fd = try std.posix.eventfd(0, std.os.linux.EFD.CLOEXEC),
48-
.fd = eventfd(0, 0),
48+
.fd = switch (builtin.os.tag) {
49+
// std.posix is unavailable on FreeBSD. We call the
50+
// syscall directly.
51+
//
52+
// TODO: error handling
53+
.freebsd => eventfd(
54+
0,
55+
0x100000, // EFD_CLOEXEC
56+
),
57+
58+
// Use std.posix if we can.
59+
else => try std.posix.eventfd(
60+
0,
61+
std.os.linux.EFD.CLOEXEC,
62+
),
63+
},
4964
};
5065
}
5166

0 commit comments

Comments
 (0)