diff --git a/Cargo.lock b/Cargo.lock index 225bf6d232..9d272299cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8141,6 +8141,7 @@ name = "katana-node" version = "1.0.0-alpha.19" dependencies = [ "anyhow", + "const_format", "dojo-metrics", "futures", "hyper 0.14.30", @@ -8161,6 +8162,8 @@ dependencies = [ "tower 0.4.13", "tower-http 0.4.4", "tracing", + "vergen", + "vergen-gitcl", ] [[package]] @@ -9760,6 +9763,15 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "ntapi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4" +dependencies = [ + "winapi", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -14230,6 +14242,20 @@ dependencies = [ "syn 2.0.77", ] +[[package]] +name = "sysinfo" +version = "0.31.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "355dbe4f8799b304b05e1b0f05fc59b2a18d36645cf169607da45bde2f69a1be" +dependencies = [ + "core-foundation-sys", + "libc", + "memchr", + "ntapi", + "rayon", + "windows 0.57.0", +] + [[package]] name = "system-configuration" version = "0.5.1" @@ -15618,6 +15644,48 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +[[package]] +name = "vergen" +version = "9.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349ed9e45296a581f455bc18039878f409992999bc1d5da12a6800eb18c8752f" +dependencies = [ + "anyhow", + "cargo_metadata", + "derive_builder", + "regex", + "rustc_version 0.4.1", + "rustversion", + "sysinfo", + "time", + "vergen-lib", +] + +[[package]] +name = "vergen-gitcl" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a3a7f91caabecefc3c249fd864b11d4abe315c166fbdb568964421bccfd2b7a" +dependencies = [ + "anyhow", + "derive_builder", + "rustversion", + "time", + "vergen", + "vergen-lib", +] + +[[package]] +name = "vergen-lib" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "229eaddb0050920816cf051e619affaf18caa3dd512de8de5839ccbc8e53abb0" +dependencies = [ + "anyhow", + "derive_builder", + "rustversion", +] + [[package]] name = "verify_db_balances" version = "1.0.0-alpha.19" diff --git a/bin/katana/src/cli/mod.rs b/bin/katana/src/cli/mod.rs index 59dc1df351..90041a21a0 100644 --- a/bin/katana/src/cli/mod.rs +++ b/bin/katana/src/cli/mod.rs @@ -4,9 +4,10 @@ mod node; use anyhow::Result; use clap::{Args, CommandFactory, Parser, Subcommand}; use clap_complete::Shell; +use katana_node::version::VERSION; #[derive(Parser)] -#[command(name = "katana", author, version, about, long_about = None)] +#[command(name = "katana", author, version = VERSION, about, long_about = None)] pub struct Cli { #[command(subcommand)] commands: Option, diff --git a/crates/katana/node/Cargo.toml b/crates/katana/node/Cargo.toml index 829ff305fe..fd55d0f9c7 100644 --- a/crates/katana/node/Cargo.toml +++ b/crates/katana/node/Cargo.toml @@ -29,6 +29,11 @@ tracing.workspace = true strum.workspace = true strum_macros.workspace = true +const_format = "0.2.33" + +[build-dependencies] +vergen = { version = "9.0.0", features = [ "build", "cargo", "emit_and_set" ] } +vergen-gitcl = { version = "1.0.0", features = [ "build", "cargo", "rustc", "si" ] } [features] starknet-messaging = [ "katana-core/starknet-messaging" ] diff --git a/crates/katana/node/build.rs b/crates/katana/node/build.rs new file mode 100644 index 0000000000..01afc6698e --- /dev/null +++ b/crates/katana/node/build.rs @@ -0,0 +1,26 @@ +use std::env; +use std::error::Error; + +use vergen::{BuildBuilder, Emitter}; +use vergen_gitcl::GitclBuilder; + +fn main() -> Result<(), Box> { + let build = BuildBuilder::default().build_timestamp(true).build()?; + let gitcl = + GitclBuilder::default().describe(true, false, None).dirty(true).sha(true).build()?; + + // Emit the instructions + Emitter::default().add_instructions(&build)?.add_instructions(&gitcl)?.emit_and_set()?; + + let sha = env::var("VERGEN_GIT_SHA")?; + let is_dirty = env::var("VERGEN_GIT_DIRTY")? == "true"; + + // > git describe --always --tags + // if not on a tag: v0.2.0-beta.3-82-g1939939b + // if on a tag: v0.2.0-beta.3 + let not_on_tag = env::var("VERGEN_GIT_DESCRIBE")?.ends_with(&format!("-g{sha}")); + let is_dev = is_dirty || not_on_tag; + println!("cargo:rustc-env=DEV_BUILD_SUFFIX={}", if is_dev { "-dev" } else { "" }); + + Ok(()) +} diff --git a/crates/katana/node/src/lib.rs b/crates/katana/node/src/lib.rs index 69893957b7..9e26ecb01d 100644 --- a/crates/katana/node/src/lib.rs +++ b/crates/katana/node/src/lib.rs @@ -2,6 +2,7 @@ pub mod config; pub mod exit; +pub mod version; use std::future::IntoFuture; use std::net::SocketAddr; diff --git a/crates/katana/node/src/version.rs b/crates/katana/node/src/version.rs new file mode 100644 index 0000000000..9905386731 --- /dev/null +++ b/crates/katana/node/src/version.rs @@ -0,0 +1,15 @@ +/// The latest version from Cargo.toml. +pub const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION"); + +/// The SHA of the latest commit. +pub const VERGEN_GIT_SHA: &str = env!("VERGEN_GIT_SHA"); + +// > 1.0.0-alpha.19 (77d4800) +// > if on dev (ie dirty): 1.0.0-alpha.19-dev (77d4800) +pub const VERSION: &str = const_format::concatcp!( + env!("CARGO_PKG_VERSION"), + env!("DEV_BUILD_SUFFIX"), + " (", + VERGEN_GIT_SHA, + ")" +);