Skip to content

Commit 08fa6ec

Browse files
RossComputerGuynikneym
authored andcommitted
fix: compatibility with 0.15
1 parent fbec5a8 commit 08fa6ec

File tree

2 files changed

+49
-32
lines changed

2 files changed

+49
-32
lines changed

build.zig

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,20 @@ pub fn build(b: *std.Build) !void {
3939
"Install the example binaries to zig-out",
4040
) orelse false;
4141

42+
const c_api_module = b.createModule(.{
43+
.root_source_file = b.path("src/c_api.zig"),
44+
.target = target,
45+
.optimize = optimize,
46+
});
47+
4248
// Static C lib
4349
const static_lib: ?*Step.Compile = lib: {
4450
if (target.result.os.tag == .wasi) break :lib null;
4551

46-
const static_lib = b.addStaticLibrary(.{
52+
const static_lib = b.addLibrary(.{
53+
.linkage = .static,
4754
.name = "xev",
48-
.root_source_file = b.path("src/c_api.zig"),
49-
.target = target,
50-
.optimize = optimize,
55+
.root_module = c_api_module,
5156
});
5257
static_lib.linkLibC();
5358
if (target.result.os.tag == .windows) {
@@ -62,11 +67,10 @@ pub fn build(b: *std.Build) !void {
6267
// We require native so we can link to libxml2
6368
if (!target.query.isNative()) break :lib null;
6469

65-
const dynamic_lib = b.addSharedLibrary(.{
70+
const dynamic_lib = b.addLibrary(.{
71+
.linkage = .dynamic,
6672
.name = "xev",
67-
.root_source_file = b.path("src/c_api.zig"),
68-
.target = target,
69-
.optimize = optimize,
73+
.root_module = c_api_module,
7074
});
7175
break :lib dynamic_lib;
7276
};
@@ -115,10 +119,12 @@ pub fn build(b: *std.Build) !void {
115119
);
116120
const test_exe = b.addTest(.{
117121
.name = "xev-test",
118-
.root_source_file = b.path("src/main.zig"),
119-
.target = target,
120-
.optimize = optimize,
121-
.filter = test_filter,
122+
.filters = if (test_filter) |filter| &.{filter} else &.{},
123+
.root_module = b.createModule(.{
124+
.root_source_file = b.path("src/main.zig"),
125+
.target = target,
126+
.optimize = optimize,
127+
}),
122128
});
123129
switch (target.result.os.tag) {
124130
.linux, .macos => test_exe.linkLibC(),
@@ -190,12 +196,14 @@ fn buildBenchmarks(
190196
// Executable builder.
191197
const exe = b.addExecutable(.{
192198
.name = name,
193-
.root_source_file = b.path(b.fmt(
194-
"src/bench/{s}",
195-
.{entry.name},
196-
)),
197-
.target = target,
198-
.optimize = .ReleaseFast, // benchmarks are always release fast
199+
.root_module = b.createModule(.{
200+
.root_source_file = b.path(b.fmt(
201+
"src/bench/{s}",
202+
.{entry.name},
203+
)),
204+
.target = target,
205+
.optimize = .ReleaseFast, // benchmarks are always release fast
206+
}),
199207
});
200208
exe.root_module.addImport("xev", b.modules.get("xev").?);
201209

@@ -239,21 +247,25 @@ fn buildExamples(
239247
const exe: *Step.Compile = if (is_zig) exe: {
240248
const exe = b.addExecutable(.{
241249
.name = name,
242-
.root_source_file = b.path(b.fmt(
243-
"examples/{s}",
244-
.{entry.name},
245-
)),
246-
.target = target,
247-
.optimize = optimize,
250+
.root_module = b.createModule(.{
251+
.root_source_file = b.path(b.fmt(
252+
"examples/{s}",
253+
.{entry.name},
254+
)),
255+
.target = target,
256+
.optimize = optimize,
257+
}),
248258
});
249259
exe.root_module.addImport("xev", b.modules.get("xev").?);
250260
break :exe exe;
251261
} else exe: {
252262
const c_lib = c_lib_ orelse return error.UnsupportedPlatform;
253263
const exe = b.addExecutable(.{
254264
.name = name,
255-
.target = target,
256-
.optimize = optimize,
265+
.root_module = b.createModule(.{
266+
.target = target,
267+
.optimize = optimize,
268+
}),
257269
});
258270
exe.linkLibC();
259271
exe.addIncludePath(b.path("include"));

src/c_api.zig

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ const builtin = @import("builtin");
1111
const assert = std.debug.assert;
1212
const xev = @import("main.zig");
1313

14+
const func_callconv: std.builtin.CallingConvention = if (blk: {
15+
const order = builtin.zig_version.order(.{ .major = 0, .minor = 14, .patch = 1 });
16+
break :blk order == .lt or order == .eq;
17+
}) .C else .c;
18+
1419
export fn xev_loop_init(loop: *xev.Loop) c_int {
1520
// TODO: overflow
1621
loop.* = xev.Loop.init(.{}) catch |err| return errorCode(err);
@@ -89,7 +94,7 @@ export fn xev_threadpool_schedule(
8994

9095
export fn xev_threadpool_task_init(
9196
t: *xev.ThreadPool.Task,
92-
cb: *const fn (*xev.ThreadPool.Task) callconv(.C) void,
97+
cb: *const fn (*xev.ThreadPool.Task) callconv(func_callconv) void,
9398
) void {
9499
const extern_t = @as(*Task, @ptrCast(@alignCast(t)));
95100
extern_t.c_callback = cb;
@@ -148,7 +153,7 @@ export fn xev_timer_run(
148153
*xev.Completion,
149154
c_int,
150155
?*anyopaque,
151-
) callconv(.C) xev.CallbackAction,
156+
) callconv(func_callconv) xev.CallbackAction,
152157
) void {
153158
const Callback = @typeInfo(@TypeOf(cb)).pointer.child;
154159
const extern_c = @as(*Completion, @ptrCast(@alignCast(c)));
@@ -188,7 +193,7 @@ export fn xev_timer_reset(
188193
*xev.Completion,
189194
c_int,
190195
?*anyopaque,
191-
) callconv(.C) xev.CallbackAction,
196+
) callconv(func_callconv) xev.CallbackAction,
192197
) void {
193198
const Callback = @typeInfo(@TypeOf(cb)).pointer.child;
194199
const extern_c = @as(*Completion, @ptrCast(@alignCast(c)));
@@ -227,7 +232,7 @@ export fn xev_timer_cancel(
227232
*xev.Completion,
228233
c_int,
229234
?*anyopaque,
230-
) callconv(.C) xev.CallbackAction,
235+
) callconv(func_callconv) xev.CallbackAction,
231236
) void {
232237
const Callback = @typeInfo(@TypeOf(cb)).pointer.child;
233238
const extern_c = @as(*Completion, @ptrCast(@alignCast(c_cancel)));
@@ -282,7 +287,7 @@ export fn xev_async_wait(
282287
*xev.Completion,
283288
c_int,
284289
?*anyopaque,
285-
) callconv(.C) xev.CallbackAction,
290+
) callconv(func_callconv) xev.CallbackAction,
286291
) void {
287292
const Callback = @typeInfo(@TypeOf(cb)).pointer.child;
288293
const extern_c = @as(*Completion, @ptrCast(@alignCast(c)));
@@ -326,7 +331,7 @@ const Completion = extern struct {
326331
const Task = extern struct {
327332
const Data = [@sizeOf(xev.ThreadPool.Task)]u8;
328333
data: Data,
329-
c_callback: *const fn (*xev.ThreadPool.Task) callconv(.C) void,
334+
c_callback: *const fn (*xev.ThreadPool.Task) callconv(func_callconv) void,
330335
};
331336

332337
/// Returns the unique error code for an error.

0 commit comments

Comments
 (0)