diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3389c86 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.zig-cache/ +zig-out/ diff --git a/.mise.toml b/.mise.toml new file mode 100644 index 0000000..4ef9eaf --- /dev/null +++ b/.mise.toml @@ -0,0 +1,11 @@ +[tools] +zig = "0.15.1" +zls = "0.15.0" +pre-commit = "latest" +"ubi:DonIsaac/zlint" = "latest" + +[hooks] +enter = 'echo use "nix develop" if you want to build' + +[settings] +experimental = true diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..506dadd --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Emil Lerch + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/build.zig b/build.zig new file mode 100644 index 0000000..18e5be9 --- /dev/null +++ b/build.zig @@ -0,0 +1,172 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + + const upstream = b.dependency("alsa-lib", .{}); + + // Create config header matching autotools output + const config = b.addConfigHeader(.{ + .style = .blank, + .include_path = "config.h", + }, .{ + .PACKAGE_NAME = "alsa-lib", + .VERSION = "1.2.14", + .HAVE_USELOCALE = 1, + .HAVE_EACCESS = 1, + .HAVE_ENDIAN_H = 1, + .HAVE_SYS_SHM_H = 1, + .HAVE_MALLOC_H = 1, + .HAVE_LFS = 1, + .HAVE_LIBDL = 1, + .PIC = 1, + .BUILD_PCM = "1", + .BUILD_MIXER = "1", + .BUILD_HWDEP = "1", + .ALSA_DEVICE_DIRECTORY = "/dev/snd/", + .ALSA_CONFIG_DIR = "/usr/share/alsa", + .ALSA_PLUGIN_DIR = "/usr/lib/alsa-lib", + .SND_MAX_CARDS = 32, + .__SYMBOL_PREFIX = "", + ._GNU_SOURCE = 1, + .HAVE_GNU_LD = 1, + .HAVE_ELF = 1, + .HAVE_ASM_PREVIOUS_DIRECTIVE = 1, + }); + + // Create version.h + const version_h = b.addWriteFiles(); + _ = version_h.add("version.h", + \\/* + \\ * version.h + \\ */ + \\ + \\#define SND_LIB_MAJOR 1 /**< major number of library version */ + \\#define SND_LIB_MINOR 2 /**< minor number of library version */ + \\#define SND_LIB_SUBMINOR 14 /**< subminor number of library version */ + \\#define SND_LIB_EXTRAVER 1000000 /**< extra version number, used mainly for betas */ + \\/** library version */ + \\#define SND_LIB_VER(maj, min, sub) (((maj)<<16)|((min)<<8)|(sub)) + \\#define SND_LIB_VERSION SND_LIB_VER(SND_LIB_MAJOR, SND_LIB_MINOR, SND_LIB_SUBMINOR) + \\/** library version (string) */ + \\#define SND_LIB_VERSION_STR "1.2.14" + \\ + ); + + // Generate asoundlib.h + const asoundlib_h = b.addWriteFiles(); + _ = asoundlib_h.add("asoundlib.h", + \\/* + \\ * ALSA library - main header file + \\ */ + \\ + \\#ifndef __ALSA_ASOUNDLIB_H + \\#define __ALSA_ASOUNDLIB_H + \\ + \\#include + \\#include + \\#include + \\#include + \\#include + \\#include + \\#include + \\#include + \\#include + \\#include + \\#include + \\ + \\#include + \\#include + \\#include + \\#include + \\#include + \\#include + \\#include + \\#include + \\#include + \\ + \\#endif /* __ALSA_ASOUNDLIB_H */ + \\ + ); + + const lib = b.addLibrary(.{ + .name = "asound", + .linkage = .static, + .root_module = b.createModule(.{ + .target = target, + .optimize = optimize, + .link_libc = true, + }), + }); + + lib.addConfigHeader(config); + lib.addIncludePath(upstream.path("include")); + lib.addIncludePath(version_h.getDirectory()); + lib.addIncludePath(asoundlib_h.getDirectory()); + + // Create alsa as symlink for the include directory. Not sure why upstream + // does this, but since we're not using their scripts, we need to do that + // as well + const create_symlink = b.addSystemCommand(&.{ "sh", "-c", "rm -f alsa; ln -sf . alsa" }); + create_symlink.setCwd(upstream.path("include")); + lib.step.dependOn(&create_symlink.step); + + lib.addCSourceFiles(.{ + .root = upstream.path(""), + .files = &.{ + "src/conf.c", + "src/confeval.c", + "src/confmisc.c", + "src/input.c", + "src/output.c", + "src/async.c", + "src/error.c", + "src/dlmisc.c", + "src/socket.c", + "src/shmarea.c", + "src/userfile.c", + "src/names.c", + "src/control/control.c", + "src/control/control_hw.c", + "src/control/cards.c", + "src/control/namehint.c", + "src/control/hcontrol.c", + "src/control/tlv.c", + "src/control/setup.c", + "src/control/ctlparse.c", + "src/control/eld.c", + "src/pcm/pcm.c", + "src/pcm/pcm_hw.c", + "src/pcm/pcm_params.c", + "src/pcm/pcm_misc.c", + "src/pcm/pcm_mmap.c", + "src/pcm/mask.c", + "src/pcm/interval.c", + }, + .flags = &.{ + "-D_GNU_SOURCE", + "-DALSA_LIBRARY_BUILD", + }, + }); + + lib.installHeadersDirectory(upstream.path("include"), "alsa", .{ + .include_extensions = &.{ + "asoundef.h", + "version.h", + "global.h", + "input.h", + "output.h", + "error.h", + "conf.h", + "control.h", + "pcm.h", + }, + }); + + // Install generated asoundlib.h and version.h + lib.installHeader(asoundlib_h.getDirectory().path(b, "asoundlib.h"), "alsa/asoundlib.h"); + lib.installHeader(version_h.getDirectory().path(b, "version.h"), "alsa/version.h"); + + b.installArtifact(lib); +} diff --git a/build.zig.zon b/build.zig.zon new file mode 100644 index 0000000..fdda73f --- /dev/null +++ b/build.zig.zon @@ -0,0 +1,18 @@ +.{ + .name = .alsa, + .version = "1.2.14", + .minimum_zig_version = "0.15.1", + .fingerprint = 0xddb406c516c1eb8d, + .dependencies = .{ + .@"alsa-lib" = .{ + .url = "git+https://github.com/alsa-project/alsa-lib?ref=v1.2.14#81d70a27136840fa8fb1bec6eb8e04fc1475a380", + .hash = "N-V-__8AACPMQgBfqlZq9Kx2qUwCMrZVkl-5dDd5bVDiF06E", + }, + }, + .paths = .{ + "LICENSE", + "README.md", + "build.zig", + "build.zig.zon", + }, +}