Skip to content

Commit

Permalink
chore(version) Remove const_format dependency (#13504)
Browse files Browse the repository at this point in the history
  • Loading branch information
duvbell authored Dec 25, 2024
1 parent 031f430 commit 951e2fd
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 107 deletions.
37 changes: 0 additions & 37 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,6 @@ boyer-moore-magiclen = "0.2.16"
bytes = { version = "1.5", default-features = false }
cfg-if = "1.0"
clap = "4"
const_format = { version = "0.2.32", features = ["rust_1_64"] }
dashmap = "6.0"
derive_more = { version = "1", default-features = false, features = ["full"] }
dyn-clone = "1.0.17"
Expand Down
1 change: 0 additions & 1 deletion crates/node/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ alloy-eips.workspace = true
eyre.workspace = true
clap = { workspace = true, features = ["derive"] }
humantime.workspace = true
const_format.workspace = true
rand.workspace = true
derive_more.workspace = true
toml.workspace = true
Expand Down
61 changes: 59 additions & 2 deletions crates/node/core/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,64 @@ fn main() -> Result<(), Box<dyn Error>> {
// if not on a tag: v0.2.0-beta.3-82-g1939939b
// if on a tag: v0.2.0-beta.3
let not_on_tag = env::var("VERGEN_GIT_DESCRIBE")?.ends_with(&format!("-g{sha_short}"));
let is_dev = is_dirty || not_on_tag;
println!("cargo:rustc-env=RETH_VERSION_SUFFIX={}", if is_dev { "-dev" } else { "" });
let version_suffix = if is_dirty || not_on_tag { "-dev" } else { "" };
println!("cargo:rustc-env=RETH_VERSION_SUFFIX={}", version_suffix);

// Set short SHA
println!("cargo:rustc-env=VERGEN_GIT_SHA_SHORT={}", &sha[..8]);

// Set the build profile
let profile = env::var("PROFILE")?;
println!("cargo:rustc-env=RETH_BUILD_PROFILE={profile}");

// Set formatted version strings
let pkg_version = env!("CARGO_PKG_VERSION");

// The short version information for reth.
// - The latest version from Cargo.toml
// - The short SHA of the latest commit.
// Example: 0.1.0 (defa64b2)
println!("cargo:rustc-env=RETH_SHORT_VERSION={pkg_version}{version_suffix} ({sha_short})");

// LONG_VERSION
// The long version information for reth.
//
// - The latest version from Cargo.toml + version suffix (if any)
// - The full SHA of the latest commit
// - The build datetime
// - The build features
// - The build profile
//
// Example:
//
// ```text
// Version: 0.1.0
// Commit SHA: defa64b2
// Build Timestamp: 2023-05-19T01:47:19.815651705Z
// Build Features: jemalloc
// Build Profile: maxperf
// ```
println!("cargo:rustc-env=RETH_LONG_VERSION_0=Version: {pkg_version}{version_suffix}");
println!("cargo:rustc-env=RETH_LONG_VERSION_1=Commit SHA: {sha}");
println!(
"cargo:rustc-env=RETH_LONG_VERSION_2=Build Timestamp: {}",
env::var("VERGEN_BUILD_TIMESTAMP")?
);
println!(
"cargo:rustc-env=RETH_LONG_VERSION_3=Build Features: {}",
env::var("VERGEN_CARGO_FEATURES")?
);
println!("cargo:rustc-env=RETH_LONG_VERSION_4=Build Profile: {profile}");

// The version information for reth formatted for P2P (devp2p).
// - The latest version from Cargo.toml
// - The target triple
//
// Example: reth/v0.1.0-alpha.1-428a6dc2f/aarch64-apple-darwin
println!(
"cargo:rustc-env=RETH_P2P_CLIENT_VERSION={}",
format_args!("reth/v{pkg_version}-{sha_short}/{}", env::var("VERGEN_CARGO_TARGET_TRIPLE")?)
);

Ok(())
}
76 changes: 10 additions & 66 deletions crates/node/core/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
pub const VERGEN_GIT_SHA_LONG: &str = env!("VERGEN_GIT_SHA");

/// The 8 character short SHA of the latest commit.
pub const VERGEN_GIT_SHA: &str = const_format::str_index!(VERGEN_GIT_SHA_LONG, ..8);
pub const VERGEN_GIT_SHA: &str = env!("VERGEN_GIT_SHA_SHORT");

/// The build timestamp.
pub const VERGEN_BUILD_TIMESTAMP: &str = env!("VERGEN_BUILD_TIMESTAMP");
Expand All @@ -28,72 +28,23 @@ pub const VERGEN_CARGO_TARGET_TRIPLE: &str = env!("VERGEN_CARGO_TARGET_TRIPLE");
pub const VERGEN_CARGO_FEATURES: &str = env!("VERGEN_CARGO_FEATURES");

/// The short version information for reth.
///
/// - The latest version from Cargo.toml
/// - The short SHA of the latest commit.
///
/// # Example
///
/// ```text
/// 0.1.0 (defa64b2)
/// ```
pub const SHORT_VERSION: &str = const_format::concatcp!(
env!("CARGO_PKG_VERSION"),
env!("RETH_VERSION_SUFFIX"),
" (",
VERGEN_GIT_SHA,
")"
);
pub const SHORT_VERSION: &str = env!("RETH_SHORT_VERSION");

/// The long version information for reth.
///
/// - The latest version from Cargo.toml
/// - The long SHA of the latest commit.
/// - The build datetime
/// - The build features
/// - The build profile
///
/// # Example:
///
/// ```text
/// Version: 0.1.0
/// Commit SHA: defa64b2
/// Build Timestamp: 2023-05-19T01:47:19.815651705Z
/// Build Features: jemalloc
/// Build Profile: maxperf
/// ```
pub const LONG_VERSION: &str = const_format::concatcp!(
"Version: ",
env!("CARGO_PKG_VERSION"),
env!("RETH_VERSION_SUFFIX"),
pub const LONG_VERSION: &str = concat!(
env!("RETH_LONG_VERSION_0"),
"\n",
"Commit SHA: ",
VERGEN_GIT_SHA_LONG,
env!("RETH_LONG_VERSION_1"),
"\n",
"Build Timestamp: ",
env!("VERGEN_BUILD_TIMESTAMP"),
env!("RETH_LONG_VERSION_2"),
"\n",
"Build Features: ",
env!("VERGEN_CARGO_FEATURES"),
env!("RETH_LONG_VERSION_3"),
"\n",
"Build Profile: ",
BUILD_PROFILE_NAME
env!("RETH_LONG_VERSION_4")
);

/// The build profile name.
pub 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]
}
};
pub const BUILD_PROFILE_NAME: &str = env!("RETH_BUILD_PROFILE");

/// The version information for reth formatted for P2P (devp2p).
///
Expand All @@ -106,14 +57,7 @@ pub const BUILD_PROFILE_NAME: &str = {
/// reth/v{major}.{minor}.{patch}-{sha1}/{target}
/// ```
/// e.g.: `reth/v0.1.0-alpha.1-428a6dc2f/aarch64-apple-darwin`
pub(crate) const P2P_CLIENT_VERSION: &str = const_format::concatcp!(
"reth/v",
env!("CARGO_PKG_VERSION"),
"-",
VERGEN_GIT_SHA,
"/",
env!("VERGEN_CARGO_TARGET_TRIPLE")
);
pub(crate) const P2P_CLIENT_VERSION: &str = env!("RETH_P2P_CLIENT_VERSION");

/// The default extra data used for payload building.
///
Expand Down

0 comments on commit 951e2fd

Please sign in to comment.