Skip to content

Instantly share code, notes, and snippets.

@bus710
Last active March 12, 2025 01:29
Show Gist options
  • Save bus710/351202009ab2a040ae0b0308bb3f2f4a to your computer and use it in GitHub Desktop.
Save bus710/351202009ab2a040ae0b0308bb3f2f4a to your computer and use it in GitHub Desktop.
How to use libxev with Zig 0.14 based project

How to use libxev with Zig 0.14 based project

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.

Steps

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:

.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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment