Skip to content

feat: xev Dynamic API + gitignore updates for Shadow support#704

Open
GrapeBaBa wants to merge 2 commits intomainfrom
shadow-to-main
Open

feat: xev Dynamic API + gitignore updates for Shadow support#704
GrapeBaBa wants to merge 2 commits intomainfrom
shadow-to-main

Conversation

@GrapeBaBa
Copy link
Copy Markdown
Member

Summary

  • Switch xev from compile-time backend selection to Dynamic API for runtime io_uring/epoll detection
  • This makes the binary portable across Linux kernel versions and Shadow-compatible
  • Add gitignore entries for zig-pkg/ cache, Shadow simulator outputs, and IDE files

Details

xev Dynamic API

All @import("xev") changed to @import("xev").Dynamic, which probes io_uring at runtime and falls back to epoll. A detectBackend() helper in utils.zig is called early in main and in test setup.

gitignore

  • zig-pkg/ — local Zig package cache (should not be committed)
  • shadow.yaml, shadow.data/ — generated by lean-quickstart/run-shadow.sh
  • .idea/ — JetBrains IDE files

Test plan

  • Verify build passes on CI
  • Verify existing tests pass
  • Verify Shadow 4-node devnet works with lean-quickstart/run-shadow.sh

Copilot AI review requested due to automatic review settings April 2, 2026 14:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Zig codebase to use libxev’s Dynamic API so the runtime can select the best available I/O backend (io_uring vs epoll), improving portability across Linux kernel versions and compatibility with Shadow. It also updates .gitignore to exclude additional local/tool-generated artifacts.

Changes:

  • Switched @import("xev") usages to @import("xev").Dynamic across node, network, and CLI code.
  • Added a detectBackend() helper and invoked it early in CLI startup and node test initialization.
  • Updated .gitignore to ignore zig-pkg/, Shadow outputs, and .idea/.

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
pkgs/node/src/utils.zig Introduces detectBackend() and moves node code to xev.Dynamic.
pkgs/node/src/testing.zig Calls backend detection before initializing the event loop in tests.
pkgs/node/src/node.zig Switches xev import for tests to xev.Dynamic.
pkgs/node/src/lib.zig Re-exports detectBackend for external callers (CLI).
pkgs/node/src/clock.zig Switches xev import to xev.Dynamic.
pkgs/network/src/mock.zig Switches to xev.Dynamic and adds backend detection in tests.
pkgs/network/src/interface.zig Switches xev import to xev.Dynamic.
pkgs/network/src/ethlibp2p.zig Switches xev import to xev.Dynamic.
pkgs/cli/src/node.zig Switches xev import to xev.Dynamic.
pkgs/cli/src/main.zig Calls node_lib.detectBackend() early during CLI startup.
build.zig Notes that xev backend override is no longer needed.
.gitignore Ignores zig-pkg/, Shadow outputs, and JetBrains IDE files.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

/// On single-backend platforms (macOS/kqueue) this is a no-op.
pub fn detectBackend() void {
if (@hasDecl(xev, "detect")) {
xev.detect() catch @panic("no available xev backend");
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

xev.detect() failures are turned into a generic @panic("no available xev backend"), which drops the underlying error and makes field debugging hard (e.g., missing io_uring support vs. permission issues). Consider including the caught error (e.g., @errorName(err) / {any}) in the panic message or returning an error instead of panicking so callers can surface it consistently.

Suggested change
xev.detect() catch @panic("no available xev backend");
xev.detect() catch |err| std.debug.panic("no available xev backend: {s}", .{@errorName(err)});

Copilot uses AI. Check for mistakes.
Comment on lines +777 to 778
if (@hasDecl(xev, "detect")) xev.detect() catch @panic("no available xev backend");
var loop = try xev.Loop.init(.{});
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

This if (@hasDecl(xev, "detect")) xev.detect() ... backend-detection snippet is duplicated in multiple tests in this file. Consider factoring it into a small local helper (e.g., detectBackendOrPanic()), so the behavior/error handling stays consistent and future changes only need to be made once.

Copilot uses AI. Check for mistakes.
Comment on lines +958 to 960
if (@hasDecl(xev, "detect")) xev.detect() catch @panic("no available xev backend");
var loop = try xev.Loop.init(.{});
defer loop.deinit();
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

This backend detection line duplicates the same xev.detect() snippet used earlier in this file. To reduce repetition (and keep the panic/error message consistent), consider extracting the detection into a single helper and calling it from each test before xev.Loop.init.

Copilot uses AI. Check for mistakes.
std.debug.print("opts={any} genesis={d}\n", .{ opts.args, genesis });

// Detect the best available I/O backend (io_uring or epoll on Linux).
node_lib.detectBackend();
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

node_lib.detectBackend() currently panics on failure (see utils.detectBackend), which bypasses the CLI’s normal ErrorHandler flow and will crash the process with a generic message. Consider changing detection to return an error and handling/logging it here (similar to the xev.Loop.init error handling below) so startup failures are reported consistently.

Suggested change
node_lib.detectBackend();
node_lib.detectBackend() catch |err| {
ErrorHandler.logErrorWithOperation(err, "detect I/O backend");
return err;
};

Copilot uses AI. Check for mistakes.
Switch from compile-time xev backend selection to the Dynamic API,
which probes io_uring at runtime and falls back to epoll. This is
needed for Shadow network simulator (no io_uring support) but also
makes the binary portable across Linux kernel versions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants