Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: delete all non-test uses of usingnamespace #118

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

_ = b.addModule("xev", .{ .root_source_file = b.path("src/main.zig") });
_ = b.addModule("xev", .{ .root_source_file = b.path("src/lib.zig") });

const man_pages = b.option(
bool,
Expand Down Expand Up @@ -60,7 +60,7 @@ pub fn build(b: *std.Build) !void {
// we can easily run it manually without digging through the cache.
const test_exe = b.addTest(.{
.name = "xev-test",
.root_source_file = b.path("src/main.zig"),
.root_source_file = b.path("src/lib.zig"),
.target = target,
.optimize = optimize,
});
Expand Down
2 changes: 1 addition & 1 deletion src/backend/epoll.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const posix = std.posix;
const queue = @import("../queue.zig");
const queue_mpsc = @import("../queue_mpsc.zig");
const heap = @import("../heap.zig");
const main = @import("../main.zig");
const main = @import("../lib.zig");
const xev = main.Epoll;
const ThreadPool = main.ThreadPool;

Expand Down
2 changes: 1 addition & 1 deletion src/backend/io_uring.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const assert = std.debug.assert;
const linux = std.os.linux;
const posix = std.posix;
const queue = @import("../queue.zig");
const xev = @import("../main.zig").IO_Uring;
const xev = @import("../lib.zig").IO_Uring;

pub const Loop = struct {
ring: linux.IoUring,
Expand Down
2 changes: 1 addition & 1 deletion src/backend/iocp.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const assert = std.debug.assert;
const windows = @import("../windows.zig");
const queue = @import("../queue.zig");
const heap = @import("../heap.zig");
const xev = @import("../main.zig").IOCP;
const xev = @import("../lib.zig").IOCP;
const posix = std.posix;

const log = std.log.scoped(.libxev_iocp);
Expand Down
2 changes: 1 addition & 1 deletion src/backend/kqueue.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const posix = std.posix;
const queue = @import("../queue.zig");
const queue_mpsc = @import("../queue_mpsc.zig");
const heap = @import("../heap.zig");
const main = @import("../main.zig");
const main = @import("../lib.zig");
const xev = main.Kqueue;
const ThreadPool = main.ThreadPool;

Expand Down
2 changes: 1 addition & 1 deletion src/backend/wasi_poll.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const wasi = std.os.wasi;
const posix = std.posix;
const queue = @import("../queue.zig");
const heap = @import("../heap.zig");
const xev = @import("../main.zig").WasiPoll;
const xev = @import("../lib.zig").WasiPoll;

pub const Loop = struct {
pub const threaded = std.Target.wasm.featureSetHas(builtin.cpu.features, .atomics);
Expand Down
2 changes: 1 addition & 1 deletion src/c_api.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
const std = @import("std");
const builtin = @import("builtin");
const assert = std.debug.assert;
const xev = @import("main.zig");
const xev = @import("lib.zig");

export fn xev_loop_init(loop: *xev.Loop) c_int {
// TODO: overflow
Expand Down
137 changes: 137 additions & 0 deletions src/lib.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
const std = @import("std");
const builtin = @import("builtin");

pub const Xev = @import("xev.zig").Xev;

/// System-specific interfaces. Note that they are always pub for
/// all systems but if you reference them and force them to be analyzed
/// the proper system APIs must exist. Due to Zig's lazy analysis, if you
/// don't use any interface it will NOT be compiled (yay!).
pub const IO_Uring = Xev(.io_uring, @import("backend/io_uring.zig"));
pub const Epoll = Xev(.epoll, @import("backend/epoll.zig"));
pub const Kqueue = Xev(.kqueue, @import("backend/kqueue.zig"));
pub const WasiPoll = Xev(.wasi_poll, @import("backend/wasi_poll.zig"));
pub const IOCP = Xev(.iocp, @import("backend/iocp.zig"));

/// Generic thread pool implementation.
pub const ThreadPool = @import("ThreadPool.zig");

/// This stream (lowercase s) can be used as a namespace to access
/// Closeable, Writeable, Readable, etc. so that custom streams
/// can be constructed.
pub const stream = @import("watcher/stream.zig");

/// The backend types.
pub const Backend = enum {
io_uring,
epoll,
kqueue,
wasi_poll,
iocp,

/// Returns a recommend default backend from inspecting the system.
pub fn default() Backend {
return @as(?Backend, switch (builtin.os.tag) {
.linux => .io_uring,
.ios, .macos => .kqueue,
.wasi => .wasi_poll,
.windows => .iocp,
else => null,
}) orelse {
@compileLog(builtin.os);
@compileError("no default backend for this target");
};
}

/// Returns the Api (return value of Xev) for the given backend type.
pub fn Api(comptime self: Backend) type {
return switch (self) {
.io_uring => IO_Uring,
.epoll => Epoll,
.kqueue => Kqueue,
.wasi_poll => WasiPoll,
.iocp => IOCP,
};
}
};

pub const backend = Backend.default();

const T = backend.Api();
pub const Sys = T.Sys;

const loop = @import("loop.zig");

/// The core loop APIs.
pub const Loop = Sys.Loop;
pub const Completion = Sys.Completion;
pub const Result = Sys.Result;
pub const ReadBuffer = Sys.ReadBuffer;
pub const WriteBuffer = Sys.WriteBuffer;
pub const Options = loop.Options;
pub const RunMode = loop.RunMode;
pub const CallbackAction = loop.CallbackAction;
pub const CompletionState = loop.CompletionState;

/// Error types
pub const AcceptError = Sys.AcceptError;
pub const CancelError = Sys.CancelError;
pub const CloseError = Sys.CloseError;
pub const ConnectError = Sys.ConnectError;
pub const ShutdownError = Sys.ShutdownError;
pub const WriteError = Sys.WriteError;
pub const ReadError = Sys.ReadError;

const Self = @This();

/// The high-level helper interfaces that make it easier to perform
/// common tasks. These may not work with all possible Loop implementations.
pub const Async = @import("watcher/async.zig").Async(Self);
pub const File = @import("watcher/file.zig").File(Self);
pub const Process = @import("watcher/process.zig").Process(Self);
pub const Stream = stream.GenericStream(Self);
pub const Timer = @import("watcher/timer.zig").Timer(Self);
pub const TCP = @import("watcher/tcp.zig").TCP(Self);
pub const UDP = @import("watcher/udp.zig").UDP(Self);

/// The callback of the main Loop operations. Higher level interfaces may
/// use a different callback mechanism.
pub const Callback = *const fn (
userdata: ?*anyopaque,
loop: *Loop,
completion: *Completion,
result: Result,
) CallbackAction;

pub const noopCallback = T.noopCallback;

test {
// Tested on all platforms
_ = @import("heap.zig");
_ = @import("queue.zig");
_ = @import("queue_mpsc.zig");
_ = ThreadPool;

// Test the C API
if (builtin.os.tag != .wasi) _ = @import("c_api.zig");

// OS-specific tests
switch (builtin.os.tag) {
.linux => {
_ = Epoll;
_ = IO_Uring;
_ = @import("linux/timerfd.zig");
},

.wasi => {
//_ = WasiPoll;
_ = @import("backend/wasi_poll.zig");
},

.windows => {
_ = @import("backend/iocp.zig");
},

else => {},
}
}
2 changes: 1 addition & 1 deletion src/loop.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

const std = @import("std");
const assert = std.debug.assert;
const xev = @import("main.zig");
const xev = @import("lib.zig");

/// Common options across backends. Not all options apply to all backends.
/// Read the doc comment for individual fields to learn what backends they
Expand Down
174 changes: 0 additions & 174 deletions src/main.zig

This file was deleted.

Loading
Loading