From 84f8532c43a740220514f4ff25c6960d5c5e16c1 Mon Sep 17 00:00:00 2001 From: alichraghi Date: Thu, 30 Jun 2022 00:05:13 +0430 Subject: [PATCH] audio: make `buildSoundIo` private and point package to `./main.zig` --- audio/build.zig | 53 +++++++++++++++---------------------------------- 1 file changed, 16 insertions(+), 37 deletions(-) diff --git a/audio/build.zig b/audio/build.zig index cfb58b3f..07a12a6d 100644 --- a/audio/build.zig +++ b/audio/build.zig @@ -4,16 +4,8 @@ const Builder = std.build.Builder; const soundio_path = thisDir() ++ "/upstream/soundio"; pub const pkg = std.build.Pkg{ - .name = "soundio", - .source = .{ .path = thisDir() ++ "/soundio/main.zig" }, -}; - -pub const SoundIoOptions = struct { - jack: bool = false, - pulseaudio: bool = false, - alsa: bool = false, - coreaudio: bool = false, - wasapi: bool = false, + .name = "mach-audio", + .source = .{ .path = thisDir() ++ "/main.zig" }, }; pub fn build(b: *Builder) void { @@ -22,19 +14,19 @@ pub fn build(b: *Builder) void { const soundio_tests = b.addTest("soundio/main.zig"); soundio_tests.setBuildMode(mode); soundio_tests.addPackage(pkg); - link(b, soundio_tests, .{ .alsa = true }); + link(b, soundio_tests); const test_step = b.step("test", "Run library tests"); test_step.dependOn(&soundio_tests.step); } -pub fn link(b: *Builder, step: *std.build.LibExeObjStep, options: SoundIoOptions) void { - const soundio_lib = buildSoundIo(b, step, options); +pub fn link(b: *Builder, step: *std.build.LibExeObjStep) void { + const soundio_lib = buildSoundIo(b, step); step.linkLibrary(soundio_lib); step.addIncludePath(soundio_path); } -pub fn buildSoundIo(b: *Builder, step: *std.build.LibExeObjStep, options: SoundIoOptions) *std.build.LibExeObjStep { +fn buildSoundIo(b: *Builder, step: *std.build.LibExeObjStep) *std.build.LibExeObjStep { // TODO(build-system): https://github.com/hexops/mach/issues/229#issuecomment-1100958939 ensureDependencySubmodule(b.allocator, "upstream") catch unreachable; @@ -60,29 +52,16 @@ pub fn buildSoundIo(b: *Builder, step: *std.build.LibExeObjStep, options: SoundI lib.addCSourceFiles(soundio_sources, &.{}); const target = (std.zig.system.NativeTargetInfo.detect(b.allocator, step.target) catch unreachable).target; - if (options.jack) { - lib.addCSourceFile(soundio_path ++ "/src/jack.c", &.{}); - lib.linkSystemLibrary("jack"); - config_file.writeAll("#define SOUNDIO_HAVE_JACK\n") catch unreachable; - } - if (target.isBSD() or target.os.tag == .linux) { - if (options.pulseaudio) { - lib.addCSourceFile(soundio_path ++ "/src/pulseaudio.c", &.{}); - lib.linkSystemLibrary("pulse"); - config_file.writeAll("#define SOUNDIO_HAVE_PULSEAUDIO\n") catch unreachable; - } - if (options.alsa) { - lib.addCSourceFile(soundio_path ++ "/src/alsa.c", &.{}); - lib.linkSystemLibrary("asound"); - config_file.writeAll("#define SOUNDIO_HAVE_ALSA\n") catch unreachable; - } - if (options.coreaudio and target.isDarwin()) { - lib.addCSourceFile(soundio_path ++ "/src/coreaudio.c", &.{}); - lib.linkFramework("CoreFoundation"); - lib.linkFramework("CoreAudio"); - config_file.writeAll("#define SOUNDIO_HAVE_COREAUDIO\n") catch unreachable; - } - } else if (options.wasapi and target.os.tag == .windows) { + if (target.isDarwin()) { + lib.addCSourceFile(soundio_path ++ "/src/coreaudio.c", &.{}); + lib.linkFramework("CoreFoundation"); + lib.linkFramework("CoreAudio"); + config_file.writeAll("#define SOUNDIO_HAVE_COREAUDIO\n") catch unreachable; + } else if (target.os.tag == .linux) { + lib.addCSourceFile(soundio_path ++ "/src/alsa.c", &.{}); + lib.linkSystemLibrary("asound"); + config_file.writeAll("#define SOUNDIO_HAVE_ALSA\n") catch unreachable; + } else if (target.os.tag == .windows) { lib.addCSourceFile(soundio_path ++ "/src/wasapi.c", &.{}); config_file.writeAll("#define SOUNDIO_HAVE_WASAPI\n") catch unreachable; }