Skip to content
This repository has been archived by the owner on Nov 5, 2023. It is now read-only.

Commit

Permalink
add build profile to version info take II (paradigmxyz#3669)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Seitz <[email protected]>
  • Loading branch information
michaelsproul and mattsse authored Jul 8, 2023
1 parent 42a824c commit 1330fc1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions bin/reth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
17 changes: 15 additions & 2 deletions bin/reth/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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).
Expand Down Expand Up @@ -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::*;
Expand Down

0 comments on commit 1330fc1

Please sign in to comment.