diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..2760fdc --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,3 @@ +[alias] +xtask = "run --package xtask --" + diff --git a/Cargo.toml b/Cargo.toml index 3eb0276..0420356 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,12 @@ [workspace] +resolver = "2" members = [ "cubeb-core", "cubeb-api", "cubeb-backend", "cubeb-sys", - "systest" + "systest", + "xtask", ] exclude = [ "cubeb-sys/libcubeb/src/cubeb-coreaudio-rs", diff --git a/cubeb-api/Cargo.toml b/cubeb-api/Cargo.toml index 2b4bec5..abde039 100644 --- a/cubeb-api/Cargo.toml +++ b/cubeb-api/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cubeb" -version = "0.18.0" +version = "0.20.0" authors = ["Dan Glastonbury "] license = "ISC" readme = "README.md" @@ -19,4 +19,4 @@ circle-ci = { repository = "mozilla/cubeb-rs" } gecko-in-tree = ["cubeb-core/gecko-in-tree"] [dependencies] -cubeb-core = { path = "../cubeb-core", version = "0.18.0" } +cubeb-core = { path = "../cubeb-core", version = "0.20.0" } diff --git a/cubeb-backend/Cargo.toml b/cubeb-backend/Cargo.toml index 12d44a6..5dbc7e8 100644 --- a/cubeb-backend/Cargo.toml +++ b/cubeb-backend/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cubeb-backend" -version = "0.18.0" +version = "0.20.0" authors = ["Dan Glastonbury "] license = "ISC" keywords = ["cubeb"] @@ -18,4 +18,4 @@ circle-ci = { repository = "mozilla/cubeb-rs" } gecko-in-tree = ["cubeb-core/gecko-in-tree"] [dependencies] -cubeb-core = { path = "../cubeb-core", version = "0.18.0" } +cubeb-core = { path = "../cubeb-core", version = "0.20.0" } diff --git a/cubeb-backend/tests/test_capi.rs b/cubeb-backend/tests/test_capi.rs index 8549f2d..d1e8ac2 100644 --- a/cubeb-backend/tests/test_capi.rs +++ b/cubeb-backend/tests/test_capi.rs @@ -3,7 +3,7 @@ // This program is made available under an ISC-style license. See the // accompanying file LICENSE for details -#![cfg_attr(feature = "cargo-clippy", allow(clippy::float_cmp))] +#![allow(clippy::float_cmp)] #[macro_use] extern crate cubeb_backend; diff --git a/cubeb-core/Cargo.toml b/cubeb-core/Cargo.toml index d5aa053..62684a9 100644 --- a/cubeb-core/Cargo.toml +++ b/cubeb-core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cubeb-core" -version = "0.18.0" +version = "0.20.0" authors = ["Dan Glastonbury "] license = "ISC" keywords = ["cubeb"] @@ -19,7 +19,7 @@ gecko-in-tree = ["cubeb-sys/gecko-in-tree"] [dependencies] bitflags = "1.2.0" -cubeb-sys = { path = "../cubeb-sys", version = "0.18" } +cubeb-sys = { path = "../cubeb-sys", version = "0.20" } [build-dependencies] cc = "1.1.30" diff --git a/cubeb-sys/Cargo.toml b/cubeb-sys/Cargo.toml index 7269471..f1838c6 100644 --- a/cubeb-sys/Cargo.toml +++ b/cubeb-sys/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "cubeb-sys" -version = "0.18.0" +version = "0.20.0" authors = ["Dan Glastonbury "] repository = "https://github.com/mozilla/cubeb-rs" license = "ISC" description = "Native bindings to the cubeb library" -exclude = ["libcubeb/"] +exclude = ["libcubeb/googletest"] links = "cubeb" build = "build.rs" diff --git a/cubeb-sys/build.rs b/cubeb-sys/build.rs index 7f5a790..7723d69 100644 --- a/cubeb-sys/build.rs +++ b/cubeb-sys/build.rs @@ -33,33 +33,50 @@ fn main() { return; } + if env::var("DOCS_RS").is_ok() { + // Use stubs, not libcubeb, for docs.rs. + return; + } + let _ = fs::remove_dir_all(env::var("OUT_DIR").unwrap()); t!(fs::create_dir_all(env::var("OUT_DIR").unwrap())); env::remove_var("DESTDIR"); - if env::var("DOCS_RS").is_ok() { - // Use stubs, not libcubeb, for docs.rs. - return; + // Copy libcubeb to the output directory. + let libcubeb_path = format!("{}/libcubeb", env::var("OUT_DIR").unwrap()); + t!(Command::new("cp") + .args(["-r", "libcubeb", &env::var("OUT_DIR").unwrap(),]) + .status()); + + fn visit_dirs(dir: &Path, cb: &dyn Fn(&fs::DirEntry)) -> std::io::Result<()> { + if dir.is_dir() { + for entry in fs::read_dir(dir)? { + let entry = entry?; + let path = entry.path(); + if path.is_dir() { + visit_dirs(&path, cb)?; + } else { + cb(&entry); + } + } + } + Ok(()) } - - // If the libcubeb submodule is present, use that. - let libcubeb_path = if Path::new("libcubeb").exists() { - "libcubeb".to_owned() - } else { - // If the submodule is not present, we're building in a packaged environment - // so we expected a vendored copy of the source to be available. - // Vendored copy generated with: - // "tar -c -f libcubeb_vendored.tar --exclude libcubeb/googletest libcubeb" - t!(Command::new("tar") - .args([ - "xvfC", - "libcubeb_vendored.tar", - &env::var("OUT_DIR").unwrap(), - ]) - .status()); - env::var("OUT_DIR").unwrap() + "/libcubeb" - }; + // For packaged build: rename libcubeb Cargo.toml.in files to Cargo.toml. + t!(visit_dirs(Path::new(&libcubeb_path), &|entry| { + let path = entry.path(); + if path + .file_name() + .unwrap() + .to_str() + .unwrap() + .ends_with("Cargo.toml.in") + { + let new_path = path.with_file_name("Cargo.toml"); + fs::rename(&path, &new_path).unwrap(); + } + })); let target = env::var("TARGET").unwrap(); let windows = target.contains("windows"); diff --git a/cubeb-sys/libcubeb_vendored.tar b/cubeb-sys/libcubeb_vendored.tar deleted file mode 100644 index 25257dc..0000000 Binary files a/cubeb-sys/libcubeb_vendored.tar and /dev/null differ diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml new file mode 100644 index 0000000..0c28be4 --- /dev/null +++ b/xtask/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "xtask" +version = "0.3.0" +edition = "2021" +publish = false +release = false + +[dependencies] diff --git a/xtask/src/main.rs b/xtask/src/main.rs new file mode 100644 index 0000000..d151f2f --- /dev/null +++ b/xtask/src/main.rs @@ -0,0 +1,134 @@ +use std::{ + env, fs, + path::{Path, PathBuf}, + process::Command, +}; + +type DynError = Box; + +fn main() { + if let Err(e) = try_main() { + eprintln!("{}", e); + std::process::exit(-1); + } +} + +fn try_main() -> Result<(), DynError> { + let task = env::args().nth(1); + match task.as_deref() { + Some("release") => release()?, + _ => print_help(), + } + Ok(()) +} + +fn print_help() { + eprintln!( + "Tasks: + +release runs 'cargo release' after preparing the source directory +" + ) +} + +fn visit_dirs(dir: &Path, cb: &dyn Fn(&fs::DirEntry)) -> std::io::Result<()> { + if dir.is_dir() { + for entry in fs::read_dir(dir)? { + let entry = entry?; + let path = entry.path(); + if path.is_dir() { + visit_dirs(&path, cb)?; + } else { + cb(&entry); + } + } + } + Ok(()) +} + +fn release() -> Result<(), DynError> { + let cargo = env::var("CARGO").unwrap_or_else(|_| "cargo".to_string()); + + let status = Command::new(&cargo) + .current_dir(project_root()) + .args(["release", "--workspace", "minor", "-x", "--no-publish"]) + .status()?; + + if !status.success() { + Err("cargo release failed")?; + } + + // For packaged build: rename libcubeb Cargo.toml files to Cargo.toml.in. + visit_dirs(Path::new("cubeb-sys/libcubeb"), &|entry| { + let path = entry.path(); + if path + .file_name() + .unwrap() + .to_str() + .unwrap() + .ends_with("Cargo.toml") + { + let new_path = path.with_file_name("Cargo.toml.in"); + fs::rename(&path, &new_path).unwrap(); + } + }) + .unwrap(); + + let status = Command::new(&cargo) + .current_dir(project_root()) + .args(["publish", "--package", "cubeb-sys", "--allow-dirty"]) + .status()?; + if !status.success() { + Err("cargo publish failed")?; + } + + // Rename libcubeb Cargo.toml.in files back to Cargo.toml. + visit_dirs(Path::new("cubeb-sys/libcubeb"), &|entry| { + let path = entry.path(); + if path + .file_name() + .unwrap() + .to_str() + .unwrap() + .ends_with("Cargo.toml.in") + { + let new_path = path.with_file_name("Cargo.toml"); + fs::rename(&path, &new_path).unwrap(); + } + }) + .unwrap(); + + let status = Command::new(&cargo) + .current_dir(project_root()) + .args(["publish", "--package", "cubeb-core"]) + .status()?; + if !status.success() { + Err("cargo publish failed")?; + } + + let status = Command::new(&cargo) + .current_dir(project_root()) + .args(["publish", "--package", "cubeb-backend"]) + .status()?; + if !status.success() { + Err("cargo publish failed")?; + } + + let status = Command::new(&cargo) + .current_dir(project_root()) + .args(["publish", "--package", "cubeb"]) + .status()?; + if !status.success() { + Err("cargo publish failed")?; + } + + Ok(()) +} + +fn project_root() -> PathBuf { + Path::new(&env!("CARGO_MANIFEST_DIR")) + .ancestors() + .nth(1) + .unwrap() + .to_path_buf() +}