diff --git a/Cargo.toml b/Cargo.toml index 62e19bf..3eb0276 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,7 @@ members = [ "cubeb-sys", "systest" ] +exclude = [ + "cubeb-sys/libcubeb/src/cubeb-coreaudio-rs", + "cubeb-sys/libcubeb/src/cubeb-pulse-rs", +] diff --git a/cubeb-sys/Cargo.toml b/cubeb-sys/Cargo.toml index 6bd6976..5765d1d 100644 --- a/cubeb-sys/Cargo.toml +++ b/cubeb-sys/Cargo.toml @@ -15,7 +15,13 @@ circle-ci = { repository = "mozilla/cubeb-rs" } [features] gecko-in-tree = [] +unittest-build = [] [build-dependencies] pkg-config = "0.3" cmake = "0.1.2" + +# Workaround, see build.rs and +# https://github.com/rust-lang/cargo/issues/4789#issuecomment-2308131243 +[dev-dependencies] +cubeb-sys = { path = ".", features = ["unittest-build"] } diff --git a/cubeb-sys/build.rs b/cubeb-sys/build.rs index ee5353b..ef3f9eb 100644 --- a/cubeb-sys/build.rs +++ b/cubeb-sys/build.rs @@ -61,15 +61,24 @@ fn main() { t!(fs::create_dir_all(env::var("OUT_DIR").unwrap())); env::remove_var("DESTDIR"); + + // Do not build the rust backends for tests: doing so causes duplicate + // symbol definitions. + #[cfg(feature = "unittest-build")] + let build_rust_libs = "OFF"; + #[cfg(not(feature = "unittest-build"))] + let build_rust_libs = "ON"; let dst = cfg .define("BUILD_SHARED_LIBS", "OFF") .define("BUILD_TESTS", "OFF") .define("BUILD_TOOLS", "OFF") + .define("BUILD_RUST_LIBS", build_rust_libs) .build(); + let debug = env::var("DEBUG").unwrap().parse::().unwrap(); + println!("cargo:rustc-link-lib=static=cubeb"); if windows { - let debug = env::var("DEBUG").unwrap().parse::().unwrap(); println!("cargo:rustc-link-lib=dylib=avrt"); println!("cargo:rustc-link-lib=dylib=ksuser"); println!("cargo:rustc-link-lib=dylib=ole32"); @@ -84,6 +93,22 @@ fn main() { println!("cargo:rustc-link-lib=framework=CoreAudio"); println!("cargo:rustc-link-lib=framework=CoreServices"); println!("cargo:rustc-link-lib=dylib=c++"); + + // Do not link the rust backends for tests: doing so causes duplicate + // symbol definitions. + #[cfg(not(feature = "unittest-build"))] + { + println!("cargo:rustc-link-lib=static=cubeb_coreaudio"); + let mut search_path = std::env::current_dir().unwrap(); + search_path.push("libcubeb/src/cubeb-coreaudio-rs/target"); + if debug { + search_path.push("debug"); + } else { + search_path.push("release"); + } + println!("cargo:rustc-link-search=native={}", search_path.display()); + } + println!("cargo:rustc-link-search=native={}/lib", dst.display()); } else { if freebsd || android { @@ -97,7 +122,22 @@ fn main() { // Ignore the result of find_library. We don't care if the // libraries are missing. let _ = pkg_config::find_library("alsa"); - let _ = pkg_config::find_library("libpulse"); + if pkg_config::find_library("libpulse").is_ok() { + // Do not link the rust backends for tests: doing so causes duplicate + // symbol definitions. + #[cfg(not(feature = "unittest-build"))] + { + println!("cargo:rustc-link-lib=static=cubeb_pulse"); + let mut search_path = std::env::current_dir().unwrap(); + search_path.push("libcubeb/src/cubeb-pulse/target"); + if debug { + search_path.push("debug"); + } else { + search_path.push("release"); + } + println!("cargo:rustc-link-search=native={}", search_path.display()); + } + } let _ = pkg_config::find_library("jack"); let _ = pkg_config::find_library("speexdsp"); if android { diff --git a/cubeb-sys/libcubeb b/cubeb-sys/libcubeb index 877364f..ffd5184 160000 --- a/cubeb-sys/libcubeb +++ b/cubeb-sys/libcubeb @@ -1 +1 @@ -Subproject commit 877364f0509c9a54f2d7015a6a9b52b4c7c99edc +Subproject commit ffd5184e47b1ca2fe4c3de17643c7695b9be463a