build: only build/run tests and libmach on non-wasm targets

This commit is contained in:
Ali Chraghi 2022-09-20 11:05:26 +04:30 committed by Stephen Gutekanst
parent f750f752ef
commit 728582c75e

View file

@ -36,6 +36,7 @@ pub fn build(b: *std.build.Builder) void {
};
const options = Options{ .gpu_dawn_options = gpu_dawn_options };
if (target.getCpuArch() != .wasm32) {
const all_tests_step = b.step("test", "Run library tests");
const glfw_test_step = b.step("test-glfw", "Run GLFW library tests");
const gpu_test_step = b.step("test-gpu", "Run GPU library tests");
@ -66,6 +67,48 @@ pub fn build(b: *std.build.Builder) void {
all_tests_step.dependOn(sysaudio_test_step);
all_tests_step.dependOn(mach_test_step);
const shaderexp_app = App.init(
b,
.{
.name = "shaderexp",
.src = "shaderexp/main.zig",
.target = target,
},
);
shaderexp_app.setBuildMode(mode);
shaderexp_app.link(options);
shaderexp_app.install();
const shaderexp_compile_step = b.step("shaderexp", "Compile shaderexp");
shaderexp_compile_step.dependOn(&shaderexp_app.getInstallStep().?.step);
const shaderexp_run_cmd = shaderexp_app.run();
shaderexp_run_cmd.dependOn(&shaderexp_app.getInstallStep().?.step);
const shaderexp_run_step = b.step("run-shaderexp", "Run shaderexp");
shaderexp_run_step.dependOn(shaderexp_run_cmd);
// compiles the `libmach` shared library
const lib = b.addSharedLibrary("mach", "src/platform/libmach.zig", .unversioned);
lib.setTarget(target);
lib.setBuildMode(mode);
lib.main_pkg_path = "src/";
const app_pkg = std.build.Pkg{
.name = "app",
.source = .{ .path = "src/platform/libmach.zig" },
};
lib.addPackage(app_pkg);
lib.addPackage(gpu.pkg);
lib.addPackage(glfw.pkg);
lib.addPackage(sysaudio.pkg);
if (target.toTarget().os.tag == .linux)
lib.addPackage(gamemode.pkg);
glfw.link(b, lib, options.glfw_options);
gpu.link(b, lib, options.gpuOptions());
gamemode.link(lib);
lib.setOutputDir("./libmach/build");
lib.install();
}
// TODO: we need a way to test wasm stuff
// const sysjs_test_step = b.step( "test-sysjs", "Run sysjs library tests");
// sysjs_test_step.dependOn(&sysjs.testStep(b, mode, target).step);
@ -137,51 +180,8 @@ pub fn build(b: *std.build.Builder) void {
example_run_step.dependOn(example_run_cmd);
}
if (target.toTarget().cpu.arch != .wasm32) {
const shaderexp_app = App.init(
b,
.{
.name = "shaderexp",
.src = "shaderexp/main.zig",
.target = target,
},
);
shaderexp_app.setBuildMode(mode);
shaderexp_app.link(options);
shaderexp_app.install();
const shaderexp_compile_step = b.step("shaderexp", "Compile shaderexp");
shaderexp_compile_step.dependOn(&shaderexp_app.getInstallStep().?.step);
const shaderexp_run_cmd = shaderexp_app.run();
shaderexp_run_cmd.dependOn(&shaderexp_app.getInstallStep().?.step);
const shaderexp_run_step = b.step("run-shaderexp", "Run shaderexp");
shaderexp_run_step.dependOn(shaderexp_run_cmd);
}
const compile_all = b.step("compile-all", "Compile all examples and applications");
compile_all.dependOn(b.getInstallStep());
// compiles the `libmach` shared library
const lib = b.addSharedLibrary("mach", "src/platform/libmach.zig", .unversioned);
lib.setTarget(target);
lib.setBuildMode(mode);
lib.main_pkg_path = "src/";
const app_pkg = std.build.Pkg{
.name = "app",
.source = .{ .path = "src/platform/libmach.zig" },
};
lib.addPackage(app_pkg);
lib.addPackage(gpu.pkg);
lib.addPackage(glfw.pkg);
lib.addPackage(sysaudio.pkg);
if (target.toTarget().os.tag == .linux)
lib.addPackage(gamemode.pkg);
glfw.link(b, lib, options.glfw_options);
gpu.link(b, lib, options.gpuOptions());
gamemode.link(lib);
lib.setOutputDir("./libmach/build");
lib.install();
}
fn testStep(b: *std.build.Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget) *std.build.RunStep {