Skip to content

Commit 1330fc1

Browse files
add build profile to version info take II (#3669)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
1 parent 42a824c commit 1330fc1

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/reth/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ hex = "0.4"
8585
thiserror = { workspace = true }
8686
pretty_assertions = "1.3.0"
8787
humantime = "2.1.0"
88+
const-str = "0.5.6"
8889

8990
[features]
9091
jemalloc = ["dep:jemallocator", "dep:jemalloc-ctl"]

bin/reth/src/version.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub(crate) const SHORT_VERSION: &str =
2828
/// Build Timestamp: 2023-05-19T01:47:19.815651705Z
2929
/// Build Features: jemalloc
3030
/// ```
31-
pub(crate) const LONG_VERSION: &str = concat!(
31+
pub(crate) const LONG_VERSION: &str = const_str::concat!(
3232
"Version: ",
3333
env!("CARGO_PKG_VERSION"),
3434
"\n",
@@ -39,7 +39,10 @@ pub(crate) const LONG_VERSION: &str = concat!(
3939
env!("VERGEN_BUILD_TIMESTAMP"),
4040
"\n",
4141
"Build Features: ",
42-
env!("VERGEN_CARGO_FEATURES")
42+
env!("VERGEN_CARGO_FEATURES"),
43+
"\n",
44+
"Build Profile: ",
45+
build_profile_name()
4346
);
4447

4548
/// The version information for reth formatted for P2P (devp2p).
@@ -76,6 +79,16 @@ pub fn default_extradata() -> String {
7679
format!("reth/v{}/{}", env!("CARGO_PKG_VERSION"), std::env::consts::OS)
7780
}
7881

82+
const fn build_profile_name() -> &'static str {
83+
// Derived from https://stackoverflow.com/questions/73595435/how-to-get-profile-from-cargo-toml-in-build-rs-or-at-runtime
84+
// We split on the path separator of the *host* machine, which may be different from
85+
// `std::path::MAIN_SEPARATOR_STR`.
86+
const OUT_DIR: &str = env!("OUT_DIR");
87+
const SEP: char = if const_str::contains!(OUT_DIR, "/") { '/' } else { '\\' };
88+
let parts = const_str::split!(OUT_DIR, SEP);
89+
parts[parts.len() - 4]
90+
}
91+
7992
#[cfg(test)]
8093
mod tests {
8194
use super::*;

0 commit comments

Comments
 (0)