Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to latest zig #96

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 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,19 +146,18 @@ 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",
);
b.getInstallStep().dependOn(&c_header.step);

// pkg-config
{
const file = try b.cache_root.join(b.allocator, &[_][]const u8{"libxev.pc"});
const pkgconfig_file = try std.fs.cwd().createFile(file, .{});

const writer = pkgconfig_file.writer();
try writer.print(
const files = b.addWriteFiles();
var buf: [4064]u8 = undefined;
var fbs = std.io.fixedBufferStream(&buf);
try fbs.writer().print(
\\prefix={s}
\\includedir=${{prefix}}/include
\\libdir=${{prefix}}/lib
Expand All @@ -170,10 +169,11 @@ pub fn build(b: *std.Build) !void {
\\Cflags: -I${{includedir}}
\\Libs: -L${{libdir}} -lxev
, .{b.install_prefix});
defer pkgconfig_file.close();

const pc_path = files.add("libxec.pv", fbs.getWritten());

b.getInstallStep().dependOn(&b.addInstallFileWithDir(
.{ .path = file },
pc_path,
.prefix,
"share/pkgconfig/libxev.pc",
).step);
Expand Down Expand Up @@ -218,7 +218,7 @@ fn benchTargets(
// Name of the app and full path to the entrypoint.
const name = entry.name[0..index];
const path = try std.fs.path.join(b.allocator, &[_][]const u8{
c_dir_path,
"src/bench",
entry.name,
});

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 = b.path(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 = b.path(path),
.flags = &[_][]const u8{
"-Wall",
"-Wextra",
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

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

79 changes: 40 additions & 39 deletions src/backend/wasi_poll.zig
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,10 @@ pub const Loop = struct {
self.batch.array[0] = .{
.userdata = 0,
.u = .{
.tag = wasi.EVENTTYPE_CLOCK,
.tag = wasi.eventtype_t.CLOCK,
.u = .{
.clock = .{
.id = @as(u32, @bitCast(posix.CLOCK.MONOTONIC)),
.id = posix.CLOCK.MONOTONIC,
.timeout = timeout,
.precision = 1 * std.time.ns_per_ms,
.flags = wasi.SUBSCRIPTION_CLOCK_ABSTIME,
Expand Down Expand Up @@ -363,9 +363,9 @@ pub const Loop = struct {

.shutdown => |v| res: {
const how: wasi.sdflags_t = switch (v.how) {
.both => wasi.SHUT.WR | wasi.SHUT.RD,
.recv => wasi.SHUT.RD,
.send => wasi.SHUT.WR,
.both => .{ .RD = true, .WR = true },
.recv => .{ .RD = true },
.send => .{ .WR = true },
};

break :res .{
Expand Down Expand Up @@ -569,7 +569,7 @@ pub const Loop = struct {
fn timer_next(next_ms: u64) wasi.timestamp_t {
// Get the absolute time we'll execute this timer next.
var now_ts: wasi.timestamp_t = undefined;
switch (wasi.clock_time_get(@as(u32, @bitCast(posix.CLOCK.MONOTONIC)), 1, &now_ts)) {
switch (wasi.clock_time_get(posix.CLOCK.MONOTONIC, 1, &now_ts)) {
.SUCCESS => {},
.INVAL => unreachable,
else => unreachable,
Expand All @@ -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 @@ -654,7 +654,7 @@ pub const Completion = struct {
.read => |v| .{
.userdata = @intFromPtr(self),
.u = .{
.tag = wasi.EVENTTYPE_FD_READ,
.tag = wasi.eventtype_t.FD_READ,
.u = .{
.fd_read = .{
.fd = v.fd,
Expand All @@ -666,7 +666,7 @@ pub const Completion = struct {
.pread => |v| .{
.userdata = @intFromPtr(self),
.u = .{
.tag = wasi.EVENTTYPE_FD_READ,
.tag = wasi.eventtype_t.FD_READ,
.u = .{
.fd_read = .{
.fd = v.fd,
Expand All @@ -678,7 +678,7 @@ pub const Completion = struct {
.write => |v| .{
.userdata = @intFromPtr(self),
.u = .{
.tag = wasi.EVENTTYPE_FD_WRITE,
.tag = wasi.eventtype_t.FD_READ,
.u = .{
.fd_write = .{
.fd = v.fd,
Expand All @@ -690,7 +690,7 @@ pub const Completion = struct {
.pwrite => |v| .{
.userdata = @intFromPtr(self),
.u = .{
.tag = wasi.EVENTTYPE_FD_WRITE,
.tag = wasi.eventtype_t.FD_WRITE,
.u = .{
.fd_write = .{
.fd = v.fd,
Expand All @@ -702,7 +702,7 @@ pub const Completion = struct {
.accept => |v| .{
.userdata = @intFromPtr(self),
.u = .{
.tag = wasi.EVENTTYPE_FD_READ,
.tag = wasi.eventtype_t.FD_READ,
.u = .{
.fd_read = .{
.fd = v.socket,
Expand All @@ -714,7 +714,7 @@ pub const Completion = struct {
.recv => |v| .{
.userdata = @intFromPtr(self),
.u = .{
.tag = wasi.EVENTTYPE_FD_READ,
.tag = wasi.eventtype_t.FD_READ,
.u = .{
.fd_read = .{
.fd = v.fd,
Expand All @@ -726,7 +726,7 @@ pub const Completion = struct {
.send => |v| .{
.userdata = @intFromPtr(self),
.u = .{
.tag = wasi.EVENTTYPE_FD_WRITE,
.tag = wasi.eventtype_t.FD_WRITE,
.u = .{
.fd_write = .{
.fd = v.fd,
Expand Down Expand Up @@ -762,7 +762,7 @@ pub const Completion = struct {
.accept => |*op| res: {
var out_fd: posix.fd_t = undefined;
break :res .{
.accept = switch (wasi.sock_accept(op.socket, 0, &out_fd)) {
.accept = switch (wasi.sock_accept(op.socket, .{}, &out_fd)) {
.SUCCESS => out_fd,
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 Expand Up @@ -1513,22 +1513,23 @@ test "wasi: file" {
// We can't use dir.createFile yet: https://github.com/ziglang/zig/issues/14324
const f = f: {
const w = wasi;
const oflags = w.O.CREAT | w.O.TRUNC;
const base: w.rights_t = w.RIGHT.FD_WRITE |
w.RIGHT.FD_READ |
w.RIGHT.FD_DATASYNC |
w.RIGHT.FD_SEEK |
w.RIGHT.FD_TELL |
w.RIGHT.FD_FDSTAT_SET_FLAGS |
w.RIGHT.FD_SYNC |
w.RIGHT.FD_ALLOCATE |
w.RIGHT.FD_ADVISE |
w.RIGHT.FD_FILESTAT_SET_TIMES |
w.RIGHT.FD_FILESTAT_SET_SIZE |
w.RIGHT.FD_FILESTAT_GET |
w.RIGHT.POLL_FD_READWRITE;
const fdflags: w.fdflags_t = w.FDFLAG.SYNC | w.FDFLAG.RSYNC | w.FDFLAG.DSYNC;
const fd = try posix.openatWasi(dir.fd, path, 0x0, oflags, 0x0, base, fdflags);
const oflags = w.oflags_t{ .CREAT = true, .TRUNC = true };
const base = w.rights_t{
.FD_WRITE = true,
.FD_READ = true,
.FD_DATASYNC = true,
.FD_SEEK = true,
.FD_TELL = true,
.FD_FDSTAT_SET_FLAGS = true,
.FD_SYNC = true,
.FD_ALLOCATE = true,
.FD_ADVISE = true,
.FD_FILESTAT_SET_TIMES = true,
.FD_FILESTAT_SET_SIZE = true,
.FD_FILESTAT_GET = true,
.POLL_FD_READWRITE = true,
};
const fd = try posix.openatWasi(dir.fd, path, .{}, oflags, .{}, base, base);
break :f std.fs.File{ .handle = fd };
};
defer dir.deleteFile(path) catch unreachable;
Expand Down
2 changes: 1 addition & 1 deletion src/build/ScdocStep.zig
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ const InstallStep = struct {
);

const fileStep = self.builder.addInstallFile(
.{ .path = src },
self.builder.path(src),
output,
);
try fileStep.step.make(progress);
Expand Down