Skip to content

Commit

Permalink
Clone libcubeb and submodules to OUT_DIR when not present. (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
kinetiknz authored Oct 31, 2024
1 parent c0ec36e commit edef7f8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cubeb-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["Dan Glastonbury <[email protected]>"]
repository = "https://github.com/mozilla/cubeb-rs"
license = "ISC"
description = "Native bindings to the cubeb library"
exclude = ["libcubeb/googletest/"]
exclude = ["libcubeb/"]

This comment has been minimized.

Copy link
@mutexlox-signal

mutexlox-signal Nov 1, 2024

Contributor

I think this is not a correct change as is: docs.rs will run without a network connection, so git clone will fail


links = "cubeb"
build = "build.rs"
Expand Down
47 changes: 35 additions & 12 deletions cubeb-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,48 @@ fn main() {
return;
}

if !Path::new("libcubeb/.git").exists() {
let _ = fs::remove_dir_all(env::var("OUT_DIR").unwrap());
t!(fs::create_dir_all(env::var("OUT_DIR").unwrap()));

env::remove_var("DESTDIR");

let libcubeb_path = if Path::new("libcubeb").exists() {
"libcubeb".to_owned()
} else {
env::var("OUT_DIR").unwrap() + "/libcubeb"
};

if !Path::new(&libcubeb_path).exists() {
let _ = Command::new("git")
.args(["submodule", "update", "--init", "--recursive"])
.args([
"clone",
"-q",
"--filter=tree:0",
"https://github.com/mozilla/cubeb",
&libcubeb_path,
])
.status();
let _ = Command::new("git")
.args([
"-C",
&libcubeb_path,
"submodule",
"update",
"--init",
"--recursive",
])
.status();
}
let libcubeb_rust_exists = Path::new("libcubeb/src/cubeb-coreaudio-rs").exists()
&& Path::new("libcubeb/src/cubeb-pulse-rs").exists();
let libcubeb_rust_exists = Path::new(&(libcubeb_path.clone() + "/src/cubeb-coreaudio-rs"))
.exists()
&& Path::new(&(libcubeb_path.clone() + "/src/cubeb-pulse-rs")).exists();

let target = env::var("TARGET").unwrap();
let windows = target.contains("windows");
let darwin = target.contains("darwin");
let freebsd = target.contains("freebsd");
let android = target.contains("android");
let mut cfg = cmake::Config::new("libcubeb");
let mut cfg = cmake::Config::new(&libcubeb_path);

if darwin {
let cmake_osx_arch = if target.contains("aarch64") {
Expand All @@ -59,11 +87,6 @@ fn main() {
cfg.define("CMAKE_OSX_ARCHITECTURES", cmake_osx_arch);
}

let _ = fs::remove_dir_all(env::var("OUT_DIR").unwrap());
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")]
Expand Down Expand Up @@ -103,7 +126,7 @@ fn main() {
{
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");
search_path.push(&(libcubeb_path + "/src/cubeb-coreaudio-rs/target"));
if debug {
search_path.push("debug");
} else {
Expand Down Expand Up @@ -133,7 +156,7 @@ fn main() {
{
println!("cargo:rustc-link-lib=static=cubeb_pulse");
let mut search_path = std::env::current_dir().unwrap();
search_path.push("libcubeb/src/cubeb-pulse-rs/target");
search_path.push(&(libcubeb_path + "/src/cubeb-pulse-rs/target"));
if debug {
search_path.push("debug");
} else {
Expand Down

0 comments on commit edef7f8

Please sign in to comment.