From e6adc3e35003d323412756ffe3392e1f7ab369b3 Mon Sep 17 00:00:00 2001 From: alichraghi Date: Wed, 20 Jul 2022 16:31:57 +0430 Subject: [PATCH] build: add mode paramater to `testStep` functions --- build.zig | 12 ++++++++++-- ecs/build.zig | 9 ++++++--- freetype/build.zig | 7 +++++-- glfw/build.zig | 6 ++++-- gpu-dawn/build.zig | 8 +++++--- gpu/build.zig | 5 +++-- sysaudio/build.zig | 6 ++++-- sysjs/build.zig | 9 ++++++--- 8 files changed, 43 insertions(+), 19 deletions(-) diff --git a/build.zig b/build.zig index 09c47880..6d0b4dc6 100644 --- a/build.zig +++ b/build.zig @@ -18,10 +18,8 @@ pub fn build(b: *std.build.Builder) void { }; const options = Options{ .gpu_dawn_options = gpu_dawn_options }; - // TODO: re-enable tests const main_tests = b.addTest("src/main.zig"); main_tests.setBuildMode(mode); - main_tests.setTarget(target); main_tests.addPackage(pkg); main_tests.addPackage(gpu.pkg); main_tests.addPackage(glfw.pkg); @@ -29,6 +27,16 @@ pub fn build(b: *std.build.Builder) void { const test_step = b.step("test", "Run library tests"); test_step.dependOn(&main_tests.step); + const test_mach_step = b.step("test-mach", "Run Mach Core library tests"); + test_mach_step.dependOn(&main_tests.step); + test_mach_step.dependOn(&gpu.testStep(b, mode, @bitCast(gpu.Options, options)).step); + test_mach_step.dependOn(&gpu_dawn.testStep(b, mode).step); + test_mach_step.dependOn(&glfw.testStep(b, mode).step); + test_mach_step.dependOn(&ecs.testStep(b, mode).step); + test_mach_step.dependOn(&freetype.testStep(b, mode).step); + test_mach_step.dependOn(&sysaudio.testStep(b, mode, .{}).step); + test_mach_step.dependOn(&sysjs.testStep(b, mode).step); + // TODO(build-system): https://github.com/hexops/mach/issues/229#issuecomment-1100958939 ensureGit(b.allocator); ensureDependencySubmodule(b.allocator, "examples/libs/zmath") catch unreachable; diff --git a/ecs/build.zig b/ecs/build.zig index 3b3004d9..93c6420a 100644 --- a/ecs/build.zig +++ b/ecs/build.zig @@ -1,12 +1,15 @@ const std = @import("std"); pub fn build(b: *std.build.Builder) void { + const mode = b.standardReleaseOptions(); const test_step = b.step("test", "Run library tests"); - test_step.dependOn(&testStep(b).step); + test_step.dependOn(&testStep(b, mode).step); } -pub fn testStep(b: *std.build.Builder) *std.build.LibExeObjStep { - return b.addTest(thisDir() ++ "/src/main.zig"); +pub fn testStep(b: *std.build.Builder, mode: std.builtin.Mode) *std.build.LibExeObjStep { + const main_tests = b.addTest(thisDir() ++ "/src/main.zig"); + main_tests.setBuildMode(mode); + return main_tests; } pub const pkg = std.build.Pkg{ diff --git a/freetype/build.zig b/freetype/build.zig index e91c7e06..fa496d9a 100644 --- a/freetype/build.zig +++ b/freetype/build.zig @@ -49,7 +49,7 @@ pub fn build(b: *std.build.Builder) !void { const target = b.standardTargetOptions(.{}); const test_step = b.step("test", "Run library tests"); - test_step.dependOn(&testStep(b).step); + test_step.dependOn(&testStep(b, mode).step); inline for ([_][]const u8{ "single-glyph", @@ -80,19 +80,22 @@ pub fn build(b: *std.build.Builder) !void { } } -pub fn testStep(b: *Builder) *std.build.LibExeObjStep { +pub fn testStep(b: *Builder, mode: std.builtin.Mode) *std.build.LibExeObjStep { const freetype_tests = b.addTestSource(pkg.source); + freetype_tests.setBuildMode(mode); 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.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.setBuildMode(mode); main_tests.addPackage(c_pkg); // Remove once the stage2 compiler fixes pkg std not found diff --git a/glfw/build.zig b/glfw/build.zig index 0aa4ba82..5c0bcaae 100644 --- a/glfw/build.zig +++ b/glfw/build.zig @@ -4,12 +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 test_step = b.step("test", "Run library tests"); - test_step.dependOn(&testStep(b).step); + test_step.dependOn(&testStep(b, mode).step); } -pub fn testStep(b: *Builder) *std.build.LibExeObjStep { +pub fn testStep(b: *Builder, mode: std.builtin.Mode) *std.build.LibExeObjStep { const main_tests = b.addTest(thisDir() ++ "/src/main.zig"); + main_tests.setBuildMode(mode); link(b, main_tests, .{}); return main_tests; } diff --git a/gpu-dawn/build.zig b/gpu-dawn/build.zig index 25c69f5a..ac3cf8c9 100644 --- a/gpu-dawn/build.zig +++ b/gpu-dawn/build.zig @@ -18,7 +18,7 @@ pub fn build(b: *Builder) void { link(b, lib, options); const test_step = b.step("test", "Run library tests"); - test_step.dependOn(&testStep(b).step); + test_step.dependOn(&testStep(b, mode).step); const dawn_example = b.addExecutable("dawn-example", "src/dawn/hello_triangle.zig"); dawn_example.setBuildMode(mode); @@ -34,8 +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 fn testStep(b: *std.build.Builder, mode: std.builtin.Mode) *std.build.LibExeObjStep { + const main_tests = b.addTest(thisDir() ++ "/src/main.zig"); + main_tests.setBuildMode(mode); + return main_tests; } pub const LinuxWindowManager = enum { diff --git a/gpu/build.zig b/gpu/build.zig index a4a2db7c..ac920a3f 100644 --- a/gpu/build.zig +++ b/gpu/build.zig @@ -11,7 +11,7 @@ pub fn build(b: *std.build.Builder) void { }; const test_step = b.step("test", "Run library tests"); - test_step.dependOn(&testStep(b, .{ .gpu_dawn_options = gpu_dawn_options }).step); + test_step.dependOn(&testStep(b, mode, .{ .gpu_dawn_options = gpu_dawn_options }).step); const example = b.addExecutable("gpu-hello-triangle", "examples/main.zig"); example.setTarget(target); @@ -28,8 +28,9 @@ 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 { +pub fn testStep(b: *std.build.Builder, mode: std.builtin.Mode, options: Options) *std.build.LibExeObjStep { const main_tests = b.addTest(thisDir() ++ "/src/main.zig"); + main_tests.setBuildMode(mode); link(b, main_tests, options); return main_tests; } diff --git a/sysaudio/build.zig b/sysaudio/build.zig index 38579a81..73204bd8 100644 --- a/sysaudio/build.zig +++ b/sysaudio/build.zig @@ -22,7 +22,7 @@ pub fn build(b: *Builder) void { const target = b.standardTargetOptions(.{}); const test_step = b.step("test", "Run library tests"); - test_step.dependOn(&testStep(b, .{}).step); + test_step.dependOn(&testStep(b, mode, .{}).step); inline for ([_][]const u8{ "soundio-sine-wave", @@ -48,11 +48,13 @@ pub fn build(b: *Builder) void { } } -pub fn testStep(b: *std.build.Builder, options: Options) *std.build.LibExeObjStep { +pub fn testStep(b: *std.build.Builder, mode: std.builtin.Mode, options: Options) *std.build.LibExeObjStep { const soundio_tests = b.addTest(thisDir() ++ "/soundio/main.zig"); + soundio_tests.setBuildMode(mode); link(b, soundio_tests, options); const main_tests = b.addTest(thisDir() ++ "/src/main.zig"); + main_tests.setBuildMode(mode); main_tests.addPackage(soundio_pkg); main_tests.step.dependOn(&soundio_tests.step); link(b, main_tests, options); diff --git a/sysjs/build.zig b/sysjs/build.zig index ab63a2f9..a0ee18ff 100644 --- a/sysjs/build.zig +++ b/sysjs/build.zig @@ -1,12 +1,15 @@ const std = @import("std"); pub fn build(b: *std.build.Builder) void { + const mode = b.standardReleaseOptions(); const test_step = b.step("test", "Run library tests"); - test_step.dependOn(&testStep(b).step); + test_step.dependOn(&testStep(b, mode).step); } -pub fn testStep(b: *std.build.Builder) *std.build.LibExeObjStep { - return b.addTest(thisDir() ++ "/src/main.zig"); +pub fn testStep(b: *std.build.Builder, mode: std.builtin.Mode) *std.build.LibExeObjStep { + const main_tests = b.addTest(thisDir() ++ "/src/main.zig"); + main_tests.setBuildMode(mode); + return main_tests; } pub const pkg = std.build.Pkg{