Skip to content

Commit

Permalink
fix: always evaluate build_profile_name at compile time (#9278)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Jul 3, 2024
1 parent 2f3104b commit f3fd7e7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions crates/node/core/src/metrics/version_metrics.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! This exposes reth's version information over prometheus.
use crate::version::{build_profile_name, VERGEN_GIT_SHA};
use crate::version::{BUILD_PROFILE_NAME, VERGEN_GIT_SHA};
use metrics::gauge;

/// Contains version information for the application.
Expand Down Expand Up @@ -28,7 +28,7 @@ impl Default for VersionInfo {
cargo_features: env!("VERGEN_CARGO_FEATURES"),
git_sha: VERGEN_GIT_SHA,
target_triple: env!("VERGEN_CARGO_TARGET_TRIPLE"),
build_profile: build_profile_name(),
build_profile: BUILD_PROFILE_NAME,
}
}
}
Expand Down
30 changes: 15 additions & 15 deletions crates/node/core/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,23 @@ pub const LONG_VERSION: &str = const_format::concatcp!(
env!("VERGEN_CARGO_FEATURES"),
"\n",
"Build Profile: ",
build_profile_name()
BUILD_PROFILE_NAME
);

pub(crate) const BUILD_PROFILE_NAME: &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");
let unix_parts = const_format::str_split!(OUT_DIR, '/');
if unix_parts.len() >= 4 {
unix_parts[unix_parts.len() - 4]
} else {
let win_parts = const_format::str_split!(OUT_DIR, '\\');
win_parts[win_parts.len() - 4]
}
};

/// The version information for reth formatted for P2P (devp2p).
///
/// - The latest version from Cargo.toml
Expand Down Expand Up @@ -116,20 +130,6 @@ pub fn default_client_version() -> ClientVersion {
}
}

pub(crate) 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");
let unix_parts = const_format::str_split!(OUT_DIR, '/');
if unix_parts.len() >= 4 {
unix_parts[unix_parts.len() - 4]
} else {
let win_parts = const_format::str_split!(OUT_DIR, '\\');
win_parts[win_parts.len() - 4]
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit f3fd7e7

Please sign in to comment.