The libxev is a library that is somewhat similar to libuv for NodeJS - async I/O event loop for C and Zig.
With the recent stable release of Zig 0.14, there was a small breaking change in the build.zig, so the previously introduced way doesn't work.
To make it clear here is a step by step note.
First of all, create a new Zig project:
$ mkdir blink && cd blink
$ zig init
Open the build.zig.zon
file, and add the libxev lines in the dependencies block:
- The URL can be found from the https://github.com/mitchellh/libxev/commits/main/
- The hash can be empty, but running
zig build
tells us
.dependencies = .{
.libxev = .{
.url = "https://github.com/mitchellh/libxev/archive/3df9337a9e84450a58a2c4af434ec1a036f7b494.tar.gz",
.hash = "libxev-0.0.0-86vtc-ziEgDbLP0vihUn1MhsxNKY4GJEga6BEr7oyHpz",
},
},
Then open the build.zig
file, and add these lines:
- The addExecutable line should exist, so the 2 lines below are the new ones to add.
const exe = b.addExecutable(.{
.name = "blink",
.root_module = exe_mod,
});
const xev = b.dependency("libxev", .{ .target = target, .optimize = optimize });
exe.root_module.addImport("xev", xev.module("xev"));
Lastly open the src/main.zig
file, and replace the contents with the basic timer example from the libxev repo.