diff --git a/Cargo.lock b/Cargo.lock index 354bd6b818cf..f968525ed50f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1036,6 +1036,12 @@ version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "520fbf3c07483f94e3e3ca9d0cfd913d7718ef2483d2cfd91c0d9e91474ab913" +[[package]] +name = "const-str" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aca749d3d3f5b87a0d6100509879f9cf486ab510803a4a4e1001da1ff61c2bd6" + [[package]] name = "convert_case" version = "0.4.0" @@ -4957,6 +4963,7 @@ dependencies = [ "clap 4.1.8", "comfy-table", "confy", + "const-str", "crossterm", "dirs-next", "eyre", diff --git a/bin/reth/Cargo.toml b/bin/reth/Cargo.toml index 7009807f75b0..1a2fc9591254 100644 --- a/bin/reth/Cargo.toml +++ b/bin/reth/Cargo.toml @@ -85,6 +85,7 @@ hex = "0.4" thiserror = { workspace = true } pretty_assertions = "1.3.0" humantime = "2.1.0" +const-str = "0.5.6" [features] jemalloc = ["dep:jemallocator", "dep:jemalloc-ctl"] diff --git a/bin/reth/src/version.rs b/bin/reth/src/version.rs index a016d209c97f..56933848a586 100644 --- a/bin/reth/src/version.rs +++ b/bin/reth/src/version.rs @@ -28,7 +28,7 @@ pub(crate) const SHORT_VERSION: &str = /// Build Timestamp: 2023-05-19T01:47:19.815651705Z /// Build Features: jemalloc /// ``` -pub(crate) const LONG_VERSION: &str = concat!( +pub(crate) const LONG_VERSION: &str = const_str::concat!( "Version: ", env!("CARGO_PKG_VERSION"), "\n", @@ -39,7 +39,10 @@ pub(crate) const LONG_VERSION: &str = concat!( env!("VERGEN_BUILD_TIMESTAMP"), "\n", "Build Features: ", - env!("VERGEN_CARGO_FEATURES") + env!("VERGEN_CARGO_FEATURES"), + "\n", + "Build Profile: ", + build_profile_name() ); /// The version information for reth formatted for P2P (devp2p). @@ -76,6 +79,16 @@ pub fn default_extradata() -> String { format!("reth/v{}/{}", env!("CARGO_PKG_VERSION"), std::env::consts::OS) } +const fn build_profile_name() -> &'static str { + // Derived from https://stackoverflow.com/questions/73595435/how-to-get-profile-from-cargo-toml-in-build-rs-or-at-runtime + // We split on the path separator of the *host* machine, which may be different from + // `std::path::MAIN_SEPARATOR_STR`. + const OUT_DIR: &str = env!("OUT_DIR"); + const SEP: char = if const_str::contains!(OUT_DIR, "/") { '/' } else { '\\' }; + let parts = const_str::split!(OUT_DIR, SEP); + parts[parts.len() - 4] +} + #[cfg(test)] mod tests { use super::*;