Skip to content

Issue 4628 - Added metadata versioning for Apache DataSketches #4636

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

Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 7 additions & 0 deletions NOTICES
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,13 @@ testing_logger (https://github.com/brucechapman/rust_testing_logger)

- The 3-Clause BSD License

cargo_metadata (https://github.com/oli-obk/cargo_metadata)

- MIT License

serde_json (https://github.com/serde-rs/json)

- Apache 2 License


The build pipeline uses the following GitHub Actions from the marketplace.
Expand Down
41 changes: 39 additions & 2 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ aws-config = { version = "1.6.1" } # Credential loading
aws-credential-types = { version = "1.2.2" } # Credential provider types
aws-types = { version = "1.3.5" } # for Region
bytes = { version = "1.10.1" } # Byte buffer for S3 uploading
cargo_metadata = { version = "0.19.2" } # Access cargo metadata programmtically
chrono = { version = "0.4.40" } # Log helper
clap = { version = "4.5.35" } # Cmd line args processing
color-eyre = { version = "0.6.3" } # Colourised version of `anyhow`
Expand All @@ -48,6 +49,7 @@ object_store = { version = "0.11.2" } # Remote cloud storage access
openssl = { version = "0.10.72" } # Use vendored feature to build from source for cross compilation
owo-colors = { version = "4.2.0" } # Colourised output
rand = { version = "0.9.0" }
serde_json = { version = "1.0.140" } # Process metadata JSON
tempfile = { version = "3.19.1" } # Create temporary files
test-log = { version = "0.2.17" }
testing_logger = { version = "0.1.1" } # Assert on logger output in tests
Expand All @@ -56,6 +58,9 @@ tokio = { version = "1.44.2", features = ["full"] } # Async runtime
tokio-test = { version = "0.4.4" } # Doc tests
url = { version = "2.5.4" } # URL processing for S3

[workspace.metadata.datasketches]
git_repository_tag = "5.2.0"

[profile.release]
incremental = true
lto = false
Expand Down
2 changes: 2 additions & 0 deletions rust/rust_sketch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ cxx = { workspace = true }
[build-dependencies]
cxx-build = { workspace = true }
git2 = { workspace = true }
cargo_metadata = { workspace = true }
serde_json = { workspace = true }

[target.'cfg(target_os = "macos")'.build-dependencies]
# Mac often won't have openssl library installed in place easy discoverable, if at all
Expand Down
61 changes: 59 additions & 2 deletions rust/rust_sketch/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use cargo_metadata::MetadataCommand;
use serde_json::Value;

pub const DEFAULT_TAG: &str = "5.2.0";

fn main() {
println!("cargo:rerun-if-changed=src/include");
println!("cargo:rerun-if-changed=src/quantiles.rs");
Expand All @@ -26,8 +31,8 @@ fn main() {
let url = std::env::var("RUST_SKETCH_DATASKETCH_URL")
.unwrap_or(String::from("https://github.com/apache/datasketches-cpp"));

// look to see if the repo tag has been overridden
let tag = std::env::var("RUST_SKETCH_DATASKETCH_TAG").unwrap_or(String::from("5.2.0"));
// look up tag to use
let tag = get_repo_tag();

// try to open repository in case it already exists
if git2::Repository::open(path.join("datasketches-cpp")).is_err() {
Expand Down Expand Up @@ -55,3 +60,55 @@ fn main() {
])
.compile("rust_sketch");
}

/// Retrieve git repository tag for Apache `DataSketches` library to retrieve.
///
/// Attempt to determine the git repository tag to retrieve for the Apache `DataSketches`
/// library. Checks in order:
/// 1. `RUST_SKETCH_DATASKETCH_TAG` environment variable.
/// 2. Cargo workspace metadata `workspace.metadata.dataketches` for a `git_repository_tag` key.
/// 3. Default tag in [`DEFAULT_TAG`].
fn get_repo_tag() -> String {
// 1. Check environment variable
if let Ok(env_tag) = std::env::var("RUST_SKETCH_DATASKETCH_TAG") {
println!(
"cargo:warning=DataSketches repository tag taken from environment variable {env_tag}"
);
return env_tag;
}

// 2. Check cargo metadata
let mut command = MetadataCommand::new();
let Ok(metadata) = command.no_deps().exec() else {
println!(
"cargo:warning=Couldn't execute cargo metadata command. Using default {DEFAULT_TAG} tag."
);
return String::from(DEFAULT_TAG);
};

let Value::Object(workspace_data) = metadata.workspace_metadata else {
println!(
"cargo:warning=Couldn't find workspace metadata. Using default {DEFAULT_TAG} tag."
);
return String::from(DEFAULT_TAG);
};

let Some(Value::Object(sketch_data)) = workspace_data.get("datasketches") else {
println!(
"cargo:warning=Couldn't find \"datasketches\" metadata section. Using default {DEFAULT_TAG} tag."
);
return String::from(DEFAULT_TAG);
};

if let Some(Value::String(repo_tag)) = sketch_data.get("git_repository_tag") {
println!(
"cargo:warning=DataSketches repository tag taken from cargo metadata variable {repo_tag}"
);
repo_tag.clone()
} else {
println!(
"cargo:warning=Couldn't find \"git_repository_tag\" metadata key. Using default {DEFAULT_TAG} tag."
);
String::from(DEFAULT_TAG)
}
}
Loading