Skip to content

Commit

Permalink
Fix test builds.
Browse files Browse the repository at this point in the history
  • Loading branch information
mutexlox-signal authored and padenot committed Oct 17, 2024
1 parent 1185d25 commit e6e74b6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 19 deletions.
6 changes: 6 additions & 0 deletions cubeb-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
53 changes: 34 additions & 19 deletions cubeb-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,18 @@ 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")
// This is safe to set always; it's a no-op if the directories don't
// exist
.define("BUILD_RUST_LIBS", "ON")
.define("BUILD_RUST_LIBS", build_rust_libs)
.build();

let debug = env::var("DEBUG").unwrap().parse::<bool>().unwrap();
Expand All @@ -89,15 +94,20 @@ fn main() {
println!("cargo:rustc-link-lib=framework=CoreServices");
println!("cargo:rustc-link-lib=dylib=c++");

println!("cargo:rustc-link-lib=dylib=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");
// 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={}", search_path.display());

println!("cargo:rustc-link-search=native={}/lib", dst.display());
} else {
Expand All @@ -113,15 +123,20 @@ fn main() {
// libraries are missing.
let _ = pkg_config::find_library("alsa");
if pkg_config::find_library("libpulse").is_ok() {
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");
// 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());
}
println!("cargo:rustc-link-search=native={}", search_path.display());
}
let _ = pkg_config::find_library("jack");
let _ = pkg_config::find_library("speexdsp");
Expand Down

0 comments on commit e6e74b6

Please sign in to comment.