diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4ea3f625..8dfbd1a4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,6 +52,9 @@ jobs: run: nix-shell --arg withRust true --run 'cargo fmt --check' - name: Clippy run: nix-shell --arg withRust true --run 'cargo clippy --all-targets --locked -- -D warnings' + # Without PulseAudio, as static (musl) builds link voxl. + - name: Clippy (no PulseAudio) + run: nix-shell --arg withRust true --run 'cargo clippy --all-targets --locked --no-default-features -- -D warnings' # Unit tests, including the Linux-only ones (dynamic resolution). - name: Test run: nix-shell --arg withRust true --run 'cargo test --locked' diff --git a/Cargo.lock b/Cargo.lock index 9553b2c3..21369ba1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -67,12 +67,6 @@ dependencies = [ "windows-sys 0.61.2", ] -[[package]] -name = "as-raw-xcb-connection" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "175571dd1d178ced59193a6fc02dde1b972eb0bc56c892cde9beeceac5bf0f6b" - [[package]] name = "atomic-waker" version = "1.1.2" @@ -1973,9 +1967,7 @@ version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9993aa5be5a26815fe2c3eacfc1fde061fc1a1f094bf1ad2a18bf9c495dd7414" dependencies = [ - "as-raw-xcb-connection", "gethostname", - "libc", "rustix", "x11rb-protocol", ] diff --git a/Cargo.toml b/Cargo.toml index 3fb4d413..fc0aea5f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,6 +31,13 @@ path = "src/lib.rs" name = "voxl" path = "src/main.rs" +[features] +default = ["pulseaudio"] +# Desktop audio on Linux, from PulseAudio. Without it voxl links no PulseAudio, so it can +# be built static (musl) and runs without its libraries, but has no desktop audio on +# Linux. macOS and Windows don't use it. +pulseaudio = [] + [dependencies] tokio = { version = "1", features = [ "rt-multi-thread", @@ -90,7 +97,6 @@ x11rb = { version = "0.13", features = [ "shape", "xinput", "randr", - "allow-unsafe-code", ] } [target.'cfg(target_os = "macos")'.dependencies] diff --git a/README.md b/README.md index caa6be26..58d15298 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,9 @@ nix-shell cargo build --release ``` +On Linux, `--no-default-features` leaves out PulseAudio, and with it desktop audio: a +voxl that can be linked statically (musl) and runs without PulseAudio's libraries. + Or install it from [crates.io](https://crates.io/crates/voxl-server) with the same libraries on your system (the crate is `voxl-server`, the binary is `voxl`): diff --git a/build.rs b/build.rs index a793a8c1..29721d4e 100644 --- a/build.rs +++ b/build.rs @@ -32,14 +32,17 @@ fn main() { println!("cargo:rerun-if-changed=build.rs"); } -/// x264, libyuv, Opus and PulseAudio from pkg-config; returns x264's include paths. +/// x264, libyuv, Opus and PulseAudio (with the pulseaudio feature) from pkg-config; +/// returns x264's include paths. fn unix_libs(target: &str) -> Vec { let x264 = pkg_config::probe_library("x264").expect("x264"); // macOS captures NV12 (no libyuv) and gets audio from ScreenCaptureKit (no PulseAudio). let libs: &[&str] = if target == "macos" { &["opus"] - } else { + } else if std::env::var_os("CARGO_FEATURE_PULSEAUDIO").is_some() { &["libyuv", "opus", "libpulse-simple"] + } else { + &["libyuv", "opus"] }; let others: Vec<_> = libs .iter() diff --git a/src/lib.rs b/src/lib.rs index 937e44de..1c9d6313 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,7 +5,7 @@ //! `tembo voxl`) embed the server the same way. mod access; -#[cfg(target_os = "linux")] +#[cfg(all(target_os = "linux", feature = "pulseaudio"))] mod audio; #[cfg(target_os = "linux")] mod capture; @@ -182,6 +182,11 @@ async fn serve(a: HashMap) { to_client: matches!(clip, "true" | "out"), }; let audio_on = truthy(a.get("audio-enabled"), true); + #[cfg(all(target_os = "linux", not(feature = "pulseaudio")))] + let audio_on = audio_on && { + log::info!("desktop audio off: this voxl was built without PulseAudio"); + false + }; let hub = hub::Hub::new(); // --read-only: the viewer watches the desktop, it does not drive it. Only the @@ -255,6 +260,7 @@ async fn serve(a: HashMap) { Ok(tx) => *hub.input.lock() = Some(tx), Err(e) => log::error!("input init failed: {e}"), } + #[cfg(any(not(target_os = "linux"), feature = "pulseaudio"))] if audio_on { let dev = a .get("audio-device-name")