diff options
-rw-r--r-- | build.zig | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/build.zig b/build.zig index 9dd9fa2..11c7deb 100644 --- a/build.zig +++ b/build.zig @@ -17,8 +17,25 @@ // along with zeal. If not, see <https://www.gnu.org/licenses/>. const std = @import("std"); +const Builder = std.build.Builder; +const LibExeObjStep = std.build.LibExeObjStep; +const Mode = std.builtin.Mode; -pub fn build(b: *std.build.Builder) void { +fn addExampleStep(comptime name: []const u8, description: []const u8, + b: *Builder, lib: *LibExeObjStep, mode: Mode) void { + const bin = b.addExecutable(name, "examples/" ++ name ++ ".zig"); + bin.addPackagePath("zeal", "src/zeal.zig"); + bin.linkLibrary(lib); + bin.setBuildMode(mode); + + const cmd = bin.run(); + cmd.step.dependOn(b.getInstallStep()); + if (b.args) |args| + cmd.addArgs(args); + b.step(name, description).dependOn(&cmd.step); +} + +pub fn build(b: *Builder) void { // Standard release options allow the person running `zig build` to select // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. const mode = b.standardReleaseOptions(); @@ -33,19 +50,8 @@ pub fn build(b: *std.build.Builder) void { var main_tests = b.addTest("src/zeal.zig"); main_tests.linkLibrary(lib); main_tests.setBuildMode(mode); + b.step("test", "Run library tests").dependOn(&main_tests.step); - const test_step = b.step("test", "Run library tests"); - test_step.dependOn(&main_tests.step); - - const example_play = b.addExecutable("zeal-play", "examples/play.zig"); - example_play.addPackagePath("zeal", "src/zeal.zig"); - example_play.linkLibrary(lib); - example_play.setBuildMode(mode); - example_play.install(); - - const example_hrtf = b.addExecutable("zeal-hrtf", "examples/hrtf.zig"); - example_hrtf.addPackagePath("zeal", "src/zeal.zig"); - example_hrtf.linkLibrary(lib); - example_hrtf.setBuildMode(mode); - example_hrtf.install(); + addExampleStep("play", "Play audio", b, lib, mode); + addExampleStep("hrtf", "Play audio with HRTF", b, lib, mode); } |