Skip to content

Commit 291f21d

Browse files
mitchellhnikneym
authored andcommitted
tweaks, up to Zig 0.14.1
1 parent 7f417fa commit 291f21d

File tree

6 files changed

+37
-17
lines changed

6 files changed

+37
-17
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ jobs:
122122
- name: Install zig
123123
uses: goto-bus-stop/setup-zig@v2
124124
with:
125-
version: 0.14.0
125+
version: 0.14.1
126126

127127
- name: test
128128
run: zig build test --summary all
@@ -142,7 +142,7 @@ jobs:
142142
- name: Install zig
143143
uses: goto-bus-stop/setup-zig@v2
144144
with:
145-
version: 0.14.0
145+
version: 0.14.1
146146

147147
- name: test
148148
run: zig build test --summary all

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}."0.14.0";
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
@@ -52,7 +52,8 @@ pub const Backend = enum {
5252
pub fn default() Backend {
5353
return switch (builtin.os.tag) {
5454
.linux => .io_uring,
55-
.ios, .macos, .freebsd => .kqueue,
55+
.ios, .macos => .kqueue,
56+
.freebsd => .kqueue,
5657
.wasi => .wasi_poll,
5758
.windows => .iocp,
5859
else => {
@@ -66,7 +67,8 @@ pub const Backend = enum {
6667
pub fn candidates() []const Backend {
6768
return switch (builtin.os.tag) {
6869
.linux => &.{ .io_uring, .epoll },
69-
.freebsd, .ios, .macos => &.{.kqueue},
70+
.ios, .macos => &.{.kqueue},
71+
.freebsd => &.{.kqueue},
7072
.wasi => &.{.wasi_poll},
7173
.windows => &.{.iocp},
7274
else => {

src/watcher/async.zig

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

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

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

23-
// Supported, uses mach port on Mac and eventfd on BSD
21+
// Supported, uses mach port on Darwin and eventfd on BSD.
2422
.kqueue => if (comptime builtin.target.os.tag.isDarwin())
2523
AsyncMachPort(xev)
2624
else
@@ -41,12 +39,29 @@ fn AsyncEventFd(comptime xev: type) type {
4139
/// eventfd file descriptor
4240
fd: posix.fd_t,
4341

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

0 commit comments

Comments
 (0)