From 37a30d430ef39169122e4db4f0e1bc92115858bc Mon Sep 17 00:00:00 2001 From: KIMJiho Date: Sun, 13 Oct 2024 14:47:13 +0900 Subject: [PATCH 1/2] add long_version opt --- Cargo.lock | 30 +++++++++++++++++++++++++++++- raftify-cli/Cargo.toml | 5 ++++- raftify-cli/build.rs | 13 +++++++++++++ raftify-cli/src/mod.rs | 9 ++++++++- 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5e1ba19d..89f1f10e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -773,6 +773,26 @@ dependencies = [ "tiny-keccak", ] +[[package]] +name = "const_format" +version = "0.2.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50c655d81ff1114fb0dcdea9225ea9f0cc712a6f8d189378e82bdf62a473a64b" +dependencies = [ + "const_format_proc_macros", +] + +[[package]] +name = "const_format_proc_macros" +version = "0.2.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eff1a44b93f47b1bac19a27932f5c591e43d1ba357ee4f61526c8a25603f0eb1" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + [[package]] name = "convert_case" version = "0.4.0" @@ -2306,17 +2326,19 @@ 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", "rocksdb", "serde", "serde_json", "slog", + "toml 0.8.19", "tonic-build", ] @@ -3307,6 +3329,12 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + [[package]] name = "untrusted" version = "0.9.0" diff --git a/raftify-cli/Cargo.toml b/raftify-cli/Cargo.toml index 023127e8..3e58a46f 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"] } @@ -15,6 +16,7 @@ clap = { version = "4.5.18", features = ["derive"] } raftify = { version = "=0.1.81", features = ["heed_storage", "inmemory_storage", "rocksdb_storage"] } rocksdb = "0.19.0" comfy-table = "7.1.1" +cfmt = {version = "0.*", package = "const_format"} [lib] name = "raftify_cli" @@ -23,3 +25,4 @@ path = "src/mod.rs" [build-dependencies] tonic-build = "0.9.2" built = "0.5" +toml = "*" \ No newline at end of file diff --git a/raftify-cli/build.rs b/raftify-cli/build.rs index a5c32511..b99fb397 100644 --- a/raftify-cli/build.rs +++ b/raftify-cli/build.rs @@ -1,4 +1,17 @@ +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(); + println!("cargo:rustc-env=RAFTIFY_VERSION={}", &version[1..]); + } + 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 9666607a..d733d1b6 100644 --- a/raftify-cli/src/mod.rs +++ b/raftify-cli/src/mod.rs @@ -11,9 +11,16 @@ use raftify::{ AbstractLogEntry, AbstractStateMachine, CustomFormatter, Result, StableStorage, }; +use cfmt::formatcp; + +const RAFTIFY_VERSION:&str = env!("RAFTIFY_VERSION"); +const VERSION_TEXT:&'static str = formatcp!("{PKG_VERSION} +raftify {}", RAFTIFY_VERSION); + #[derive(Parser)] -#[command(name = "raftify")] +#[command(name = PKG_NAME)] #[command(version = PKG_VERSION)] +#[command(long_version = VERSION_TEXT)] #[command(author = PKG_AUTHORS)] #[command(about = PKG_DESCRIPTION)] struct App { From c2e12de25a3890ebeb684d74d7b0323543301d85 Mon Sep 17 00:00:00 2001 From: Gyubong Date: Sun, 13 Oct 2024 20:06:34 +0900 Subject: [PATCH 2/2] feat: Print also raftify features --- Cargo.lock | 16 +++++----------- raftify-cli/Cargo.lock | 24 +++++++++++++++++++++++- raftify-cli/Cargo.toml | 4 ++-- raftify-cli/build.rs | 3 +++ raftify-cli/src/mod.rs | 11 ++++++----- 5 files changed, 39 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 89f1f10e..280b7def 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -775,22 +775,22 @@ dependencies = [ [[package]] name = "const_format" -version = "0.2.33" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50c655d81ff1114fb0dcdea9225ea9f0cc712a6f8d189378e82bdf62a473a64b" +checksum = "cbc3a6725e090f416f3c12d12605d90d6be4fde8bd762d236535ab02b388c70d" dependencies = [ "const_format_proc_macros", ] [[package]] name = "const_format_proc_macros" -version = "0.2.33" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eff1a44b93f47b1bac19a27932f5c591e43d1ba357ee4f61526c8a25603f0eb1" +checksum = "e029ee8893eaad89abcb0885453d9555b8cb7982ac456ad044884725215bce42" dependencies = [ "proc-macro2", "quote", - "unicode-xid", + "syn 1.0.109", ] [[package]] @@ -3329,12 +3329,6 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" -[[package]] -name = "unicode-xid" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" - [[package]] name = "untrusted" version = "0.9.0" diff --git a/raftify-cli/Cargo.lock b/raftify-cli/Cargo.lock index a3217964..cb561e84 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,17 +1649,19 @@ dependencies = [ [[package]] name = "raftify_cli" -version = "0.1.81" +version = "0.1.82" dependencies = [ "built", "clap", "comfy-table", + "const_format", "log", "raftify", "rocksdb", "serde", "serde_json", "slog", + "toml 0.8.19", "tonic-build", ] diff --git a/raftify-cli/Cargo.toml b/raftify-cli/Cargo.toml index 3e58a46f..9693c268 100644 --- a/raftify-cli/Cargo.toml +++ b/raftify-cli/Cargo.toml @@ -16,7 +16,7 @@ clap = { version = "4.5.18", features = ["derive"] } raftify = { version = "=0.1.81", features = ["heed_storage", "inmemory_storage", "rocksdb_storage"] } rocksdb = "0.19.0" comfy-table = "7.1.1" -cfmt = {version = "0.*", package = "const_format"} +cfmt = { version = "0.1.0", package = "const_format" } [lib] name = "raftify_cli" @@ -25,4 +25,4 @@ path = "src/mod.rs" [build-dependencies] tonic-build = "0.9.2" built = "0.5" -toml = "*" \ No newline at end of file +toml = "0.8.19" diff --git a/raftify-cli/build.rs b/raftify-cli/build.rs index b99fb397..c449e4b2 100644 --- a/raftify-cli/build.rs +++ b/raftify-cli/build.rs @@ -7,9 +7,12 @@ fn main() -> Result<(), Box> { 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"); diff --git a/raftify-cli/src/mod.rs b/raftify-cli/src/mod.rs index d733d1b6..90654324 100644 --- a/raftify-cli/src/mod.rs +++ b/raftify-cli/src/mod.rs @@ -13,16 +13,17 @@ use raftify::{ use cfmt::formatcp; -const RAFTIFY_VERSION:&str = env!("RAFTIFY_VERSION"); -const VERSION_TEXT:&'static str = formatcp!("{PKG_VERSION} -raftify {}", RAFTIFY_VERSION); +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 = PKG_NAME)] -#[command(version = PKG_VERSION)] -#[command(long_version = VERSION_TEXT)] #[command(author = PKG_AUTHORS)] #[command(about = PKG_DESCRIPTION)] +#[command(version = VERSION_TEXT)] +#[command(long_version = VERSION_TEXT)] struct App { #[command(subcommand)] command: Commands,