From 46a805bc903b773282ea8cc19295c861295c5a55 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Wed, 8 Feb 2023 01:14:27 -0700 Subject: [PATCH] sysaudio: update to latest Zig build API Signed-off-by: Stephen Gutekanst --- libs/sysaudio/build.zig | 17 ++++++++++------- libs/sysaudio/sdk.zig | 29 ++++++++++++++++++----------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/libs/sysaudio/build.zig b/libs/sysaudio/build.zig index a7e15679..d432556d 100644 --- a/libs/sysaudio/build.zig +++ b/libs/sysaudio/build.zig @@ -3,8 +3,8 @@ const sysaudio_sdk = @import("sdk.zig"); const system_sdk = @import("libs/mach-glfw/system_sdk.zig"); const sysjs = @import("libs/mach-sysjs/build.zig"); -pub fn build(b: *std.build.Builder) void { - const mode = b.standardReleaseOptions(); +pub fn build(b: *std.Build) void { + const optimize = b.standardOptimizeOption(.{}); const target = b.standardTargetOptions(.{}); const sysaudio = sysaudio_sdk.Sdk(.{ .system_sdk = system_sdk, @@ -12,15 +12,18 @@ pub fn build(b: *std.build.Builder) void { }); const test_step = b.step("test", "Run library tests"); - test_step.dependOn(&sysaudio.testStep(b, mode, target).step); + test_step.dependOn(&sysaudio.testStep(b, optimize, target).step); inline for ([_][]const u8{ "sine-wave", }) |example| { - const example_exe = b.addExecutable("example-" ++ example, "examples/" ++ example ++ ".zig"); - example_exe.setBuildMode(mode); - example_exe.setTarget(target); - example_exe.addPackage(sysaudio.pkg); + const example_exe = b.addExecutable(.{ + .name = "example-" ++ example, + .root_source_file = .{ .path = "examples/" ++ example ++ ".zig" }, + .target = target, + .optimize = optimize, + }); + example_exe.addModule("sysaudio", sysaudio.module(b)); sysaudio.link(b, example_exe, .{}); example_exe.install(); diff --git a/libs/sysaudio/sdk.zig b/libs/sysaudio/sdk.zig index 078d02b7..a671ce83 100644 --- a/libs/sysaudio/sdk.zig +++ b/libs/sysaudio/sdk.zig @@ -2,12 +2,6 @@ const std = @import("std"); pub fn Sdk(comptime deps: anytype) type { return struct { - pub const pkg = std.build.Pkg{ - .name = "sysaudio", - .source = .{ .path = sdkPath("/src/main.zig") }, - .dependencies = &.{deps.sysjs.pkg}, - }; - pub const Options = struct { install_libs: bool = false, @@ -15,16 +9,29 @@ pub fn Sdk(comptime deps: anytype) type { system_sdk: deps.system_sdk.Options = .{}, }; - pub fn testStep(b: *std.build.Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget) *std.build.RunStep { - const main_tests = b.addTestExe("sysaudio-tests", sdkPath("/src/main.zig")); - main_tests.setBuildMode(mode); - main_tests.setTarget(target); + pub fn module(b: *std.Build) *std.build.Module { + return b.createModule(.{ + .source_file = .{ .path = sdkPath("/src/main.zig") }, + .dependencies = &.{ + .{ .name = "sysjs", .module = deps.sysjs.module(b) }, + }, + }); + } + + pub fn testStep(b: *std.Build, optimize: std.builtin.OptimizeMode, target: std.zig.CrossTarget) *std.build.RunStep { + const main_tests = b.addTest(.{ + .name = "sysaudio-tests", + .kind = .test_exe, + .root_source_file = .{ .path = sdkPath("/src/main.zig") }, + .target = target, + .optimize = optimize, + }); link(b, main_tests, .{}); main_tests.install(); return main_tests.run(); } - pub fn link(b: *std.build.Builder, step: *std.build.LibExeObjStep, options: Options) void { + pub fn link(b: *std.Build, step: *std.build.CompileStep, options: Options) void { if (step.target.toTarget().cpu.arch != .wasm32) { // TODO(build-system): pass system SDK options through deps.system_sdk.include(b, step, .{});