diff --git a/Cargo.toml b/Cargo.toml index 64029d8..0d567f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,2 +1,21 @@ [workspace] -members = ["crates/openvino", "crates/openvino-sys", "crates/openvino-finder", "crates/xtask"] +resolver = "2" +members = [ + "crates/openvino", + "crates/openvino-sys", + "crates/openvino-finder", + "crates/xtask", +] + +[workspace.package] +version = "0.6.0" +authors = ["OpenVINO Project Developers"] +edition = "2021" +license = "Apache-2.0" +readme = "README.md" +repository = "https://github.com/intel/openvino-rs" + +[workspace.dependencies] +openvino-sys = { path = "crates/openvino-sys", version = "=0.6.0" } +openvino-finder = { path = "crates/openvino-finder", version = "=0.6.0" } +env_logger = "0.10" diff --git a/crates/openvino-finder/Cargo.toml b/crates/openvino-finder/Cargo.toml index 9446d37..073e4c4 100644 --- a/crates/openvino-finder/Cargo.toml +++ b/crates/openvino-finder/Cargo.toml @@ -1,19 +1,19 @@ [package] name = "openvino-finder" -version = "0.6.0" description = "A helper crate for finding OpenVINO installations on a system." -license = "Apache-2.0" +version.workspace = true +authors.workspace = true +license.workspace = true +edition.workspace = true readme = "README.md" -authors = ["OpenVINO Project Developers"] repository = "https://github.com/intel/openvino-rs" documentation = "https://docs.rs/openvino-finder" keywords = ["openvino", "machine-learning", "ml", "neural-network"] categories = ["development-tools"] -edition = "2018" [dependencies] cfg-if = "1.0" log = "0.4" [dev-dependencies] -env_logger = "0.10" +env_logger = { workspace = true } diff --git a/crates/openvino-sys/Cargo.toml b/crates/openvino-sys/Cargo.toml index e8f20cf..503b869 100644 --- a/crates/openvino-sys/Cargo.toml +++ b/crates/openvino-sys/Cargo.toml @@ -1,15 +1,15 @@ [package] name = "openvino-sys" -version = "0.6.0" -license = "Apache-2.0" description = "Low-level bindings for OpenVINO (use the `openvino` crate for easier-to-use bindings)." -readme = "README.md" -authors = ["OpenVINO Project Developers"] -repository = "https://github.com/intel/openvino-rs" +version.workspace = true +authors.workspace = true +license.workspace = true +edition.workspace = true +readme.workspace = true +repository.workspace = true documentation = "https://docs.rs/openvino-sys" keywords = ["openvino", "machine-learning", "ml", "neural-network"] categories = ["external-ffi-bindings", "science"] -edition = "2018" include = [ "/Cargo.toml", "/README.md", @@ -22,16 +22,16 @@ include = [ # - built from an OpenVINO installation when used as a dependency "/upstream/src/bindings/c/include", ] -links = "inference_engine_c_api" +links = "openvino_c_api" [dependencies] once_cell = { version = "1.18", optional = true } libloading = { version = "0.8", optional = true } -openvino-finder = { version = "0.6.0", path = "../openvino-finder" } +openvino-finder = { workspace = true } [build-dependencies] -openvino-finder = { version = "0.6.0", path = "../openvino-finder" } -env_logger = "0.10" +openvino-finder = { workspace = true } +env_logger = { workspace = true } [features] # Linking features: `build.rs` will default to dynamic linking if none is selected. diff --git a/crates/openvino/Cargo.toml b/crates/openvino/Cargo.toml index f98a8f6..608f196 100644 --- a/crates/openvino/Cargo.toml +++ b/crates/openvino/Cargo.toml @@ -1,20 +1,20 @@ [package] name = "openvino" -version = "0.6.0" -license = "Apache-2.0" description = "High-level bindings for OpenVINO." -readme = "README.md" -authors = ["OpenVINO Project Developers"] -repository = "https://github.com/intel/openvino-rs" +version.workspace = true +authors.workspace = true +license.workspace = true +edition.workspace = true +readme.workspace = true +repository.workspace = true documentation = "https://docs.rs/openvino" keywords = ["openvino", "machine-learning", "ml", "neural-network"] categories = ["api-bindings", "science"] -edition = "2018" exclude = ["/tests"] [dependencies] -openvino-sys = { path = "../openvino-sys", version = "0.6.0" } -openvino-finder = { path = "../openvino-finder", version = "0.6.0" } +openvino-sys = { workspace = true } +openvino-finder = { workspace = true } thiserror = "1.0" [dev-dependencies] diff --git a/crates/xtask/src/bump.rs b/crates/xtask/src/bump.rs index febd94c..f243d3b 100644 --- a/crates/xtask/src/bump.rs +++ b/crates/xtask/src/bump.rs @@ -1,5 +1,5 @@ -use crate::util::{get_crates, Crate}; -use anyhow::{bail, Context, Result}; +use crate::util::{get_crates, get_top_level_cargo_toml, get_top_level_version, Crate}; +use anyhow::{Context, Result}; use clap::Args; use semver::{BuildMetadata, Prerelease}; use std::fs; @@ -26,17 +26,10 @@ impl BumpCommand { let publishable_crates: Vec = get_crates()?.into_iter().filter(|c| c.publish).collect(); - // Check that all of the versions are the same. - if !publishable_crates - .windows(2) - .all(|w| w[0].version == w[1].version) - { - bail!("Not all crate versions are the same: {publishable_crates:?}"); - } - // Change the version. Unless specified with a custom version, the `pre` and `build` // metadata are cleared. - let mut next_version = semver::Version::parse(&publishable_crates[0].version)?; + let current_version = get_top_level_version()?; + let mut next_version = current_version.clone(); next_version.pre = Prerelease::EMPTY; next_version.build = BuildMetadata::EMPTY; match &self.bump { @@ -55,11 +48,17 @@ impl BumpCommand { Bump::Custom(v) => next_version = semver::Version::parse(v)?, } - // Update the Cargo.toml files. - let next_version_str = &next_version.to_string(); - for c in &publishable_crates { - update_version(c, &publishable_crates, next_version_str, self.dry_run)?; - } + // Update the top-level Cargo.toml version. We expect all the crates use the top-level + // workspace version. + assert!(publishable_crates.iter().all(uses_workspace_version)); + let current_version_str = current_version.to_string(); + let next_version_str = next_version.to_string(); + update_version( + &publishable_crates, + ¤t_version_str, + &next_version_str, + self.dry_run, + )?; // Update the Cargo.lock file. if !self.dry_run { @@ -107,17 +106,27 @@ impl std::str::FromStr for Bump { } } -/// Update the version of `krate` and any dependencies in `crates` to match the version passed in -/// `next_version`. Adapted from Wasmtime's [publish.rs] script. +/// Check that a publishable crate pulls its version from the workspace version. +fn uses_workspace_version(krate: &Crate) -> bool { + let contents = fs::read_to_string(&krate.path).unwrap(); + let toml: toml::Value = contents.parse().unwrap(); + let version_workspace = &toml["package"]["version"]["workspace"]; + *version_workspace == toml::Value::Boolean(true) +} + +/// Update the version in the top-level Cargo.toml and any dependencies in its +/// `[workspace.dependencies]` to match the version passed in `next_version`. Adapted from +/// Wasmtime's [publish.rs] script. /// /// [publish.rs]: https://github.com/bytecodealliance/wasmtime/blob/main/scripts/publish.rs fn update_version( - krate: &Crate, crates: &[Crate], + current_version: &str, next_version: &str, dry_run: bool, ) -> Result<()> { - let contents = fs::read_to_string(&krate.path)?; + let top_level_cargo_toml_path = get_top_level_cargo_toml()?; + let contents = fs::read_to_string(&top_level_cargo_toml_path)?; let mut new_contents = String::new(); let mut reading_dependencies = false; for line in contents.lines() { @@ -125,11 +134,13 @@ fn update_version( // Update top-level `version = "..."` line. if !reading_dependencies && line.starts_with("version =") { + let modified_line = line.replace(current_version, next_version); println!( - "> bump `{}` {} => {}", - krate.name, krate.version, next_version + "> bump: {} => {}", + line.trim_start_matches("version =").trim(), + modified_line.trim_start_matches("version =").trim() ); - new_contents.push_str(&line.replace(&krate.version.to_string(), next_version)); + new_contents.push_str(&modified_line); rewritten = true; } @@ -145,21 +156,21 @@ fn update_version( if !reading_dependencies || !line.starts_with(&format!("{} ", other.name)) { continue; } - if !line.contains(&other.version.to_string()) { + if !line.contains(current_version) { if !line.contains("version =") { continue; } panic!( - "{:?} has a dependency on {} but doesn't list version {}", - krate.path, other.name, other.version + "workspace dependency {} doesn't list version {}", + other.name, current_version ); } println!( "> bump dependency `{}` {} => {}", - other.name, other.version, next_version + other.name, current_version, next_version ); rewritten = true; - new_contents.push_str(&line.replace(&other.version, next_version)); + new_contents.push_str(&line.replace(current_version, next_version)); break; } @@ -172,7 +183,7 @@ fn update_version( } if !dry_run { - fs::write(&krate.path, new_contents)?; + fs::write(top_level_cargo_toml_path, new_contents)?; } Ok(()) diff --git a/crates/xtask/src/publish.rs b/crates/xtask/src/publish.rs index abab230..38aa733 100644 --- a/crates/xtask/src/publish.rs +++ b/crates/xtask/src/publish.rs @@ -1,7 +1,7 @@ -use crate::util::{exec, get_crates, path_to_crates, Crate}; -use anyhow::{bail, Result}; +use crate::util::{exec, get_crates, get_top_level_version, path_to_crates, Crate}; +use anyhow::Result; use clap::Args; -use std::{process::Command, thread::sleep, time::Duration}; +use std::process::Command; #[derive(Debug, Args)] pub struct PublishCommand { @@ -16,18 +16,13 @@ pub struct PublishCommand { impl PublishCommand { pub fn execute(&self) -> Result<()> { + // Find the single crate version in the top-level Cargo.toml. + let version = get_top_level_version()?; + // Find the publishable crates. let publishable_crates: Vec = get_crates()?.into_iter().filter(|c| c.publish).collect(); - // Check that all of the versions are the same. - if !publishable_crates - .windows(2) - .all(|w| w[0].version == w[1].version) - { - bail!("Not all crate versions are the same: {publishable_crates:?}"); - } - // Check that all of the publishable crates are in `PUBLICATION_ORDER`. assert_eq!(publishable_crates.len(), PUBLICATION_ORDER.len()); assert!(publishable_crates @@ -52,14 +47,11 @@ impl PublishCommand { if let Err(e) = exec_result { println!("Failed to publish crate {krate}, continuing:\n {e}"); } - - // Hopefully this gives crates.io enough time for subsequent publications to work. - sleep(Duration::from_secs(20)); } } // Tag the repository. - let tag = format!("v{}", publishable_crates[0].version); + let tag = format!("v{}", version); if self.git { println!("> push Git tag: {tag}"); if !self.dry_run { diff --git a/crates/xtask/src/util.rs b/crates/xtask/src/util.rs index 9225cd5..edcc7de 100644 --- a/crates/xtask/src/util.rs +++ b/crates/xtask/src/util.rs @@ -26,6 +26,32 @@ pub fn path_to_crates() -> Result { .into()) } +/// Determine the path to the top-level `Cargo.toml` file. +pub fn get_top_level_cargo_toml() -> Result { + let crates_dir = path_to_crates()?; + let top_level_dir = crates_dir + .parent() + .with_context(|| "Failed to get parent of path.".to_string())?; + let cargo_toml = top_level_dir.join("Cargo.toml"); + assert!(cargo_toml.is_file()); + Ok(cargo_toml) +} + +/// Parse the top-level `Cargo.toml` for the workspace version. +pub fn get_top_level_version() -> Result { + let path = get_top_level_cargo_toml()?; + let contents = fs::read_to_string(&path)?; + let toml: Value = contents + .parse() + .with_context(|| format!("unable to parse TOML of {}", &path.display()))?; + + let version = toml["workspace"]["package"]["version"] + .as_str() + .with_context(|| "No top-level package version in workspace Cargo.toml")? + .to_owned(); + Ok(Version::parse(&version)?) +} + /// Retrieve information about all of the crates found in the `crates` directory. pub fn get_crates() -> Result> { let crates_dir = path_to_crates()?; @@ -38,18 +64,11 @@ pub fn get_crates() -> Result> { let toml: Value = contents .parse() .with_context(|| format!("unable to parse TOML of {}", &path.display()))?; - let name = toml["package"]["name"] .as_str() .with_context(|| "Every Cargo.toml should have a package name")? .to_owned(); - let version = toml["package"]["version"] - .as_str() - .with_context(|| "Every Cargo.toml should have a package name")? - .to_owned(); - Version::parse(&version)?; - let publish = toml["package"] .get("publish") .unwrap_or(&Value::Boolean(true)) @@ -59,7 +78,6 @@ pub fn get_crates() -> Result> { crates.push(Crate { name, path, - version, publish, }); } @@ -72,6 +90,5 @@ pub fn get_crates() -> Result> { pub struct Crate { pub name: String, pub path: PathBuf, - pub version: String, pub publish: bool, }