diff options
Diffstat (limited to 'build.zig')
-rw-r--r-- | build.zig | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/build.zig b/build.zig index 67f6993..aa7fbff 100644 --- a/build.zig +++ b/build.zig @@ -18,12 +18,20 @@ const std = @import("std"); const Build = std.Build; +const Compile = Build.Step.Compile; const CrossTarget = std.zig.CrossTarget; -const LibExeObjStep = std.build.LibExeObjStep; +const Module = Build.Module; const OptimizeMode = std.builtin.OptimizeMode; +/// Link given library, executable, or object with shared libraries. +pub fn link(compile: *Compile) void { + compile.linkSystemLibrary("openal"); + compile.linkSystemLibrary("sndfile"); + compile.linkSystemLibrary("c"); +} + fn addExampleStep(comptime name: []const u8, description: []const u8, - b: *Build, lib: *LibExeObjStep, + b: *Build, module: *Module, target: CrossTarget, optimize: OptimizeMode) void { const bin = b.addExecutable(.{ .name = name, @@ -31,23 +39,16 @@ fn addExampleStep(comptime name: []const u8, description: []const u8, .target = target, .optimize = optimize, }); - bin.addPackagePath("zeal", "src/zeal.zig"); - bin.linkLibrary(lib); + bin.addModule("zeal", module); + link(bin); - const cmd = bin.run(); + const cmd = b.addRunArtifact(bin); cmd.step.dependOn(b.getInstallStep()); if (b.args) |args| cmd.addArgs(args); b.step(name, description).dependOn(&cmd.step); } -/// Link given library, executable, or object with shared libraries. -pub fn link(lib_exe_obj: *LibExeObjStep) void { - lib_exe_obj.linkSystemLibrary("openal"); - lib_exe_obj.linkSystemLibrary("sndfile"); - lib_exe_obj.linkSystemLibrary("c"); -} - pub fn build(b: *Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); @@ -67,6 +68,9 @@ pub fn build(b: *Build) void { main_tests.linkLibrary(lib); b.step("test", "Run library tests").dependOn(&main_tests.step); - //addExampleStep("play", "Play audio", b, lib, target, optimize); - //addExampleStep("hrtf", "Play audio with HRTF", b, lib, target, optimize); + const module = b.createModule(.{ + .source_file = .{ .path = "src/zeal.zig" }, + }); + addExampleStep("play", "Play audio", b, module, target, optimize); + addExampleStep("hrtf", "Play audio with HRTF", b, module, target, optimize); } |