Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 27 additions & 49 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// 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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions src/backend/io_uring.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
};
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/dynamic.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/queue.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/queue_mpsc.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/watcher/stream.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
}
}
Expand Down
15 changes: 10 additions & 5 deletions src/watcher/tcp.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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{};
Expand Down Expand Up @@ -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 {
Expand All @@ -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();
}

Expand All @@ -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 {
Expand Down