Load libasound at runtime, or make the ALSA host optional, so Linux binaries don't require libasound
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 14/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- linux, rust
- Domain
- build-system
Research direction
Start with the ALSA host's is_available(), which currently returns a hardcoded true, and the Host::new(), default_host() and available_hosts() paths that depend on it. The alsa-sys dependency and its pkg-config link are where the runtime-loading option would go. The issue asks for a maintainer decision between two designs (dlopen in alsa-sys, or a default-on alsa feature), so it is not ready for a patch yet. Done would be an agreed design plus a build with no libasound in NEEDED.
Written by the indexing model from the issue text.
Description
Problem
On Linux and the BSDs, cpal always depends on alsa, and alsa-sys links libasound through pkg-config. So every binary that uses cpal has libasound.so.2 in NEEDED, and that has two costs:
- At run time, the binary won't start without libasound (
error while loading shared libraries: libasound.so.2), even when audio is an optional part of a larger program and the host never touches a device: a headless server, a minimal container, a CI runner. - At build time, every build needs the ALSA headers and pkg-config (
libasound2-dev), includingcargo installon a machine that only wants the non-audio parts. This also gets in the way of cross and static builds (see #982 and diwic/alsa-sys#10).
The ALSA host's is_available() is the natural place to report this, but today it returns a hardcoded true.
Proposal
Either of these would solve it. The first is preferred, because it keeps raw ALSA on hosts without a sound server.
- Load libasound at runtime (dlopen). An opt-in feature in which the ALSA host resolves the
snd_*symbols fromlibasound.so.2on first use.is_available()returnsfalsewhen the library is missing,Host::new()returnsHostUnavailable, anddefault_host()/available_hosts()fall through. The loading would most naturally live inalsa-sysbehind a feature (bindgen can generate a dynamic-loading wrapper), and cpal would forward it. The build then needs no ALSA headers or pkg-config either. This is how other audio stacks handle it: SDL (SDL_AUDIO_DRIVER_ALSA_DYNAMIC), miniaudio (runtime linking by default), and Firefox's cubeb all dlopen libasound. - Make the ALSA host optional on Linux. A default-on
alsafeature, so a build withdefault-features = false, features = ["pulseaudio"]uses only the PulseAudio host. That host is built on the pure-Rustpulseaudioprotocol crate, so the build needs no system audio library at all. The cost is that hosts without a sound server have no devices. This is close to thealsafeature being considered for FreeBSD in #1404 (also mentioned in #988 and asked about in #929), extended to Linux.
Use case
moq ships moq-cli, a tool for publishing and playing live media, as prebuilt binaries and through cargo install. Microphone capture and speaker playback go through cpal (0.18.2). On Linux, cpal is the one dependency that links a system library at load time: camera capture needs none, and our hardware video codecs (VA-API, NVENC) already dlopen theirs. So capture and playback are off by default today. Turning them on would make every Linux user install libasound2-dev to cargo install, and the same binary that runs on a desktop wouldn't start on a server or in a container without ALSA, even when it's only publishing a file. We'd like to ship one Linux binary that uses ALSA (or PulseAudio) where it exists and reports no audio host where it doesn't.
(Written by Opus 5.5)
- Dominant language
- Rust
- Stars
- 4k
- Forks
- 554
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 1
Getting set up
- Ships a Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from RustAudio/cpal
-
API design
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
-
correctness
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
-
aaudio: dynamic buffer tuning never grows the buffer (set_buffer_size_in_frames reports Err on success)Possibly taken @dannyward630 claimed this 39 days ago. Openhost - aaudio platform - android
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
-
WebAudio wasm build fails with wasm-bindgen panic=unwind closuresPossibly taken @bogusyogi claimed this 48 days ago. Openhost - webaudio platform - web
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
PipeWire: dropping callback captures on the realtime worker can terminate the process with SIGXCPUOpenhost - pipewire platform - linux
Difficulty 4/5 3-5 days Newbie friendliness 45/100
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
ci: migrate pinned macos-15 runners to macos-26 and macos-26-intelPossibly taken @hawkingrei claimed this today. Openenhancement
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
nowledge-co/hawdb#2224 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
eclipse-score/coverage_tool#95 ·
Maintainers usually reply within 2 days
-
bug nvim
Difficulty 2/5 1-3 hours Newbie friendliness 74/100