From b500b04c41c8f274b4933fb0d4550918de6d19ee Mon Sep 17 00:00:00 2001 From: Ali Chraghi Date: Sun, 24 Jul 2022 23:38:19 +0430 Subject: [PATCH] all: build: install tests exe --- build.zig | 22 ++++++++++++---------- ecs/build.zig | 11 +++++++---- glfw/build.zig | 18 +++++++----------- gpu-dawn/build.zig | 16 ++++++---------- gpu/build.zig | 35 +++++++++++++++++++---------------- src/main.zig | 4 ++++ sysaudio/build.zig | 17 +++++++++++------ sysjs/build.zig | 7 ++++--- 8 files changed, 70 insertions(+), 60 deletions(-) diff --git a/build.zig b/build.zig index 8248f28b..e21aa76b 100644 --- a/build.zig +++ b/build.zig @@ -18,25 +18,27 @@ pub fn build(b: *std.build.Builder) void { }; const options = Options{ .gpu_dawn_options = gpu_dawn_options }; - const main_tests = b.addTest("src/main.zig"); + const main_tests = b.addTestExe("mach-tests", "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); + main_tests.install(); const test_step = b.step("test", "Run library tests"); - test_step.dependOn(&main_tests.step); + test_step.dependOn(&main_tests.run().step); + test_step.dependOn(&gpu.testStep(b, mode, target, @bitCast(gpu.Options, options)).step); + test_step.dependOn(&gpu_dawn.testStep(b, mode, target).step); + test_step.dependOn(&glfw.testStep(b, mode, target).step); + test_step.dependOn(&ecs.testStep(b, mode, target).step); + test_step.dependOn(&freetype.testStep(b, mode, target).step); + test_step.dependOn(&sysaudio.testStep(b, mode, target, .{}).step); + // TODO: we need a way to test wasm stuff + // test_mach_step.dependOn(&sysjs.testStep(b, mode, target).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); + test_mach_step.dependOn(&main_tests.run().step); // TODO(build-system): https://github.com/hexops/mach/issues/229#issuecomment-1100958939 ensureGit(b.allocator); diff --git a/ecs/build.zig b/ecs/build.zig index 93c6420a..94ee020f 100644 --- a/ecs/build.zig +++ b/ecs/build.zig @@ -2,14 +2,17 @@ const std = @import("std"); pub fn build(b: *std.build.Builder) void { const mode = b.standardReleaseOptions(); + const target = b.standardTargetOptions(.{}); const test_step = b.step("test", "Run library tests"); - test_step.dependOn(&testStep(b, mode).step); + test_step.dependOn(&testStep(b, mode, target).step); } -pub fn testStep(b: *std.build.Builder, mode: std.builtin.Mode) *std.build.LibExeObjStep { - const main_tests = b.addTest(thisDir() ++ "/src/main.zig"); +pub fn testStep(b: *std.build.Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget) *std.build.RunStep { + const main_tests = b.addTestExe("ecs-tests", thisDir() ++ "/src/main.zig"); main_tests.setBuildMode(mode); - return main_tests; + main_tests.setTarget(target); + main_tests.install(); + return main_tests.run(); } pub const pkg = std.build.Pkg{ diff --git a/glfw/build.zig b/glfw/build.zig index a2991c4a..2bcfdca1 100644 --- a/glfw/build.zig +++ b/glfw/build.zig @@ -7,21 +7,17 @@ pub fn build(b: *Builder) void { const mode = b.standardReleaseOptions(); const target = b.standardTargetOptions(.{}); - const test_app = b.addStaticLibrary("test_app", null); - test_app.setBuildMode(mode); - test_app.setTarget(target); - link(b, test_app, .{}); - test_app.install(); - const test_step = b.step("test", "Run library tests"); - test_step.dependOn(&testStep(b, mode).step); + test_step.dependOn(&testStep(b, mode, target).step); } -pub fn testStep(b: *Builder, mode: std.builtin.Mode) *std.build.LibExeObjStep { - const main_tests = b.addTest(thisDir() ++ "/src/main.zig"); +pub fn testStep(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget) *std.build.RunStep { + const main_tests = b.addTestExe("glfw_tests", thisDir() ++ "/src/main.zig"); main_tests.setBuildMode(mode); + main_tests.setTarget(target); link(b, main_tests, .{}); - return main_tests; + main_tests.install(); + return main_tests.run(); } pub const LinuxWindowManager = enum { @@ -67,7 +63,7 @@ fn buildLibrary(b: *Builder, step: *std.build.LibExeObjStep, options: Options) * // TODO(build-system): https://github.com/hexops/mach/issues/229#issuecomment-1100958939 ensureDependencySubmodule(b.allocator, "upstream") catch unreachable; - const main_abs = std.fs.path.join(b.allocator, &.{ (comptime thisDir()), "src/main.zig" }) catch unreachable; + const main_abs = thisDir() ++ "/src/main.zig"; const lib = b.addStaticLibrary("glfw", main_abs); lib.setBuildMode(step.build_mode); lib.setTarget(step.target); diff --git a/gpu-dawn/build.zig b/gpu-dawn/build.zig index ac3cf8c9..1fcc397a 100644 --- a/gpu-dawn/build.zig +++ b/gpu-dawn/build.zig @@ -11,14 +11,8 @@ pub fn build(b: *Builder) void { .from_source = b.option(bool, "dawn-from-source", "Build Dawn from source") orelse false, }; - const lib = b.addStaticLibrary("gpu", "src/main.zig"); - lib.setBuildMode(mode); - lib.setTarget(target); - lib.install(); - link(b, lib, options); - const test_step = b.step("test", "Run library tests"); - test_step.dependOn(&testStep(b, mode).step); + test_step.dependOn(&testStep(b, mode, target).step); const dawn_example = b.addExecutable("dawn-example", "src/dawn/hello_triangle.zig"); dawn_example.setBuildMode(mode); @@ -34,10 +28,12 @@ pub fn build(b: *Builder) void { dawn_example_run_step.dependOn(&dawn_example_run_cmd.step); } -pub fn testStep(b: *std.build.Builder, mode: std.builtin.Mode) *std.build.LibExeObjStep { - const main_tests = b.addTest(thisDir() ++ "/src/main.zig"); +pub fn testStep(b: *std.build.Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget) *std.build.RunStep { + const main_tests = b.addTestExe("gpu-dawn-tests", thisDir() ++ "/src/main.zig"); main_tests.setBuildMode(mode); - return main_tests; + main_tests.setTarget(target); + main_tests.install(); + return main_tests.run(); } pub const LinuxWindowManager = enum { diff --git a/gpu/build.zig b/gpu/build.zig index ac920a3f..d083988e 100644 --- a/gpu/build.zig +++ b/gpu/build.zig @@ -11,28 +11,31 @@ pub fn build(b: *std.build.Builder) void { }; const test_step = b.step("test", "Run library tests"); - test_step.dependOn(&testStep(b, mode, .{ .gpu_dawn_options = gpu_dawn_options }).step); + test_step.dependOn(&testStep(b, mode, target, .{ .gpu_dawn_options = gpu_dawn_options }).step); - const example = b.addExecutable("gpu-hello-triangle", "examples/main.zig"); - example.setTarget(target); - example.setBuildMode(mode); - example.install(); - example.linkLibC(); - example.addPackagePath("gpu", "src/main.zig"); - example.addPackagePath("glfw", "libs/mach-glfw/src/main.zig"); - link(b, example, .{ .gpu_dawn_options = gpu_dawn_options }); + // const example = b.addExecutable("gpu-hello-triangle", "examples/main.zig"); + // example.setBuildMode(mode); + //example.setTarget(target); + // example.linkLibC(); + // example.addPackagePath("gpu", "src/main.zig"); + // example.addPackagePath("glfw", "libs/mach-glfw/src/main.zig"); + // link(b, example, .{ .gpu_dawn_options = gpu_dawn_options }); - const example_run_cmd = example.run(); - example_run_cmd.step.dependOn(b.getInstallStep()); - const example_run_step = b.step("run-example", "Run the example"); - example_run_step.dependOn(&example_run_cmd.step); + // example.install(); + + // const example_run_cmd = example.run(); + // example_run_cmd.step.dependOn(b.getInstallStep()); + // const example_run_step = b.step("run-example", "Run the example"); + // example_run_step.dependOn(&example_run_cmd.step); } -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"); +pub fn testStep(b: *std.build.Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget, options: Options) *std.build.RunStep { + const main_tests = b.addTestExe("gpu-tests", thisDir() ++ "/src/main.zig"); main_tests.setBuildMode(mode); + main_tests.setTarget(target); link(b, main_tests, options); - return main_tests; + main_tests.install(); + return main_tests.run(); } pub const Options = struct { diff --git a/src/main.zig b/src/main.zig index 12880dab..cb1dcdb1 100644 --- a/src/main.zig +++ b/src/main.zig @@ -9,3 +9,7 @@ pub const ecs = @import("ecs"); // Engine exports pub const App = @import("engine.zig").App; pub const module = @import("engine.zig").module; + +test { + _ = void; +} diff --git a/sysaudio/build.zig b/sysaudio/build.zig index 73204bd8..956e82ec 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, mode, .{}).step); + test_step.dependOn(&testStep(b, mode, target, .{}).step); inline for ([_][]const u8{ "soundio-sine-wave", @@ -48,18 +48,23 @@ pub fn build(b: *Builder) void { } } -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"); +pub fn testStep(b: *std.build.Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget, options: Options) *std.build.RunStep { + const soundio_tests = b.addTestExe("soundio-tests", thisDir() ++ "/soundio/main.zig"); soundio_tests.setBuildMode(mode); + soundio_tests.setTarget(target); link(b, soundio_tests, options); + soundio_tests.install(); - const main_tests = b.addTest(thisDir() ++ "/src/main.zig"); + const main_tests = b.addTestExe("sysaudio-tests", thisDir() ++ "/src/main.zig"); main_tests.setBuildMode(mode); + main_tests.setTarget(target); main_tests.addPackage(soundio_pkg); - main_tests.step.dependOn(&soundio_tests.step); link(b, main_tests, options); + main_tests.install(); - return main_tests; + const main_tests_run = main_tests.run(); + main_tests_run.step.dependOn(&soundio_tests.run().step); + return main_tests_run; } pub fn link(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void { diff --git a/sysjs/build.zig b/sysjs/build.zig index a0ee18ff..39eea10c 100644 --- a/sysjs/build.zig +++ b/sysjs/build.zig @@ -6,10 +6,11 @@ pub fn build(b: *std.build.Builder) void { test_step.dependOn(&testStep(b, mode).step); } -pub fn testStep(b: *std.build.Builder, mode: std.builtin.Mode) *std.build.LibExeObjStep { - const main_tests = b.addTest(thisDir() ++ "/src/main.zig"); +pub fn testStep(b: *std.build.Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget) *std.build.RunStep { + const main_tests = b.addTestExe("sysjs-tests", thisDir() ++ "/src/main.zig"); main_tests.setBuildMode(mode); - return main_tests; + main_tests.setTarget(target); + return main_tests.run(); } pub const pkg = std.build.Pkg{