From 2c916b815470923ae74b1c415055cc6d22b1afc1 Mon Sep 17 00:00:00 2001 From: Leah Amelia Chen Date: Sat, 3 Oct 2026 16:37:48 +0800 Subject: [PATCH 1/2] build: update to Zig 0.17 --- build.zig | 76 ++++++++++++++++++++----------------------------------- 1 file changed, 27 insertions(+), 49 deletions(-) diff --git a/build.zig b/build.zig index ec2da420..ee8d77ae 100644 --- a/build.zig +++ b/build.zig @@ -19,14 +19,7 @@ pub fn build(b: *std.Build) !void { bool, "emit-man-pages", "Set to true to build man pages. Requires scdoc. Defaults to true if scdoc is found.", - ) orelse if (b.findProgram( - &[_][]const u8{"scdoc"}, - &[_][]const u8{}, - )) |_| - true - else |err| switch (err) { - error.FileNotFound => false, - }; + ) orelse (b.findProgram(.{ .names = &.{"scdoc"} }) != null); const emit_bench = b.option( bool, @@ -86,25 +79,28 @@ pub fn build(b: *std.Build) !void { ); // pkg-config - const pc: *Step.InstallFile = pc: { - const file = b.addWriteFile("libxev.pc", b.fmt( - \\prefix={s} - \\includedir=${{prefix}}/include - \\libdir=${{prefix}}/lib - \\ - \\Name: libxev - \\URL: https://github.com/mitchellh/libxev - \\Description: High-performance, cross-platform event loop - \\Version: 0.1.0 - \\Cflags: -I${{includedir}} - \\Libs: -L${{libdir}} -lxev - , .{b.install_prefix})); - break :pc b.addInstallFileWithDir( - file.getDirectory().path(b, "libxev.pc"), - .prefix, - "share/pkgconfig/libxev.pc", - ); - }; + // FIXME: It is impossible since Zig 0.17 to obtain the + // installation prefix at the configure phase, as that + // is the responsibility of the maker. + // const pc: *Step.InstallFile = pc: { + // const file = b.addWriteFile("libxev.pc", b.fmt( + // \\prefix={s} + // \\includedir=${{prefix}}/include + // \\libdir=${{prefix}}/lib + // \\ + // \\Name: libxev + // \\URL: https://github.com/mitchellh/libxev + // \\Description: High-performance, cross-platform event loop + // \\Version: 0.1.0 + // \\Cflags: -I${{includedir}} + // \\Libs: -L${{libdir}} -lxev + // , .{b.install_prefix})); + // break :pc b.addInstallFileWithDir( + // file.getDirectory().path(b, "libxev.pc"), + // .prefix, + // "share/pkgconfig/libxev.pc", + // ); + // }; // Man pages const man = try manPages(b); @@ -145,7 +141,7 @@ pub fn build(b: *std.Build) !void { if (static_lib) |v| b.installArtifact(v); if (dynamic_lib) |v| b.installArtifact(v); b.getInstallStep().dependOn(&c_header.step); - b.getInstallStep().dependOn(&pc.step); + // b.getInstallStep().dependOn(&pc.step); b.installArtifact(test_exe); if (emit_man) { for (man) |step| b.getInstallStep().dependOn(step); @@ -177,14 +173,7 @@ fn buildBenchmarks( var steps: std.ArrayList(*Step.Compile) = .empty; defer steps.deinit(alloc); - var dir = try std.Io.Dir.cwd().openDir( - io, - try b.build_root.join( - b.allocator, - &.{ "src", "bench" }, - ), - .{ .iterate = true }, - ); + var dir = try b.root.openDir(io, "src/bench", .{ .iterate = true }); defer dir.close(io); // Go through and add each as a step @@ -233,14 +222,7 @@ fn buildExamples( var steps: std.ArrayList(*Step.Compile) = .empty; defer steps.deinit(alloc); - var dir = try std.Io.Dir.cwd().openDir( - io, - try b.build_root.join( - b.allocator, - &.{"examples"}, - ), - .{ .iterate = true }, - ); + var dir = try b.root.openDir(io, "examples", .{ .iterate = true }); defer dir.close(io); // Go through and add each as a step @@ -313,11 +295,7 @@ fn manPages(b: *std.Build) ![]const *Step { var steps: std.ArrayList(*Step) = .empty; defer steps.deinit(alloc); - var dir = try std.Io.Dir.cwd().openDir( - io, - try b.build_root.join(b.allocator, &.{"docs"}), - .{ .iterate = true }, - ); + var dir = try b.root.openDir(io, "docs", .{ .iterate = true }); defer dir.close(io); var it = dir.iterate(); From 819ffa180ca20e31c7eded74e2e1aceb1eab557f Mon Sep 17 00:00:00 2001 From: Leah Amelia Chen Date: Sat, 3 Oct 2026 16:50:59 +0800 Subject: [PATCH 2/2] treewide: update to Zig 0.17 --- src/backend/io_uring.zig | 6 +++--- src/dynamic.zig | 2 +- src/main.zig | 12 ++++++------ src/queue.zig | 2 +- src/queue_mpsc.zig | 2 +- src/watcher/stream.zig | 4 ++-- src/watcher/tcp.zig | 15 ++++++++++----- 7 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/backend/io_uring.zig b/src/backend/io_uring.zig index 6891bc3a..b420971b 100644 --- a/src/backend/io_uring.zig +++ b/src/backend/io_uring.zig @@ -1650,7 +1650,7 @@ test "io_uring: sendmsg/recvmsg" { defer xev_posix.close(client); // Send - const buffer_send = [_]u8{42} ** 128; + const buffer_send: [128]u8 = @splat(42); const iovecs_send = [_]posix.iovec_const{ posix.iovec_const{ .base = &buffer_send, .len = buffer_send.len }, }; @@ -1685,11 +1685,11 @@ test "io_uring: sendmsg/recvmsg" { // Recv - var buffer_recv = [_]u8{0} ** 128; + var buffer_recv: [128]u8 = @splat(0); var iovecs_recv = [_]posix.iovec{ posix.iovec{ .base = &buffer_recv, .len = buffer_recv.len }, }; - const addr = [_]u8{0} ** 4; + const addr: [4]u8 = @splat(0); var address_recv = net.Address.initIp4(addr, 0); var msg_recv: linux.msghdr = linux.msghdr{ .name = &address_recv.any, diff --git a/src/dynamic.zig b/src/dynamic.zig index 51f438bf..547abb94 100644 --- a/src/dynamic.zig +++ b/src/dynamic.zig @@ -461,7 +461,7 @@ fn Union( var field_names: [bes.len + 1][:0]const u8 = undefined; var field_types: [bes.len + 1]type = undefined; - var field_attrs: [bes.len + 1]std.builtin.Type.UnionField.Attributes = @splat(.{}); + var field_attrs: [bes.len + 1]std.builtin.Type.Union.FieldAttributes = @splat(.{}); for (bes, 0..) |be, i| { var T: type = be.Api(); for (field) |f| T = @field(T, f); diff --git a/src/main.zig b/src/main.zig index 39119a6e..78695a44 100644 --- a/src/main.zig +++ b/src/main.zig @@ -44,14 +44,14 @@ comptime { // from the main struct. const main = @This(); const default = Backend.default().Api(); - for (@typeInfo(default).@"struct".decls) |decl| { - const Decl = @TypeOf(@field(default, decl.name)); + for (@typeInfo(default).@"struct".decl_names) |decl| { + const Decl = @TypeOf(@field(default, decl)); if (Decl == void) continue; - if (!@hasDecl(main, decl.name)) { - @compileError("missing decl: " ++ decl.name); + if (!@hasDecl(main, decl)) { + @compileError("missing decl: " ++ decl); } - if (Decl != @TypeOf(@field(main, decl.name))) { - @compileError("decl has wrong type: " ++ decl.name); + if (Decl != @TypeOf(@field(main, decl))) { + @compileError("decl has wrong type: " ++ decl); } } } diff --git a/src/queue.zig b/src/queue.zig index 7cafda37..ad2421db 100644 --- a/src/queue.zig +++ b/src/queue.zig @@ -73,7 +73,7 @@ test Intrusive { try testing.expect(q.empty()); // Elems - var elems: [10]Elem = .{Elem{}} ** 10; + var elems: [10]Elem = @splat(.{}); // One try testing.expect(q.pop() == null); diff --git a/src/queue_mpsc.zig b/src/queue_mpsc.zig index 3a9f4cbb..6b24f4e6 100644 --- a/src/queue_mpsc.zig +++ b/src/queue_mpsc.zig @@ -90,7 +90,7 @@ test Intrusive { q.init(); // Elems - var elems: [10]Elem = .{Elem{}} ** 10; + var elems: [10]Elem = @splat(.{}); // One try testing.expect(q.pop() == null); diff --git a/src/watcher/stream.zig b/src/watcher/stream.zig index c00e631e..736935a6 100644 --- a/src/watcher/stream.zig +++ b/src/watcher/stream.zig @@ -145,8 +145,8 @@ fn Pollable(comptime xev: type, comptime T: type, comptime options: Options) typ for (xev.candidates) |be| { const CandidateT = @field(be.Api(), options.type.?); const info = @typeInfo(CandidateT).@"struct"; - for (info.decls) |decl| { - if (std.mem.eql(u8, decl.name, "poll")) break; + for (info.decl_names) |decl| { + if (std.mem.eql(u8, decl, "poll")) break; } else return struct {}; } } diff --git a/src/watcher/tcp.zig b/src/watcher/tcp.zig index 040378f8..1340b1e6 100644 --- a/src/watcher/tcp.zig +++ b/src/watcher/tcp.zig @@ -809,7 +809,12 @@ fn TCPTests(comptime xev: type, comptime Impl: type) type { &std.mem.toBytes(@as(c_int, 8192)), ); - const send_buf = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 } ** 100_000; + const send_buf_len = 1_000_000; + var send_buf: [send_buf_len]u8 = undefined; + for (0..100_000) |i| @memcpy( + send_buf[i * 10..][0..10], + &[_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }, + ); var sent_unqueued: usize = 0; // First we try to send the whole 1MB buffer in one write operation, this _should_ result @@ -832,7 +837,7 @@ fn TCPTests(comptime xev: type, comptime Impl: type) type { try loop.run(.until_done); // SO_SNDBUF doesn't seem to be respected exactly, sent_unqueued will often be ~32kB // even though SO_SNDBUF was set to 8kB - try testing.expect(sent_unqueued < (send_buf.len / 10)); + try testing.expect(sent_unqueued < (send_buf_len / 10)); // Set up queued write var w_queue = xev.WriteQueue{}; @@ -872,7 +877,7 @@ fn TCPTests(comptime xev: type, comptime Impl: type) type { loop: *xev.Loop, conn: Impl, completion: xev.Completion = .{}, - buf: [send_buf.len]u8 = undefined, + buf: [send_buf_len]u8 = undefined, bytes_read: usize = 0, pub fn read(receiver: *@This()) void { @@ -896,7 +901,7 @@ fn TCPTests(comptime xev: type, comptime Impl: type) type { const n_bytes = r catch unreachable; receiver.bytes_read += n_bytes; - if (receiver.bytes_read < send_buf.len) { + if (receiver.bytes_read < send_buf_len) { receiver.read(); } @@ -912,7 +917,7 @@ fn TCPTests(comptime xev: type, comptime Impl: type) type { // Wait for the send/receive try loop.run(.until_done); try testing.expectEqualSlices(u8, &send_buf, receiver.buf[0..receiver.bytes_read]); - try testing.expect(send_buf.len == sent_unqueued + sent_queued); + try testing.expect(send_buf_len == sent_unqueued + sent_queued); // Close server_conn.?.close(&loop, &c_accept, ?Impl, &server_conn, (struct {