all: build: install tests exe

This commit is contained in:
Ali Chraghi 2022-07-24 23:38:19 +04:30 committed by Stephen Gutekanst
parent a6a678b912
commit b500b04c41
8 changed files with 70 additions and 60 deletions

View file

@ -18,25 +18,27 @@ pub fn build(b: *std.build.Builder) void {
}; };
const options = Options{ .gpu_dawn_options = gpu_dawn_options }; 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.setBuildMode(mode);
main_tests.setTarget(target); main_tests.setTarget(target);
main_tests.addPackage(pkg); main_tests.addPackage(pkg);
main_tests.addPackage(gpu.pkg); main_tests.addPackage(gpu.pkg);
main_tests.addPackage(glfw.pkg); main_tests.addPackage(glfw.pkg);
main_tests.install();
const test_step = b.step("test", "Run library tests"); 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"); const test_mach_step = b.step("test-mach", "Run Mach Core library tests");
test_mach_step.dependOn(&main_tests.step); test_mach_step.dependOn(&main_tests.run().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 // TODO(build-system): https://github.com/hexops/mach/issues/229#issuecomment-1100958939
ensureGit(b.allocator); ensureGit(b.allocator);

View file

@ -2,14 +2,17 @@ const std = @import("std");
pub fn build(b: *std.build.Builder) void { pub fn build(b: *std.build.Builder) void {
const mode = b.standardReleaseOptions(); const mode = b.standardReleaseOptions();
const target = b.standardTargetOptions(.{});
const test_step = b.step("test", "Run library tests"); 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 { pub fn testStep(b: *std.build.Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget) *std.build.RunStep {
const main_tests = b.addTest(thisDir() ++ "/src/main.zig"); const main_tests = b.addTestExe("ecs-tests", thisDir() ++ "/src/main.zig");
main_tests.setBuildMode(mode); main_tests.setBuildMode(mode);
return main_tests; main_tests.setTarget(target);
main_tests.install();
return main_tests.run();
} }
pub const pkg = std.build.Pkg{ pub const pkg = std.build.Pkg{

View file

@ -7,21 +7,17 @@ pub fn build(b: *Builder) void {
const mode = b.standardReleaseOptions(); const mode = b.standardReleaseOptions();
const target = b.standardTargetOptions(.{}); 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"); 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 { pub fn testStep(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget) *std.build.RunStep {
const main_tests = b.addTest(thisDir() ++ "/src/main.zig"); const main_tests = b.addTestExe("glfw_tests", thisDir() ++ "/src/main.zig");
main_tests.setBuildMode(mode); main_tests.setBuildMode(mode);
main_tests.setTarget(target);
link(b, main_tests, .{}); link(b, main_tests, .{});
return main_tests; main_tests.install();
return main_tests.run();
} }
pub const LinuxWindowManager = enum { 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 // TODO(build-system): https://github.com/hexops/mach/issues/229#issuecomment-1100958939
ensureDependencySubmodule(b.allocator, "upstream") catch unreachable; 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); const lib = b.addStaticLibrary("glfw", main_abs);
lib.setBuildMode(step.build_mode); lib.setBuildMode(step.build_mode);
lib.setTarget(step.target); lib.setTarget(step.target);

View file

@ -11,14 +11,8 @@ pub fn build(b: *Builder) void {
.from_source = b.option(bool, "dawn-from-source", "Build Dawn from source") orelse false, .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"); 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"); const dawn_example = b.addExecutable("dawn-example", "src/dawn/hello_triangle.zig");
dawn_example.setBuildMode(mode); dawn_example.setBuildMode(mode);
@ -34,10 +28,12 @@ pub fn build(b: *Builder) void {
dawn_example_run_step.dependOn(&dawn_example_run_cmd.step); dawn_example_run_step.dependOn(&dawn_example_run_cmd.step);
} }
pub fn testStep(b: *std.build.Builder, mode: std.builtin.Mode) *std.build.LibExeObjStep { pub fn testStep(b: *std.build.Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget) *std.build.RunStep {
const main_tests = b.addTest(thisDir() ++ "/src/main.zig"); const main_tests = b.addTestExe("gpu-dawn-tests", thisDir() ++ "/src/main.zig");
main_tests.setBuildMode(mode); main_tests.setBuildMode(mode);
return main_tests; main_tests.setTarget(target);
main_tests.install();
return main_tests.run();
} }
pub const LinuxWindowManager = enum { pub const LinuxWindowManager = enum {

View file

@ -11,28 +11,31 @@ pub fn build(b: *std.build.Builder) void {
}; };
const test_step = b.step("test", "Run library tests"); 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"); // const example = b.addExecutable("gpu-hello-triangle", "examples/main.zig");
example.setTarget(target); // example.setBuildMode(mode);
example.setBuildMode(mode); //example.setTarget(target);
example.install(); // example.linkLibC();
example.linkLibC(); // example.addPackagePath("gpu", "src/main.zig");
example.addPackagePath("gpu", "src/main.zig"); // example.addPackagePath("glfw", "libs/mach-glfw/src/main.zig");
example.addPackagePath("glfw", "libs/mach-glfw/src/main.zig"); // link(b, example, .{ .gpu_dawn_options = gpu_dawn_options });
link(b, example, .{ .gpu_dawn_options = gpu_dawn_options });
const example_run_cmd = example.run(); // example.install();
example_run_cmd.step.dependOn(b.getInstallStep());
const example_run_step = b.step("run-example", "Run the example"); // const example_run_cmd = example.run();
example_run_step.dependOn(&example_run_cmd.step); // 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 { pub fn testStep(b: *std.build.Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget, options: Options) *std.build.RunStep {
const main_tests = b.addTest(thisDir() ++ "/src/main.zig"); const main_tests = b.addTestExe("gpu-tests", thisDir() ++ "/src/main.zig");
main_tests.setBuildMode(mode); main_tests.setBuildMode(mode);
main_tests.setTarget(target);
link(b, main_tests, options); link(b, main_tests, options);
return main_tests; main_tests.install();
return main_tests.run();
} }
pub const Options = struct { pub const Options = struct {

View file

@ -9,3 +9,7 @@ pub const ecs = @import("ecs");
// Engine exports // Engine exports
pub const App = @import("engine.zig").App; pub const App = @import("engine.zig").App;
pub const module = @import("engine.zig").module; pub const module = @import("engine.zig").module;
test {
_ = void;
}

View file

@ -22,7 +22,7 @@ pub fn build(b: *Builder) void {
const target = b.standardTargetOptions(.{}); const target = b.standardTargetOptions(.{});
const test_step = b.step("test", "Run library tests"); 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{ inline for ([_][]const u8{
"soundio-sine-wave", "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 { pub fn testStep(b: *std.build.Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget, options: Options) *std.build.RunStep {
const soundio_tests = b.addTest(thisDir() ++ "/soundio/main.zig"); const soundio_tests = b.addTestExe("soundio-tests", thisDir() ++ "/soundio/main.zig");
soundio_tests.setBuildMode(mode); soundio_tests.setBuildMode(mode);
soundio_tests.setTarget(target);
link(b, soundio_tests, options); 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.setBuildMode(mode);
main_tests.setTarget(target);
main_tests.addPackage(soundio_pkg); main_tests.addPackage(soundio_pkg);
main_tests.step.dependOn(&soundio_tests.step);
link(b, main_tests, options); 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 { pub fn link(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void {

View file

@ -6,10 +6,11 @@ pub fn build(b: *std.build.Builder) void {
test_step.dependOn(&testStep(b, mode).step); test_step.dependOn(&testStep(b, mode).step);
} }
pub fn testStep(b: *std.build.Builder, mode: std.builtin.Mode) *std.build.LibExeObjStep { pub fn testStep(b: *std.build.Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget) *std.build.RunStep {
const main_tests = b.addTest(thisDir() ++ "/src/main.zig"); const main_tests = b.addTestExe("sysjs-tests", thisDir() ++ "/src/main.zig");
main_tests.setBuildMode(mode); main_tests.setBuildMode(mode);
return main_tests; main_tests.setTarget(target);
return main_tests.run();
} }
pub const pkg = std.build.Pkg{ pub const pkg = std.build.Pkg{