Skip to content
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
21 changes: 20 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
10 changes: 5 additions & 5 deletions crates/openvino-finder/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 }
20 changes: 10 additions & 10 deletions crates/openvino-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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.
Expand Down
16 changes: 8 additions & 8 deletions crates/openvino/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
69 changes: 40 additions & 29 deletions crates/xtask/src/bump.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -26,17 +26,10 @@ impl BumpCommand {
let publishable_crates: Vec<Crate> =
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 {
Expand All @@ -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,
&current_version_str,
&next_version_str,
self.dry_run,
)?;

// Update the Cargo.lock file.
if !self.dry_run {
Expand Down Expand Up @@ -107,29 +106,41 @@ 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() {
let mut rewritten = false;

// 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;
}

Expand All @@ -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;
}

Expand All @@ -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(())
Expand Down
22 changes: 7 additions & 15 deletions crates/xtask/src/publish.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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<Crate> =
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
Expand All @@ -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 {
Expand Down
35 changes: 26 additions & 9 deletions crates/xtask/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,32 @@ pub fn path_to_crates() -> Result<PathBuf> {
.into())
}

/// Determine the path to the top-level `Cargo.toml` file.
pub fn get_top_level_cargo_toml() -> Result<PathBuf> {
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<Version> {
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<Vec<Crate>> {
let crates_dir = path_to_crates()?;
Expand All @@ -38,18 +64,11 @@ pub fn get_crates() -> Result<Vec<Crate>> {
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))
Expand All @@ -59,7 +78,6 @@ pub fn get_crates() -> Result<Vec<Crate>> {
crates.push(Crate {
name,
path,
version,
publish,
});
}
Expand All @@ -72,6 +90,5 @@ pub fn get_crates() -> Result<Vec<Crate>> {
pub struct Crate {
pub name: String,
pub path: PathBuf,
pub version: String,
pub publish: bool,
}