@@ -3,6 +3,9 @@ const std = @import("std");
3
3
const assert = std .debug .assert ;
4
4
5
5
pub fn build (b : * std.Build ) void {
6
+ const optimize = b .standardOptimizeOption (.{});
7
+ const target = b .standardTargetOptions (.{});
8
+
6
9
const zsdl2_module = b .addModule ("zsdl2" , .{
7
10
.root_source_file = b .path ("src/sdl2.zig" ),
8
11
});
@@ -25,6 +28,42 @@ pub fn build(b: *std.Build) void {
25
28
_ = b .addModule ("zsdl3" , .{
26
29
.root_source_file = b .path ("src/sdl3.zig" ),
27
30
});
31
+
32
+ const test_step = b .step ("test" , "Run bindings tests" );
33
+ { // Test SDL2 bindings
34
+ const zsdl2_tests = addTests (test_step , target , optimize , "zsdl2-tests" , "src/sdl2.zig" );
35
+ link_SDL2 (zsdl2_tests );
36
+ }
37
+ { // Test SDL2_ttf bindings
38
+ const zsdl2_ttf_tests = addTestsAux (
39
+ test_step ,
40
+ target ,
41
+ optimize ,
42
+ "zsdl2_ttf-tests" ,
43
+ "src/sdl2_ttf.zig" ,
44
+ "zsdl2" ,
45
+ zsdl2_module ,
46
+ );
47
+ link_SDL2 (zsdl2_ttf_tests );
48
+ link_SDL2_ttf (zsdl2_ttf_tests );
49
+ }
50
+ { // Test SDL2_image bindings
51
+ const zsdl2_image_tests = addTestsAux (
52
+ test_step ,
53
+ target ,
54
+ optimize ,
55
+ "zsdl2_ttf-image" ,
56
+ "src/sdl2_image.zig" ,
57
+ "zsdl2" ,
58
+ zsdl2_module ,
59
+ );
60
+ link_SDL2 (zsdl2_image_tests );
61
+ link_SDL2_image (zsdl2_image_tests );
62
+ }
63
+ { // Test SDL3 bindings
64
+ const zsdl3_tests = addTests (test_step , target , optimize , "zsdl3-tests" , "src/sdl3.zig" );
65
+ link_SDL3 (zsdl3_tests );
66
+ }
28
67
}
29
68
30
69
pub fn link_SDL2 (compile_step : * std.Build.Step.Compile ) void {
@@ -279,3 +318,36 @@ pub const prebuilt = struct {
279
318
return null ;
280
319
}
281
320
};
321
+
322
+ fn addTests (
323
+ test_step : * std.Build.Step ,
324
+ target : std.Build.ResolvedTarget ,
325
+ optimize : std.builtin.OptimizeMode ,
326
+ name : []const u8 ,
327
+ root_src_path : []const u8 ,
328
+ ) * std.Build.Step.Compile {
329
+ const b = test_step .owner ;
330
+ const tests = b .addTest (.{
331
+ .name = name ,
332
+ .root_source_file = b .path (root_src_path ),
333
+ .target = target ,
334
+ .optimize = optimize ,
335
+ });
336
+ b .installArtifact (tests );
337
+ test_step .dependOn (& b .addRunArtifact (tests ).step );
338
+ return tests ;
339
+ }
340
+
341
+ fn addTestsAux (
342
+ test_step : * std.Build.Step ,
343
+ target : std.Build.ResolvedTarget ,
344
+ optimize : std.builtin.OptimizeMode ,
345
+ name : []const u8 ,
346
+ root_src_path : []const u8 ,
347
+ parent_module_name : []const u8 ,
348
+ parent_module : * std.Build.Module ,
349
+ ) * std.Build.Step.Compile {
350
+ const tests = addTests (test_step , target , optimize , name , root_src_path );
351
+ tests .root_module .addImport (parent_module_name , parent_module );
352
+ return tests ;
353
+ }
0 commit comments