diff --git a/.changeset/headless_linux_build_path.md b/.changeset/headless_linux_build_path.md new file mode 100644 index 000000000..f80a748dc --- /dev/null +++ b/.changeset/headless_linux_build_path.md @@ -0,0 +1,8 @@ +--- +livekit: patch +webrtc-sys: patch +libwebrtc: patch +livekit-ffi: patch +--- + +Add headless Linux build path - #1024 (@mikefaille) diff --git a/Cargo.toml b/Cargo.toml index d16cf17a8..dba905450 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,7 +45,7 @@ license = "Apache-2.0" [workspace.dependencies] device-info = { version = "0.1.0", path = "device-info" } imgproc = { version = "0.3.19", path = "imgproc" } -libwebrtc = { version = "0.3.29", path = "libwebrtc" } +libwebrtc = { version = "0.3.29", path = "libwebrtc", default-features = false } livekit = { version = "0.7.36", path = "livekit" } livekit-api = { version = "0.4.18", path = "livekit-api" } livekit-ffi = { version = "0.12.52", path = "livekit-ffi" } diff --git a/examples/local_audio/Cargo.toml b/examples/local_audio/Cargo.toml index 200f528b3..6d65b9cd8 100644 --- a/examples/local_audio/Cargo.toml +++ b/examples/local_audio/Cargo.toml @@ -9,7 +9,7 @@ tokio = { workspace = true, features = ["full"] } env_logger = { workspace = true } livekit = { workspace = true, features = ["rustls-tls-native-roots"] } livekit-api = { workspace = true, features = ["rustls-tls-native-roots"] } -libwebrtc = { workspace = true } +libwebrtc = { workspace = true, features = ["glib-main-loop"] } log = { workspace = true } cpal = "0.15" anyhow = { workspace = true } diff --git a/examples/local_video/Cargo.toml b/examples/local_video/Cargo.toml index b865a4808..8e9e4efca 100644 --- a/examples/local_video/Cargo.toml +++ b/examples/local_video/Cargo.toml @@ -26,7 +26,7 @@ required-features = ["desktop"] tokio = { workspace = true, features = ["full", "parking_lot"] } livekit = { workspace = true, features = ["rustls-tls-native-roots"] } webrtc-sys = { workspace = true } -libwebrtc = { workspace = true } +libwebrtc = { workspace = true, features = ["glib-main-loop"] } livekit-api = { workspace = true } yuv-sys = { workspace = true, features = ["jpeg"] } futures = { workspace = true } diff --git a/livekit/Cargo.toml b/livekit/Cargo.toml index d3d3441b0..dae2287b7 100644 --- a/livekit/Cargo.toml +++ b/livekit/Cargo.toml @@ -8,11 +8,12 @@ repository.workspace = true [features] # By default ws TLS is not enabled -default = ["tokio"] +default = ["tokio", "glib-main-loop"] async = ["livekit-api/signal-client-async"] tokio = ["livekit-api/signal-client-tokio"] dispatcher = ["livekit-api/signal-client-dispatcher"] +glib-main-loop = ["libwebrtc/glib-main-loop"] # Note that the following features only change the behavior of tokio-tungstenite. diff --git a/webrtc-sys/build.rs b/webrtc-sys/build.rs index 4d779777e..bb4049d8c 100644 --- a/webrtc-sys/build.rs +++ b/webrtc-sys/build.rs @@ -16,6 +16,10 @@ use std::path::Path; use std::path::PathBuf; use std::{env, path, process::Command}; +fn lk_headless() -> bool { + env::var("LK_HEADLESS").map(|v| v == "1" || v.eq_ignore_ascii_case("true")).unwrap_or(false) +} + fn main() { if env::var("DOCS_RS").is_ok() { return; @@ -23,10 +27,13 @@ fn main() { let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap(); let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap(); - let is_desktop = target_os == "linux" || target_os == "windows" || target_os == "macos"; + let headless_linux = target_os == "linux" && lk_headless(); + let is_desktop = + (target_os == "linux" || target_os == "windows" || target_os == "macos") && !headless_linux; println!("cargo:rerun-if-env-changed=LK_DEBUG_WEBRTC"); println!("cargo:rerun-if-env-changed=LK_CUSTOM_WEBRTC"); + println!("cargo:rerun-if-env-changed=LK_HEADLESS"); let mut rust_files = vec![ "src/peer_connection.rs", @@ -166,20 +173,22 @@ fn main() { println!("cargo:rustc-link-lib=dylib=pthread"); println!("cargo:rustc-link-lib=dylib=m"); - // In order to avoid any ABI mismatches we use the sysroot's headers. - add_gio_headers(&mut builder); + if !headless_linux { + // In order to avoid any ABI mismatches we use the sysroot's headers. + add_gio_headers(&mut builder); - for lib_name in ["glib-2.0", "gobject-2.0", "gio-2.0"] { - pkg_config::probe_library(lib_name).unwrap(); - } + for lib_name in ["glib-2.0", "gobject-2.0", "gio-2.0"] { + pkg_config::probe_library(lib_name).unwrap(); + } - add_lazy_load_so( - &mut builder, - "desktop_capturer", - ["drm", "gbm", "X11", "Xfixes", "Xdamage", "Xrandr", "Xcomposite", "Xext"] - .map(String::from) - .to_vec(), - ); + add_lazy_load_so( + &mut builder, + "desktop_capturer", + ["drm", "gbm", "X11", "Xfixes", "Xdamage", "Xrandr", "Xcomposite", "Xext"] + .map(String::from) + .to_vec(), + ); + } let x86 = target_arch == "x86_64" || target_arch == "i686"; let arm = target_arch == "aarch64" || target_arch.contains("arm");