diff --git a/Cargo.lock b/Cargo.lock index 2c1a099..6c857f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -773,6 +773,26 @@ dependencies = [ "tiny-keccak", ] +[[package]] +name = "const_format" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbc3a6725e090f416f3c12d12605d90d6be4fde8bd762d236535ab02b388c70d" +dependencies = [ + "const_format_proc_macros", +] + +[[package]] +name = "const_format_proc_macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e029ee8893eaad89abcb0885453d9555b8cb7982ac456ad044884725215bce42" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "convert_case" version = "0.4.0" @@ -2311,16 +2331,18 @@ dependencies = [ [[package]] name = "raftify_cli" -version = "0.1.81" +version = "0.1.82" dependencies = [ "built", "clap 4.5.19", "comfy-table", + "const_format", "log", "raftify", "serde", "serde_json", "slog", + "toml 0.8.19", "tonic-build", ] diff --git a/raftify-cli/Cargo.lock b/raftify-cli/Cargo.lock index e188616..ae8d906 100644 --- a/raftify-cli/Cargo.lock +++ b/raftify-cli/Cargo.lock @@ -459,6 +459,26 @@ dependencies = [ "tiny-keccak", ] +[[package]] +name = "const_format" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbc3a6725e090f416f3c12d12605d90d6be4fde8bd762d236535ab02b388c70d" +dependencies = [ + "const_format_proc_macros", +] + +[[package]] +name = "const_format_proc_macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e029ee8893eaad89abcb0885453d9555b8cb7982ac456ad044884725215bce42" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "convert_case" version = "0.6.0" @@ -1629,16 +1649,18 @@ dependencies = [ [[package]] name = "raftify_cli" -version = "0.1.81" +version = "0.1.82" dependencies = [ "built", "clap", "comfy-table", + "const_format", "log", "raftify", "serde", "serde_json", "slog", + "toml 0.8.19", "tonic-build", ] diff --git a/raftify-cli/Cargo.toml b/raftify-cli/Cargo.toml index a7423ed..0bded57 100644 --- a/raftify-cli/Cargo.toml +++ b/raftify-cli/Cargo.toml @@ -1,9 +1,10 @@ [package] name = "raftify_cli" -version = "0.1.81" +version = "0.1.82" edition = "2021" description = "Raftify CLI tool" license = "MIT/Apache-2.0" +build = "build.rs" [dependencies] log = { version = "0.4", features = ["std"] } @@ -14,6 +15,7 @@ built = "0.5" clap = { version = "4.5.18", features = ["derive"] } raftify = { version = "=0.1.81", features = ["heed_storage", "inmemory_storage", "rocksdb_storage"] } comfy-table = "7.1.1" +cfmt = { version = "0.1.0", package = "const_format" } [lib] name = "raftify_cli" @@ -22,3 +24,4 @@ path = "src/mod.rs" [build-dependencies] tonic-build = "0.9.2" built = "0.5" +toml = "0.8.19" diff --git a/raftify-cli/build.rs b/raftify-cli/build.rs index a5c3251..c449e4b 100644 --- a/raftify-cli/build.rs +++ b/raftify-cli/build.rs @@ -1,4 +1,20 @@ +use std::fs; +use std::path::Path; +use toml::Value; + fn main() -> Result<(), Box> { + let path = Path::new("Cargo.toml"); + let read = fs::read_to_string(path) + .expect("Failed to read Cargo.toml"); + let toml: Value = read.parse::().expect("Failed to parse Cargo.toml"); + + if let Some(raftify_dep) = toml.get("dependencies").and_then(|deps| deps.get("raftify")) { + let version = raftify_dep.get("version").unwrap().as_str().unwrap(); + let features = raftify_dep.get("features").unwrap().as_array().unwrap().iter().map(|f| f.as_str().unwrap()).collect::>().join(", "); + println!("cargo:rustc-env=RAFTIFY_VERSION={}", &version[1..]); + println!("cargo:rustc-env=RAFTIFY_FEATURES={}", features); + } + built::write_built_file().expect("Failed to acquire build-time information"); Ok(()) } diff --git a/raftify-cli/src/mod.rs b/raftify-cli/src/mod.rs index 9666607..9065432 100644 --- a/raftify-cli/src/mod.rs +++ b/raftify-cli/src/mod.rs @@ -11,11 +11,19 @@ use raftify::{ AbstractLogEntry, AbstractStateMachine, CustomFormatter, Result, StableStorage, }; +use cfmt::formatcp; + +const RAFTIFY_VERSION: &str = env!("RAFTIFY_VERSION"); +const RAFTIFY_FEATURES: &str = env!("RAFTIFY_FEATURES"); +const VERSION_TEXT: &'static str = formatcp!("{PKG_VERSION} +(Built with raftify {}, Enabled features: {})", RAFTIFY_VERSION, RAFTIFY_FEATURES); + #[derive(Parser)] -#[command(name = "raftify")] -#[command(version = PKG_VERSION)] +#[command(name = PKG_NAME)] #[command(author = PKG_AUTHORS)] #[command(about = PKG_DESCRIPTION)] +#[command(version = VERSION_TEXT)] +#[command(long_version = VERSION_TEXT)] struct App { #[command(subcommand)] command: Commands,