Skip to content

Commit 6dfa8a9

Browse files
committed
Use tests to do basic compile checks
1 parent 1c8f7de commit 6dfa8a9

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

build.zig

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub fn build(b: *std.Build) void {
5656
b.installArtifact(glfw);
5757
glfw.installHeadersDirectory(b.path("libs/glfw/include"), "", .{});
5858

59-
glfw.addIncludePath(b.path("libs/glfw/include"));
59+
addIncludePaths(b, glfw, target, options);
6060
glfw.linkLibC();
6161

6262
const src_dir = "libs/glfw/src/";
@@ -205,14 +205,30 @@ pub fn build(b: *std.Build) void {
205205
},
206206
else => {},
207207
}
208+
addIncludePaths(b, module, target, options);
208209

209-
module.addIncludePath(b.path("libs/glfw/include"));
210+
const test_step = b.step("test", "Run zglfw tests");
211+
const tests = b.addTest(.{
212+
.name = "zglfw-tests",
213+
.root_source_file = b.path("src/zglfw.zig"),
214+
.target = target,
215+
.optimize = optimize,
216+
});
217+
addIncludePaths(b, tests, target, options);
218+
tests.root_module.addImport("zglfw_options", options_module);
219+
tests.linkLibrary(glfw);
220+
b.installArtifact(tests);
221+
test_step.dependOn(&b.addRunArtifact(tests).step);
222+
}
223+
224+
fn addIncludePaths(b: *std.Build, unit: anytype, target: anytype, options: anytype) void {
225+
unit.addIncludePath(b.path("libs/glfw/include"));
210226
switch (target.result.os.tag) {
211227
.linux => {
212228
if (b.lazyDependency("system_sdk", .{})) |system_sdk| {
213-
module.addSystemIncludePath(system_sdk.path("linux/include"));
229+
unit.addSystemIncludePath(system_sdk.path("linux/include"));
214230
if (options.enable_wayland) {
215-
glfw.addSystemIncludePath(system_sdk.path("linux/include/wayland"));
231+
unit.addSystemIncludePath(system_sdk.path("linux/include/wayland"));
216232
}
217233
}
218234
},

src/zglfw.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const assert = std.debug.assert;
44

55
const options = @import("zglfw_options");
66

7-
comptime {
7+
test {
88
_ = std.testing.refAllDeclsRecursive(@This());
99
}
1010

0 commit comments

Comments
 (0)