Skip to content

Commit cb3d10b

Browse files
committed
extracted version-check as top-level step
1 parent 4aa6a7a commit cb3d10b

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

libs/zsdl/build.zig

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,12 @@ pub fn build(b: *std.Build) void {
212212
const test_step = b.step("test", "Run zsdl tests");
213213
test_step.dependOn(runTests(b, optimize, target));
214214

215+
const version_check_step = b.step("version-check", "checks runtime library version is the same as the compiled version");
216+
version_check_step.dependOn(testStep("src/sdl2_version_check.zig", b, "zsdl-sdl2-version-check", target, optimize, .{
217+
.api_version = .sdl2,
218+
.enable_ttf = true,
219+
}));
220+
215221
_ = package(b, target, optimize, .{
216222
.options = .{
217223
.api_version = b.option(ApiVersion, "api_version", "Select an SDL API version") orelse .sdl2,
@@ -227,13 +233,13 @@ pub fn runTests(
227233
const step = b.allocator.create(std.Build.Step) catch @panic("OOM");
228234
step.* = std.Build.Step.init(.{ .id = .custom, .name = "zsdl-tests", .owner = b });
229235

230-
step.dependOn(testStep(b, "zsdl-tests-sdl2", target, optimize, .{
236+
step.dependOn(testStep("src/zsdl.zig", b, "zsdl-tests-sdl2", target, optimize, .{
231237
.api_version = .sdl2,
232238
.enable_ttf = true,
233239
}));
234240

235241
// TODO: link SDL3 libs on all platforms
236-
// step.dependOn(testStep(b, "zsdl-tests-sdl3", target, optimize, .{
242+
// step.dependOn(testStep("src/zsdl.zig", b, "zsdl-tests-sdl3", target, optimize, .{
237243
// .api_version = .sdl3,
238244
// .enable_ttf = true,
239245
// }));
@@ -242,6 +248,7 @@ pub fn runTests(
242248
}
243249

244250
fn testStep(
251+
comptime test_entry: []const u8,
245252
b: *std.Build,
246253
name: []const u8,
247254
target: std.Build.ResolvedTarget,
@@ -250,7 +257,7 @@ fn testStep(
250257
) *std.Build.Step {
251258
const tests = b.addTest(.{
252259
.name = name,
253-
.root_source_file = .{ .path = thisDir() ++ "/src/zsdl.zig" },
260+
.root_source_file = .{ .path = thisDir() ++ "/" ++ test_entry },
254261
.target = target,
255262
.optimize = optimize,
256263
});

libs/zsdl/src/sdl2.zig

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,6 @@ pub fn getVersion() Version {
125125
}
126126
extern fn SDL_GetVersion(version: *Version) void;
127127

128-
test "compiled version should be same as linked version" {
129-
try std.testing.expectEqual(VERSION, getVersion());
130-
}
131-
132128
//--------------------------------------------------------------------------------------------------
133129
//
134130
// Display and Window management

libs/zsdl/src/sdl2_version_check.zig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const std = @import("std");
2+
const sdl2 = @import("sdl2.zig");
3+
4+
test "compiled version should be same as linked version" {
5+
try std.testing.expectEqual(sdl2.VERSION, sdl2.getVersion());
6+
}

0 commit comments

Comments
 (0)