Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
on: [push, pull_request]
name: Test
env:
ZIG_VERSION: 0.16.0
ZIG_VERSION: 0.17.0

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ directory.

# Build

Build requires the installation of the Zig 0.16. libxev follows stable
Build requires the installation of the Zig 0.17. libxev follows stable
Zig releases and generally does not support nightly builds. When a stable
release is imminent we may have a branch that supports it.
**libxev has no other build dependencies.**
Expand Down
50 changes: 25 additions & 25 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -79,28 +79,25 @@ pub fn build(b: *std.Build) !void {
);

// pkg-config
// 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",
// );
// };
const pc: *Step.InstallFile = pc: {
const file = b.addWriteFile("libxev.pc", b.fmt(
\\prefix=${{pcfiledir}}/../..
\\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
, .{}));
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 @@ -141,7 +138,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 @@ -173,6 +170,7 @@ fn buildBenchmarks(
var steps: std.ArrayList(*Step.Compile) = .empty;
defer steps.deinit(alloc);

b.dependOnDirectoryContents(b.path("src/bench"));
var dir = try b.root.openDir(io, "src/bench", .{ .iterate = true });
defer dir.close(io);

Expand All @@ -199,7 +197,7 @@ fn buildBenchmarks(
.{entry.name},
)),
.target = target,
.optimize = .ReleaseFast, // benchmarks are always release fast
.optimize = .fast, // benchmarks are always release fast
}),
});
exe.root_module.addImport("xev", b.modules.get("xev").?);
Expand All @@ -214,14 +212,15 @@ fn buildBenchmarks(
fn buildExamples(
b: *std.Build,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
optimize: std.lang.Optimize,
c_lib_: ?*Step.Compile,
) ![]const *Step.Compile {
const io = b.graph.io;
const alloc = b.allocator;
var steps: std.ArrayList(*Step.Compile) = .empty;
defer steps.deinit(alloc);

b.dependOnDirectoryContents(b.path("examples"));
var dir = try b.root.openDir(io, "examples", .{ .iterate = true });
defer dir.close(io);

Expand Down Expand Up @@ -295,6 +294,7 @@ fn manPages(b: *std.Build) ![]const *Step {
var steps: std.ArrayList(*Step) = .empty;
defer steps.deinit(alloc);

b.dependOnDirectoryContents(b.path("docs"));
var dir = try b.root.openDir(io, "docs", .{ .iterate = true });
defer dir.close(io);

Expand Down
2 changes: 1 addition & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.{
.name = .libxev,
.minimum_zig_version = "0.16.0",
.minimum_zig_version = "0.17.0",
.version = "0.0.0",
.fingerprint = 0x30f7363573edabf3,
.paths = .{""},
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# Other overlays
(final: prev: rec {
zigpkgs = inputs.zig.packages.${prev.system};
zig = inputs.zig.packages.${prev.system}."0.16.0";
zig = inputs.zig.packages.${prev.system}."0.17.0";

# Our package
libxev = prev.callPackage ./nix/package.nix {};
Expand Down
7 changes: 7 additions & 0 deletions nix/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ stdenv.mkDerivation rec {

outputs = [ "out" "dev" "man" ];

# libxev.pc locates its prefix from where it sits, and the dev output keeps
# it apart from the libraries in $out.
postFixup = ''
substituteInPlace $dev/share/pkgconfig/libxev.pc \
--replace-fail 'prefix=''${pcfiledir}/../..' "prefix=$out"
'';

meta = with lib; {
description = "A high performance, cross-platform event loop.";
homepage = "https://github.com/mitchellh/libxev";
Expand Down
26 changes: 13 additions & 13 deletions src/backend/io_uring.zig
Original file line number Diff line number Diff line change
Expand Up @@ -667,21 +667,21 @@ pub const Completion = struct {
.accept => .{
.accept = if (res >= 0)
@intCast(res)
else switch (@as(posix.E, @enumFromInt(-res))) {
else switch (@as(posix.E, @fromBackingInt(@intCast(-res)))) {
.CANCELED => error.Canceled,
.AGAIN => error.Again,
else => |errno| posix.unexpectedErrno(errno),
},
},

.close => .{
.close = if (res >= 0) {} else switch (@as(posix.E, @enumFromInt(-res))) {
.close = if (res >= 0) {} else switch (@as(posix.E, @fromBackingInt(@intCast(-res)))) {
else => |errno| posix.unexpectedErrno(errno),
},
},

.connect => .{
.connect = if (res >= 0) {} else switch (@as(posix.E, @enumFromInt(-res))) {
.connect = if (res >= 0) {} else switch (@as(posix.E, @fromBackingInt(@intCast(-res)))) {
.CANCELED => error.Canceled,
.CONNREFUSED => error.ConnectionRefused,
.TIMEDOUT => error.TimedOut,
Expand All @@ -691,7 +691,7 @@ pub const Completion = struct {
},

.poll => .{
.poll = if (res >= 0) {} else switch (@as(posix.E, @enumFromInt(-res))) {
.poll = if (res >= 0) {} else switch (@as(posix.E, @fromBackingInt(@intCast(-res)))) {
else => |errno| posix.unexpectedErrno(errno),
},
},
Expand All @@ -715,7 +715,7 @@ pub const Completion = struct {
.send => .{
.send = if (res >= 0)
@intCast(res)
else switch (@as(posix.E, @enumFromInt(-res))) {
else switch (@as(posix.E, @fromBackingInt(@intCast(-res)))) {
.CANCELED => error.Canceled,
.PIPE => error.BrokenPipe,
.CONNRESET => error.ConnectionResetByPeer,
Expand All @@ -726,7 +726,7 @@ pub const Completion = struct {
.sendmsg => .{
.sendmsg = if (res >= 0)
@intCast(res)
else switch (@as(posix.E, @enumFromInt(-res))) {
else switch (@as(posix.E, @fromBackingInt(@intCast(-res)))) {
.CANCELED => error.Canceled,
.PIPE => error.BrokenPipe,
.CONNRESET => error.ConnectionResetByPeer,
Expand All @@ -735,15 +735,15 @@ pub const Completion = struct {
},

.shutdown => .{
.shutdown = if (res >= 0) {} else switch (@as(posix.E, @enumFromInt(-res))) {
.shutdown = if (res >= 0) {} else switch (@as(posix.E, @fromBackingInt(@intCast(-res)))) {
.CANCELED => error.Canceled,
.NOTCONN => error.SocketNotConnected,
else => |errno| posix.unexpectedErrno(errno),
},
},

.timer => |*op| timer: {
const e = @as(posix.E, @enumFromInt(-res));
const e = @as(posix.E, @fromBackingInt(@intCast(-res)));

// If we have reset set, that means that we were canceled so
// that we can update our expiration time.
Expand All @@ -763,7 +763,7 @@ pub const Completion = struct {
},

.timer_remove => .{
.timer_remove = if (res >= 0) {} else switch (@as(posix.E, @enumFromInt(-res))) {
.timer_remove = if (res >= 0) {} else switch (@as(posix.E, @fromBackingInt(@intCast(-res)))) {
.NOENT => error.NotFound,
.BUSY => error.ExpirationInProgress,

Expand All @@ -781,7 +781,7 @@ pub const Completion = struct {
.write => .{
.write = if (res >= 0)
@intCast(res)
else switch (@as(posix.E, @enumFromInt(-res))) {
else switch (@as(posix.E, @fromBackingInt(@intCast(-res)))) {
.CANCELED => error.Canceled,
// If a write is interrupted, we retry it automatically.
.INTR => return .rearm,
Expand All @@ -792,7 +792,7 @@ pub const Completion = struct {
.pwrite => .{
.pwrite = if (res >= 0)
@intCast(res)
else switch (@as(posix.E, @enumFromInt(-res))) {
else switch (@as(posix.E, @fromBackingInt(@intCast(-res)))) {
.CANCELED => error.Canceled,
// If a write is interrupted, we retry it automatically.
.INTR => return .rearm,
Expand All @@ -801,7 +801,7 @@ pub const Completion = struct {
},

.cancel => .{
.cancel = if (res >= 0) {} else switch (@as(posix.E, @enumFromInt(-res))) {
.cancel = if (res >= 0) {} else switch (@as(posix.E, @fromBackingInt(@intCast(-res)))) {
.NOENT => error.NotFound,
.ALREADY => error.ExpirationInProgress,
else => |errno| posix.unexpectedErrno(errno),
Expand Down Expand Up @@ -829,7 +829,7 @@ pub const Completion = struct {
};
}

return switch (@as(posix.E, @enumFromInt(-res))) {
return switch (@as(posix.E, @fromBackingInt(@intCast(-res)))) {
.CANCELED => error.Canceled,
.CONNRESET => error.ConnectionResetByPeer,
else => |errno| posix.unexpectedErrno(errno),
Expand Down
2 changes: 1 addition & 1 deletion src/backend/iocp.zig
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ pub const Loop = struct {
const completion: *Completion = @ptrFromInt(entry.lpCompletionKey);
completion.result = .{ .job_object = .{
.message = .{
.type = @enumFromInt(entry.dwNumberOfBytesTransferred),
.type = @fromBackingInt(@intCast(entry.dwNumberOfBytesTransferred)),
.value = @intFromPtr(entry.lpOverlapped),
},
} };
Expand Down
10 changes: 5 additions & 5 deletions src/backend/kqueue.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1292,7 +1292,7 @@ pub const Completion = struct {
/// in the situation that kqueue fails to enqueue the completion or
/// a raw syscall fails.
fn syscall_result(c: *Completion, r: i32) Result {
const errno: posix.E = if (r >= 0) .SUCCESS else @enumFromInt(-r);
const errno: posix.E = if (r >= 0) .SUCCESS else @fromBackingInt(@intCast(-r));
return switch (c.op) {
.noop => unreachable,

Expand Down Expand Up @@ -1553,7 +1553,7 @@ fn getsockoptError(socket: posix.socket_t) ConnectError!void {
}

if (err_code == 0) return;
return switch (@as(posix.E, @enumFromInt(@as(u16, @intCast(err_code))))) {
return switch (@as(posix.E, @fromBackingInt(@intCast(@as(u16, @intCast(err_code)))))) {
.ADDRNOTAVAIL => error.AddressUnavailable,
.AFNOSUPPORT => error.AddressFamilyUnsupported,
.ACCES, .PERM => error.AccessDenied,
Expand Down Expand Up @@ -1926,7 +1926,7 @@ fn kevent_syscall(

/// Converts a posix errno to the negative i32 format expected by syscall_result.
inline fn errno_to_result(errno: posix.E) i32 {
return -@as(i32, @intCast(@intFromEnum(errno)));
return -@as(i32, @intCast(@backingInt(errno)));
}

/// kevent_init initializes a Kevent from a std.c.Kevent. This is used when
Expand Down Expand Up @@ -2714,7 +2714,7 @@ test "kqueue: mach port" {

// Send a message to the port
var msg: darwin.mach_msg_header_t = .{
.msgh_bits = @intFromEnum(posix.system.MACH.MSG.TYPE.MAKE_SEND_ONCE),
.msgh_bits = @backingInt(posix.system.MACH.MSG.TYPE.MAKE_SEND_ONCE),
.msgh_size = @sizeOf(darwin.mach_msg_header_t),
.msgh_remote_port = mach_port,
.msgh_local_port = darwin.MACH_PORT_NULL,
Expand Down Expand Up @@ -2829,7 +2829,7 @@ test "kqueue: timer armed from delayed callback must not fire early" {
) catch unreachable;

var msg: darwin.mach_msg_header_t = .{
.msgh_bits = @intFromEnum(posix.system.MACH.MSG.TYPE.MAKE_SEND_ONCE),
.msgh_bits = @backingInt(posix.system.MACH.MSG.TYPE.MAKE_SEND_ONCE),
.msgh_size = @sizeOf(darwin.mach_msg_header_t),
.msgh_remote_port = port,
.msgh_local_port = darwin.MACH_PORT_NULL,
Expand Down
2 changes: 0 additions & 2 deletions src/bench/ping-pongs.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ const Allocator = std.mem.Allocator;
const xev = @import("xev");
//const xev = @import("xev").Dynamic;



pub const std_options: std.Options = .{
.log_level = .info,
};
Expand Down
4 changes: 2 additions & 2 deletions src/darwin.zig
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub extern "c" fn mach_msg(
) std.c.kern_return_t;

pub fn getKernError(err: std.c.kern_return_t) KernE {
return @as(KernE, @enumFromInt(@as(u32, @truncate(@as(usize, @intCast(err))))));
return @as(KernE, @fromBackingInt(@intCast(@as(u32, @truncate(@as(usize, @intCast(err)))))));
}

/// Kernel return values
Expand Down Expand Up @@ -291,7 +291,7 @@ pub const KernE = enum(u32) {
};

pub fn getMachMsgError(err: mach_msg_return_t) MachMsgE {
return @as(MachMsgE, @enumFromInt(@as(u32, @truncate(@as(usize, @intCast(err))))));
return @as(MachMsgE, @fromBackingInt(@intCast(@as(u32, @truncate(@as(usize, @intCast(err)))))));
}

/// Mach msg return values
Expand Down
10 changes: 5 additions & 5 deletions src/dynamic.zig
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ pub fn Xev(comptime bes: []const AllBackend) type {

/// Helpers to convert between the subset/superset of backends.
pub fn subset(comptime be: AllBackend) Backend {
return @enumFromInt(@intFromEnum(be));
return @fromBackingInt(@intCast(@backingInt(be)));
}

pub fn superset(comptime be: Backend) AllBackend {
return @enumFromInt(@intFromEnum(be));
return @fromBackingInt(@intCast(@backingInt(be)));
}

pub fn Union(comptime field: []const []const u8) type {
Expand Down Expand Up @@ -208,7 +208,7 @@ pub fn Xev(comptime bes: []const AllBackend) type {
const testing = std.testing;
try detect();
inline for (bes) |be| {
if (@intFromEnum(be) == @intFromEnum(backend)) {
if (@backingInt(be) == @backingInt(backend)) {
try testing.expect(be.Api().available());
break;
}
Expand All @@ -219,7 +219,7 @@ pub fn Xev(comptime bes: []const AllBackend) type {
const testing = std.testing;
try testing.expect(prefer(bes[0]));
inline for (bes) |be| {
if (@intFromEnum(be) == @intFromEnum(backend)) {
if (@backingInt(be) == @backingInt(backend)) {
try testing.expect(be.Api().available());
break;
}
Expand Down Expand Up @@ -432,7 +432,7 @@ fn EnumSubset(comptime T: type, comptime values: []const T) type {
var field_values: [values.len]tag_type = undefined;
for (values, 0..) |value, i| {
field_names[i] = @tagName(value);
field_values[i] = @intFromEnum(value);
field_values[i] = @backingInt(value);
}

return @Enum(tag_type, .exhaustive, &field_names, &field_values);
Expand Down
Loading