Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add build.rs config to use rust backends. #91

Merged
merged 3 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ members = [
"cubeb-sys",
"systest"
]
exclude = [
"cubeb-sys/libcubeb/src/cubeb-coreaudio-rs",
"cubeb-sys/libcubeb/src/cubeb-pulse-rs",
]
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"] }
44 changes: 42 additions & 2 deletions cubeb-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<bool>().unwrap();

println!("cargo:rustc-link-lib=static=cubeb");
if windows {
let debug = env::var("DEBUG").unwrap().parse::<bool>().unwrap();
println!("cargo:rustc-link-lib=dylib=avrt");
println!("cargo:rustc-link-lib=dylib=ksuser");
println!("cargo:rustc-link-lib=dylib=ole32");
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cubeb-sys/libcubeb
Loading