add build profile to version info (#3652)

This commit is contained in:
Michael Sproul
2023-07-07 19:50:00 +10:00
committed by GitHub
parent b8a5476704
commit db77c279d0
3 changed files with 19 additions and 2 deletions

7
Cargo.lock generated
View File

@@ -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",

View File

@@ -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"]

View File

@@ -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,12 @@ pub fn default_extradata() -> String {
format!("reth/v{}/{}", env!("CARGO_PKG_VERSION"), std::env::consts::OS)
}
const fn build_profile_name() -> &'static str {
// Nice hack from https://stackoverflow.com/questions/73595435/how-to-get-profile-from-cargo-toml-in-build-rs-or-at-runtime
let out_dir_path = const_str::split!(env!("OUT_DIR"), std::path::MAIN_SEPARATOR_STR);
out_dir_path[out_dir_path.len() - 4]
}
#[cfg(test)]
mod tests {
use super::*;