diff --git a/ecs/build.zig b/ecs/build.zig index 28f25886..3b3004d9 100644 --- a/ecs/build.zig +++ b/ecs/build.zig @@ -1,14 +1,12 @@ const std = @import("std"); pub fn build(b: *std.build.Builder) void { - const mode = b.standardReleaseOptions(); - - const main_tests = b.addTest("src/main.zig"); - main_tests.addPackage(pkg); - main_tests.setBuildMode(mode); - const test_step = b.step("test", "Run library tests"); - test_step.dependOn(&main_tests.step); + test_step.dependOn(&testStep(b).step); +} + +pub fn testStep(b: *std.build.Builder) *std.build.LibExeObjStep { + return b.addTest(thisDir() ++ "/src/main.zig"); } pub const pkg = std.build.Pkg{ diff --git a/freetype/build.zig b/freetype/build.zig index 7e349558..e91c7e06 100644 --- a/freetype/build.zig +++ b/freetype/build.zig @@ -48,40 +48,8 @@ pub fn build(b: *std.build.Builder) !void { const mode = b.standardReleaseOptions(); const target = b.standardTargetOptions(.{}); - const freetype_tests = b.addTestSource(pkg.source); - freetype_tests.setBuildMode(mode); - freetype_tests.setTarget(target); - freetype_tests.addPackage(c_pkg); - freetype_tests.addPackage(utils_pkg); - link(b, freetype_tests, .{}); - - const harfbuzz_tests = b.addTestSource(harfbuzz_pkg.source); - harfbuzz_tests.setBuildMode(mode); - harfbuzz_tests.setTarget(target); - harfbuzz_tests.addPackage(c_pkg); - harfbuzz_tests.addPackage(utils_pkg); - harfbuzz_tests.addPackage(pkg); - link(b, harfbuzz_tests, .{ .harfbuzz = .{} }); - - const main_tests = b.addTest("test/main.zig"); - main_tests.setBuildMode(mode); - main_tests.setTarget(target); - main_tests.addPackage(c_pkg); - - // Remove once the stage2 compiler fixes pkg std not found - main_tests.addPackage(utils_pkg); - - main_tests.addPackage(pkg); - link(b, main_tests, .{ .freetype = .{ - .ft_config_path = "./test/ft", - .brotli = true, - } }); - main_tests.main_pkg_path = thisDir(); - const test_step = b.step("test", "Run library tests"); - test_step.dependOn(&freetype_tests.step); - test_step.dependOn(&harfbuzz_tests.step); - test_step.dependOn(&main_tests.step); + test_step.dependOn(&testStep(b).step); inline for ([_][]const u8{ "single-glyph", @@ -112,6 +80,36 @@ pub fn build(b: *std.build.Builder) !void { } } +pub fn testStep(b: *Builder) *std.build.LibExeObjStep { + const freetype_tests = b.addTestSource(pkg.source); + freetype_tests.addPackage(c_pkg); + freetype_tests.addPackage(utils_pkg); + link(b, freetype_tests, .{}); + + const harfbuzz_tests = b.addTestSource(harfbuzz_pkg.source); + harfbuzz_tests.addPackage(c_pkg); + harfbuzz_tests.addPackage(utils_pkg); + harfbuzz_tests.addPackage(pkg); + link(b, harfbuzz_tests, .{ .harfbuzz = .{} }); + + const main_tests = b.addTest(thisDir() ++ "/test/main.zig"); + main_tests.addPackage(c_pkg); + + // Remove once the stage2 compiler fixes pkg std not found + main_tests.addPackage(utils_pkg); + + main_tests.addPackage(pkg); + link(b, main_tests, .{ .freetype = .{ + .ft_config_path = thisDir() ++ "/test/ft", + .brotli = true, + } }); + main_tests.main_pkg_path = thisDir(); + main_tests.step.dependOn(&freetype_tests.step); + main_tests.step.dependOn(&harfbuzz_tests.step); + + return main_tests; +} + pub fn link(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void { const ft_lib = buildFreetype(b, step, options.freetype); step.linkLibrary(ft_lib); diff --git a/glfw/build.zig b/glfw/build.zig index fbbf74e0..0aa4ba82 100644 --- a/glfw/build.zig +++ b/glfw/build.zig @@ -4,16 +4,14 @@ const Builder = std.build.Builder; const system_sdk = @import("system_sdk.zig"); pub fn build(b: *Builder) void { - const mode = b.standardReleaseOptions(); - const target = b.standardTargetOptions(.{}); - - const main_tests = b.addTest("src/main.zig"); - main_tests.setBuildMode(mode); - main_tests.setTarget(target); - link(b, main_tests, .{}); - const test_step = b.step("test", "Run library tests"); - test_step.dependOn(&main_tests.step); + test_step.dependOn(&testStep(b).step); +} + +pub fn testStep(b: *Builder) *std.build.LibExeObjStep { + const main_tests = b.addTest(thisDir() ++ "/src/main.zig"); + link(b, main_tests, .{}); + return main_tests; } pub const LinuxWindowManager = enum { diff --git a/gpu-dawn/build.zig b/gpu-dawn/build.zig index 2eaf9c14..25c69f5a 100644 --- a/gpu-dawn/build.zig +++ b/gpu-dawn/build.zig @@ -17,11 +17,8 @@ pub fn build(b: *Builder) void { lib.install(); link(b, lib, options); - const main_tests = b.addTest("src/main.zig"); - main_tests.setBuildMode(mode); - const test_step = b.step("test", "Run library tests"); - test_step.dependOn(&main_tests.step); + test_step.dependOn(&testStep(b).step); const dawn_example = b.addExecutable("dawn-example", "src/dawn/hello_triangle.zig"); dawn_example.setBuildMode(mode); @@ -37,6 +34,10 @@ pub fn build(b: *Builder) void { dawn_example_run_step.dependOn(&dawn_example_run_cmd.step); } +pub fn testStep(b: *std.build.Builder) *std.build.LibExeObjStep { + return b.addTest(thisDir() ++ "/src/main.zig"); +} + pub const LinuxWindowManager = enum { X11, Wayland, diff --git a/gpu/build.zig b/gpu/build.zig index 793a6416..a4a2db7c 100644 --- a/gpu/build.zig +++ b/gpu/build.zig @@ -10,13 +10,8 @@ pub fn build(b: *std.build.Builder) void { .from_source = b.option(bool, "dawn-from-source", "Build Dawn from source") orelse false, }; - const main_tests = b.addTest("src/main.zig"); - main_tests.setTarget(target); - main_tests.setBuildMode(mode); - link(b, main_tests, .{ .gpu_dawn_options = gpu_dawn_options }); - const test_step = b.step("test", "Run library tests"); - test_step.dependOn(&main_tests.step); + test_step.dependOn(&testStep(b, .{ .gpu_dawn_options = gpu_dawn_options }).step); const example = b.addExecutable("gpu-hello-triangle", "examples/main.zig"); example.setTarget(target); @@ -33,6 +28,12 @@ pub fn build(b: *std.build.Builder) void { example_run_step.dependOn(&example_run_cmd.step); } +pub fn testStep(b: *std.build.Builder, options: Options) *std.build.LibExeObjStep { + const main_tests = b.addTest(thisDir() ++ "/src/main.zig"); + link(b, main_tests, options); + return main_tests; +} + pub const Options = struct { glfw_options: glfw.Options = .{}, gpu_dawn_options: gpu_dawn.Options = .{}, diff --git a/sysaudio/build.zig b/sysaudio/build.zig index 7c8afdf7..38579a81 100644 --- a/sysaudio/build.zig +++ b/sysaudio/build.zig @@ -21,18 +21,8 @@ pub fn build(b: *Builder) void { const mode = b.standardReleaseOptions(); const target = b.standardTargetOptions(.{}); - const soundio_tests = b.addTest("soundio/main.zig"); - soundio_tests.setBuildMode(mode); - link(b, soundio_tests, .{}); - - const main_tests = b.addTest("src/main.zig"); - main_tests.setBuildMode(mode); - main_tests.addPackage(soundio_pkg); - link(b, main_tests, .{}); - const test_step = b.step("test", "Run library tests"); - test_step.dependOn(&soundio_tests.step); - test_step.dependOn(&main_tests.step); + test_step.dependOn(&testStep(b, .{}).step); inline for ([_][]const u8{ "soundio-sine-wave", @@ -58,6 +48,18 @@ pub fn build(b: *Builder) void { } } +pub fn testStep(b: *std.build.Builder, options: Options) *std.build.LibExeObjStep { + const soundio_tests = b.addTest(thisDir() ++ "/soundio/main.zig"); + link(b, soundio_tests, options); + + const main_tests = b.addTest(thisDir() ++ "/src/main.zig"); + main_tests.addPackage(soundio_pkg); + main_tests.step.dependOn(&soundio_tests.step); + link(b, main_tests, options); + + return main_tests; +} + pub fn link(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void { _ = options; if (step.target.toTarget().cpu.arch != .wasm32) { diff --git a/sysjs/build.zig b/sysjs/build.zig index 57e4fa0c..ab63a2f9 100644 --- a/sysjs/build.zig +++ b/sysjs/build.zig @@ -1,14 +1,12 @@ const std = @import("std"); pub fn build(b: *std.build.Builder) void { - const mode = b.standardReleaseOptions(); - - const main_tests = b.addTest("src/main.zig"); - main_tests.addPackage(pkg); - main_tests.setBuildMode(mode); - const test_step = b.step("test", "Run library tests"); - test_step.dependOn(&main_tests.step); + test_step.dependOn(&testStep(b).step); +} + +pub fn testStep(b: *std.build.Builder) *std.build.LibExeObjStep { + return b.addTest(thisDir() ++ "/src/main.zig"); } pub const pkg = std.build.Pkg{