diff --git a/Cargo.lock b/Cargo.lock index 07b69d63..94d303a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3960,6 +3960,13 @@ dependencies = [ "thiserror", ] +[[package]] +name = "stellar_version" +version = "0.1.0" +dependencies = [ + "cargo_metadata 0.18.1", +] + [[package]] name = "strsim" version = "0.11.1" diff --git a/Cargo.toml b/Cargo.toml index 0cb9879c..dee0760b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] resolver = "2" -members = ["crates/*", "test/*", "examples/soroban/*"] +members = ["crates/*", "test/*", "examples/soroban/*", "stellar_version"] exclude = ["test/*", "examples/soroban/*"] [workspace.package] @@ -18,6 +18,7 @@ soroban-sdk = "22.0.0-rc.3" stellar-xdr = "22.0.0-rc.1.1" stellar-strkey = "0.0.11" +cargo-run-bin = "1.7.3" cargo_metadata = "0.18.1" thiserror = "1.0.38" sha2 = "0.10.7" @@ -31,4 +32,4 @@ strip = "symbols" debug-assertions = true panic = "abort" codegen-units = 1 -lto = true +lto = true \ No newline at end of file diff --git a/justfile b/justfile index e9cf6dd3..8e51b717 100644 --- a/justfile +++ b/justfile @@ -4,6 +4,8 @@ export PATH := './target/bin:' + env_var('PATH') export CONFIG_DIR := 'target/' # hash := `soroban contract install --wasm ./target/wasm32-unknown-unknown/contracts/example_status_message.wasm` +stellar-version := `cargo run --bin stellar_version` + [private] @@ -28,7 +30,7 @@ build: # Setup the project to use a pinned version of the CLI setup: - -cargo binstall -y --install-path ./target/bin stellar-cli --version 22.0.1 + -cargo binstall -y --install-path ./target/bin stellar-cli --version {{stellar-version}} # Build loam-cli test contracts to speed up testing build-cli-test-contracts: @@ -47,4 +49,4 @@ create: build # # Builds contracts. Deploys core subcontract and then redeploys to status message. redeploy: - ./redeploy.sh + ./redeploy.sh \ No newline at end of file diff --git a/stellar_version/Cargo.toml b/stellar_version/Cargo.toml new file mode 100644 index 00000000..ac2ff94c --- /dev/null +++ b/stellar_version/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "stellar_version" +version = "0.1.0" +edition = "2021" + +[dependencies] +cargo_metadata = "0.18.1" diff --git a/stellar_version/src/main.rs b/stellar_version/src/main.rs new file mode 100644 index 00000000..7a6a5eec --- /dev/null +++ b/stellar_version/src/main.rs @@ -0,0 +1,32 @@ +use cargo_metadata::{MetadataCommand, Package}; +use std::process; + +fn main() { + // Run the `cargo metadata` command to get workspace metadata + let metadata = match MetadataCommand::new().exec() { + Ok(metadata) => metadata, + Err(error) => { + eprintln!("Failed to get cargo metadata: {error}"); + process::exit(1); + } + }; + + // Iterate over all packages in the workspace + for package in metadata.packages { + if let Some(version) = find_stellar_cli_version(&package) { + println!("{version}"); + return; + } + } + + eprintln!("stellar-cli dependency not found in any crate."); + process::exit(1); +} + +fn find_stellar_cli_version(package: &Package) -> Option { + package + .dependencies + .iter() + .find(|dep| dep.name == "soroban-cli") + .map(|dep| dep.req.to_string()) +}