audio: make buildSoundIo private and point package to ./main.zig

This commit is contained in:
alichraghi 2022-06-30 00:05:13 +04:30 committed by Stephen Gutekanst
parent 0e8b53d840
commit 84f8532c43

View file

@ -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()) {
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 (options.wasapi and target.os.tag == .windows) {
} 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;
}