audio: make buildSoundIo private and point package to ./main.zig
This commit is contained in:
parent
0e8b53d840
commit
84f8532c43
1 changed files with 16 additions and 37 deletions
|
|
@ -4,16 +4,8 @@ const Builder = std.build.Builder;
|
||||||
const soundio_path = thisDir() ++ "/upstream/soundio";
|
const soundio_path = thisDir() ++ "/upstream/soundio";
|
||||||
|
|
||||||
pub const pkg = std.build.Pkg{
|
pub const pkg = std.build.Pkg{
|
||||||
.name = "soundio",
|
.name = "mach-audio",
|
||||||
.source = .{ .path = thisDir() ++ "/soundio/main.zig" },
|
.source = .{ .path = thisDir() ++ "/main.zig" },
|
||||||
};
|
|
||||||
|
|
||||||
pub const SoundIoOptions = struct {
|
|
||||||
jack: bool = false,
|
|
||||||
pulseaudio: bool = false,
|
|
||||||
alsa: bool = false,
|
|
||||||
coreaudio: bool = false,
|
|
||||||
wasapi: bool = false,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn build(b: *Builder) void {
|
pub fn build(b: *Builder) void {
|
||||||
|
|
@ -22,19 +14,19 @@ pub fn build(b: *Builder) void {
|
||||||
const soundio_tests = b.addTest("soundio/main.zig");
|
const soundio_tests = b.addTest("soundio/main.zig");
|
||||||
soundio_tests.setBuildMode(mode);
|
soundio_tests.setBuildMode(mode);
|
||||||
soundio_tests.addPackage(pkg);
|
soundio_tests.addPackage(pkg);
|
||||||
link(b, soundio_tests, .{ .alsa = true });
|
link(b, soundio_tests);
|
||||||
|
|
||||||
const test_step = b.step("test", "Run library tests");
|
const test_step = b.step("test", "Run library tests");
|
||||||
test_step.dependOn(&soundio_tests.step);
|
test_step.dependOn(&soundio_tests.step);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn link(b: *Builder, step: *std.build.LibExeObjStep, options: SoundIoOptions) void {
|
pub fn link(b: *Builder, step: *std.build.LibExeObjStep) void {
|
||||||
const soundio_lib = buildSoundIo(b, step, options);
|
const soundio_lib = buildSoundIo(b, step);
|
||||||
step.linkLibrary(soundio_lib);
|
step.linkLibrary(soundio_lib);
|
||||||
step.addIncludePath(soundio_path);
|
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
|
// TODO(build-system): https://github.com/hexops/mach/issues/229#issuecomment-1100958939
|
||||||
ensureDependencySubmodule(b.allocator, "upstream") catch unreachable;
|
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, &.{});
|
lib.addCSourceFiles(soundio_sources, &.{});
|
||||||
|
|
||||||
const target = (std.zig.system.NativeTargetInfo.detect(b.allocator, step.target) catch unreachable).target;
|
const target = (std.zig.system.NativeTargetInfo.detect(b.allocator, step.target) catch unreachable).target;
|
||||||
if (options.jack) {
|
if (target.isDarwin()) {
|
||||||
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.addCSourceFile(soundio_path ++ "/src/coreaudio.c", &.{});
|
||||||
lib.linkFramework("CoreFoundation");
|
lib.linkFramework("CoreFoundation");
|
||||||
lib.linkFramework("CoreAudio");
|
lib.linkFramework("CoreAudio");
|
||||||
config_file.writeAll("#define SOUNDIO_HAVE_COREAUDIO\n") catch unreachable;
|
config_file.writeAll("#define SOUNDIO_HAVE_COREAUDIO\n") catch unreachable;
|
||||||
}
|
} else if (target.os.tag == .linux) {
|
||||||
} else if (options.wasapi and target.os.tag == .windows) {
|
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", &.{});
|
lib.addCSourceFile(soundio_path ++ "/src/wasapi.c", &.{});
|
||||||
config_file.writeAll("#define SOUNDIO_HAVE_WASAPI\n") catch unreachable;
|
config_file.writeAll("#define SOUNDIO_HAVE_WASAPI\n") catch unreachable;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue