Skip to content

Zig bindings for libuv. Also a build script to build libuv from scratch using only Zig (for easy cross-compilation, integration with Zig, etc.).

License

Notifications You must be signed in to change notification settings

optimism-java/zig-libuv

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Forked this repo to upgrade the zig version to master. The original repo is here.


zig-libuv

zig-libuv contains a build.zig that can build libuv using Zig and also contains a package with Zig bindings. Both can be used together or separately. Building libuv with Zig enables easy cross-compilation. The bindings allow you to consume libuv easily whether it is built with Zig or not.

Example

There are lots of examples in the tests for each individual handle type. Below is an example of using a timer, copied exactly from the tests:

var loop = try Loop.init(testing.allocator);
defer loop.deinit(testing.allocator);

var timer = try init(testing.allocator, loop);
defer timer.deinit(testing.allocator);

var called: bool = false;
timer.setData(&called);
try timer.start((struct {
    fn callback(t: *Timer) void {
        t.getData(bool).?.* = true;
        t.close(null);
    }
}).callback, 10, 1000);

_ = try loop.run(.default);

try testing.expect(called);

Usage

To build libuv:

const libuv = @import("path/to/zig-libuv/build.zig");

pub fn build(b: *std.build.Builder) !void {
    // ...

    const exe = b.addExecutable("my-program", "src/main.zig");
    _ = libuv.link(b, exe);
}

To use the Zig bindings, add the package:

exe.addPackage(libuv.pkg);

About

Zig bindings for libuv. Also a build script to build libuv from scratch using only Zig (for easy cross-compilation, integration with Zig, etc.).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Zig 99.9%
  • Other 0.1%