Skip to content

Commit

Permalink
fix: update to zig 0.13 (#99)
Browse files Browse the repository at this point in the history
this PR allows libxev to compile with zig version 0.13. I'm a little
unsure about the one instance where on my machine I had to use `.{
.cwd_relative = file }` rather than `b.path(file)` for the pkg-config
`.pc` file install step.
  • Loading branch information
mitchellh committed Jun 9, 2024
2 parents 1b42563 + 25da0a6 commit f6a672a
Show file tree
Hide file tree
Showing 22 changed files with 109 additions and 92 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
x86_64-linux-musl,
aarch64-macos,
x86_64-macos,
wasm32-wasi,
# wasm32-wasi, - regressed in Zig 0.13
x86_64-windows-gnu

# Broken but not in any obvious way:
Expand Down Expand Up @@ -67,8 +67,9 @@ jobs:
# will ensure we have all our dependencies.
- name: test
run: nix develop -c zig build test --summary all
- name: test wasi
run: nix develop -c zig build test -Dtarget=wasm32-wasi -fwasmtime --summary all
# WASI has regressed since Zig 0.13, we should fix it.
# - name: test wasi
# run: nix develop -c zig build test -Dtarget=wasm32-wasi -fwasmtime --summary all

- name: build all benchmarks and examples
run: nix develop -c zig build -Dexample -Dbench --summary all
Expand All @@ -91,7 +92,7 @@ jobs:
- name: Install zig
uses: goto-bus-stop/setup-zig@v2
with:
version: 0.12.0-dev.2058+04ac028a2
version: 0.13.0

- name: test
run: zig build test --summary all
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
zig-cache
.zig-cache
zig-out
32 changes: 16 additions & 16 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 = .{ .path = "src/main.zig" } });
_ = b.addModule("xev", .{ .root_source_file = b.path("src/main.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 = .{ .path = "src/main.zig" },
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
Expand All @@ -76,7 +76,7 @@ pub fn build(b: *std.Build) !void {
const static_c_lib: ?*std.Build.Step.Compile = if (target.result.os.tag != .wasi) lib: {
const static_lib = b.addStaticLibrary(.{
.name = "xev",
.root_source_file = .{ .path = "src/c_api.zig" },
.root_source_file = b.path("src/c_api.zig"),
.target = target,
.optimize = optimize,
});
Expand All @@ -98,9 +98,9 @@ pub fn build(b: *std.Build) !void {
.optimize = optimize,
});
static_binding_test.linkLibC();
static_binding_test.addIncludePath(.{ .path = "include" });
static_binding_test.addIncludePath(b.path("include"));
static_binding_test.addCSourceFile(.{
.file = .{ .path = "examples/_basic.c" },
.file = b.path("examples/_basic.c"),
.flags = &[_][]const u8{ "-Wall", "-Wextra", "-pedantic", "-std=c99", "-D_POSIX_C_SOURCE=199309L" },
});
static_binding_test.linkLibrary(static_lib);
Expand All @@ -119,7 +119,7 @@ pub fn build(b: *std.Build) !void {

const dynamic_lib = b.addSharedLibrary(.{
.name = dynamic_lib_name,
.root_source_file = .{ .path = "src/c_api.zig" },
.root_source_file = b.path("src/c_api.zig"),
.target = target,
.optimize = optimize,
});
Expand All @@ -132,9 +132,9 @@ pub fn build(b: *std.Build) !void {
.optimize = optimize,
});
dynamic_binding_test.linkLibC();
dynamic_binding_test.addIncludePath(.{ .path = "include" });
dynamic_binding_test.addIncludePath(b.path("include"));
dynamic_binding_test.addCSourceFile(.{
.file = .{ .path = "examples/_basic.c" },
.file = b.path("examples/_basic.c"),
.flags = &[_][]const u8{ "-Wall", "-Wextra", "-pedantic", "-std=c99" },
});
dynamic_binding_test.linkLibrary(dynamic_lib);
Expand All @@ -146,7 +146,7 @@ pub fn build(b: *std.Build) !void {

// C Headers
const c_header = b.addInstallFileWithDir(
.{ .path = "include/xev.h" },
b.path("include/xev.h"),
.header,
"xev.h",
);
Expand All @@ -173,7 +173,7 @@ pub fn build(b: *std.Build) !void {
defer pkgconfig_file.close();

b.getInstallStep().dependOn(&b.addInstallFileWithDir(
.{ .path = file },
.{ .cwd_relative = file },
.prefix,
"share/pkgconfig/libxev.pc",
).step);
Expand Down Expand Up @@ -204,8 +204,8 @@ fn benchTargets(
var map = std.StringHashMap(*std.Build.Step.Compile).init(b.allocator);

// Open the directory
const c_dir_path = (comptime thisDir()) ++ "/src/bench";
var c_dir = try std.fs.cwd().openDir(c_dir_path, .{ .iterate = true });
const c_dir_path = "src/bench";
var c_dir = try std.fs.cwd().openDir(comptime thisDir() ++ "/" ++ c_dir_path, .{ .iterate = true });
defer c_dir.close();

// Go through and add each as a step
Expand All @@ -230,7 +230,7 @@ fn benchTargets(
// Executable builder.
const c_exe = b.addExecutable(.{
.name = name,
.root_source_file = .{ .path = path },
.root_source_file = b.path(path),
.target = target,
.optimize = .ReleaseFast, // benchmarks are always release fast
});
Expand Down Expand Up @@ -288,7 +288,7 @@ fn exampleTargets(
if (is_zig) {
const c_exe = b.addExecutable(.{
.name = name,
.root_source_file = .{ .path = path },
.root_source_file = .{ .cwd_relative = path },
.target = target,
.optimize = optimize,
});
Expand All @@ -307,9 +307,9 @@ fn exampleTargets(
.optimize = optimize,
});
c_exe.linkLibC();
c_exe.addIncludePath(.{ .path = "include" });
c_exe.addIncludePath(b.path("include"));
c_exe.addCSourceFile(.{
.file = .{ .path = path },
.file = .{ .cwd_relative = path },
.flags = &[_][]const u8{
"-Wall",
"-Wextra",
Expand Down
52 changes: 35 additions & 17 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
description = "libxev is a high performance, cross-platform event loop.";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/release-23.05";
nixpkgs.url = "github:nixos/nixpkgs/release-24.05";
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
zig.url = "github:mitchellh/zig-overlay";
Expand All @@ -24,7 +24,7 @@
# Other overlays
(final: prev: rec {
zigpkgs = inputs.zig.packages.${prev.system};
zig = zigpkgs.master;
zig = inputs.zig.packages.${prev.system}."0.13.0";

# Latest versions
wasmtime = inputs.nixpkgs-unstable.legacyPackages.${prev.system}.wasmtime;
Expand All @@ -46,7 +46,7 @@
nativeBuildInputs = with pkgs; [
mandoc
scdoc
zigpkgs.master
zig

# Wasm
wabt
Expand Down
4 changes: 2 additions & 2 deletions src/backend/io_uring.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1604,7 +1604,7 @@ test "io_uring: sendmsg/recvmsg" {
// Send
const buffer_send = [_]u8{42} ** 128;
const iovecs_send = [_]os.iovec_const{
os.iovec_const{ .iov_base = &buffer_send, .iov_len = buffer_send.len },
os.iovec_const{ .base = &buffer_send, .len = buffer_send.len },
};
var msg_send = os.msghdr_const{
.name = &address.any,
Expand Down Expand Up @@ -1639,7 +1639,7 @@ test "io_uring: sendmsg/recvmsg" {

var buffer_recv = [_]u8{0} ** 128;
var iovecs_recv = [_]os.iovec{
os.iovec{ .iov_base = &buffer_recv, .iov_len = buffer_recv.len },
os.iovec{ .base = &buffer_recv, .len = buffer_recv.len },
};
const addr = [_]u8{0} ** 4;
var address_recv = net.Address.initIp4(addr, 0);
Expand Down
18 changes: 9 additions & 9 deletions src/backend/wasi_poll.zig
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ pub const Loop = struct {

fn get_now() !wasi.timestamp_t {
var ts: wasi.timestamp_t = undefined;
return switch (wasi.clock_time_get(@as(u32, @bitCast(posix.CLOCK.MONOTONIC)), 1, &ts)) {
return switch (wasi.clock_time_get(posix.CLOCK.MONOTONIC, 1, &ts)) {
.SUCCESS => ts,
.INVAL => error.UnsupportedClock,
else => |err| posix.unexpectedErrno(err),
Expand Down Expand Up @@ -825,8 +825,8 @@ pub const Completion = struct {
const errno = switch (op.buffer) {
.slice => |v| slice: {
var iovs = [1]posix.iovec{posix.iovec{
.iov_base = v.ptr,
.iov_len = v.len,
.base = v.ptr,
.len = v.len,
}};

break :slice wasi.sock_recv(
Expand All @@ -841,8 +841,8 @@ pub const Completion = struct {

.array => |*v| array: {
var iovs = [1]posix.iovec{posix.iovec{
.iov_base = v,
.iov_len = v.len,
.base = v,
.len = v.len,
}};

break :array wasi.sock_recv(
Expand All @@ -869,8 +869,8 @@ pub const Completion = struct {
const errno = switch (op.buffer) {
.slice => |v| slice: {
var iovs = [1]posix.iovec_const{posix.iovec_const{
.iov_base = v.ptr,
.iov_len = v.len,
.base = v.ptr,
.len = v.len,
}};

break :slice wasi.sock_send(
Expand All @@ -884,8 +884,8 @@ pub const Completion = struct {

.array => |*v| array: {
var iovs = [1]posix.iovec_const{posix.iovec_const{
.iov_base = &v.array,
.iov_len = v.len,
.base = &v.array,
.len = v.len,
}};

break :array wasi.sock_send(
Expand Down
4 changes: 2 additions & 2 deletions src/bench/async1.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const Allocator = std.mem.Allocator;
const Instant = std.time.Instant;
const xev = @import("xev");

pub const std_options = struct {
pub const log_level: std.log.Level = .info;
pub const std_options: std.Options = .{
.log_level = .info,
};

// Tune-ables
Expand Down
4 changes: 2 additions & 2 deletions src/bench/async2.zig
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const std = @import("std");
const run = @import("async1.zig").run;

pub const std_options = struct {
pub const log_level: std.log.Level = .info;
pub const std_options: std.Options = .{
.log_level = .info,
};

pub fn main() !void {
Expand Down
4 changes: 2 additions & 2 deletions src/bench/async4.zig
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const std = @import("std");
const run = @import("async1.zig").run;

pub const std_options = struct {
pub const log_level: std.log.Level = .info;
pub const std_options: std.Options = .{
.log_level = .info,
};

pub fn main() !void {
Expand Down
Loading

0 comments on commit f6a672a

Please sign in to comment.