Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: always evaluate build_profile_name at compile time #9278

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading