From 6dab8a00cedd87352e934eaf89997925d36ad8ed Mon Sep 17 00:00:00 2001 From: duvbell Date: Mon, 23 Dec 2024 02:23:12 +0700 Subject: [PATCH 1/7] Remove const_format dependency --- crates/node/core/build.rs | 3 +++ crates/node/core/src/version.rs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/node/core/build.rs b/crates/node/core/build.rs index 1a78793a4746..5255aa1bdef5 100644 --- a/crates/node/core/build.rs +++ b/crates/node/core/build.rs @@ -24,5 +24,8 @@ fn main() -> Result<(), Box> { 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 { "" }); + + // Set short SHA + println!("cargo:rustc-env=VERGEN_GIT_SHA_SHORT={}", &sha[..8]); Ok(()) } diff --git a/crates/node/core/src/version.rs b/crates/node/core/src/version.rs index 406cb89ca9a6..813d1d459970 100644 --- a/crates/node/core/src/version.rs +++ b/crates/node/core/src/version.rs @@ -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"); From 888816c427ed86ae4bde84abd6191b45c71e3015 Mon Sep 17 00:00:00 2001 From: duvbell Date: Tue, 24 Dec 2024 19:21:46 +0700 Subject: [PATCH 2/7] refactor: short version --- crates/node/core/build.rs | 38 +++++++++++++++++++++++++++++++-- crates/node/core/src/version.rs | 31 ++------------------------- 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/crates/node/core/build.rs b/crates/node/core/build.rs index 5255aa1bdef5..8272a35f1f8e 100644 --- a/crates/node/core/build.rs +++ b/crates/node/core/build.rs @@ -22,10 +22,44 @@ fn main() -> Result<(), Box> { // 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 out_dir = env::var("OUT_DIR")?; + let profile = if out_dir.contains('/') { + // Unix-style paths + let parts: Vec<_> = out_dir.split('/').collect(); + if parts.len() >= 4 { + parts[parts.len() - 4] + } else { + // Try Windows-style paths as fallback + let parts: Vec<_> = out_dir.split('\\').collect(); + parts[parts.len() - 4] + } + } else { + // Windows-style paths + let parts: Vec<_> = out_dir.split('\\').collect(); + parts[parts.len() - 4] + }; + 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={}", + format!("{pkg_version}{version_suffix} ({sha_short})") + ); + + panic!("debug"); + Ok(()) } diff --git a/crates/node/core/src/version.rs b/crates/node/core/src/version.rs index 813d1d459970..9a4dab9dd02f 100644 --- a/crates/node/core/src/version.rs +++ b/crates/node/core/src/version.rs @@ -28,22 +28,7 @@ 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. /// @@ -81,19 +66,7 @@ pub const LONG_VERSION: &str = const_format::concatcp!( ); /// 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). /// From f7ff4fb746dfaff3d69dc73890f590f3b56edfc0 Mon Sep 17 00:00:00 2001 From: duvbell Date: Tue, 24 Dec 2024 19:25:03 +0700 Subject: [PATCH 3/7] refactor: long version --- crates/node/core/build.rs | 31 ++++++++++++++++++++++++++++++ crates/node/core/src/version.rs | 34 +-------------------------------- 2 files changed, 32 insertions(+), 33 deletions(-) diff --git a/crates/node/core/build.rs b/crates/node/core/build.rs index 8272a35f1f8e..9bda55b4f8e6 100644 --- a/crates/node/core/build.rs +++ b/crates/node/core/build.rs @@ -59,6 +59,37 @@ fn main() -> Result<(), Box> { format!("{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={}", + format!( + "Version: {pkg_version}{version_suffix}\n\ + Commit SHA: {sha}\n\ + Build Timestamp: {}\n\ + Build Features: {}\n\ + Build Profile: {profile}", + env::var("VERGEN_BUILD_TIMESTAMP")?, + env::var("VERGEN_CARGO_FEATURES")?, + ) + ); + panic!("debug"); Ok(()) diff --git a/crates/node/core/src/version.rs b/crates/node/core/src/version.rs index 9a4dab9dd02f..a8fbff39fdba 100644 --- a/crates/node/core/src/version.rs +++ b/crates/node/core/src/version.rs @@ -31,39 +31,7 @@ pub const VERGEN_CARGO_FEATURES: &str = env!("VERGEN_CARGO_FEATURES"); 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"), - "\n", - "Commit SHA: ", - VERGEN_GIT_SHA_LONG, - "\n", - "Build Timestamp: ", - env!("VERGEN_BUILD_TIMESTAMP"), - "\n", - "Build Features: ", - env!("VERGEN_CARGO_FEATURES"), - "\n", - "Build Profile: ", - BUILD_PROFILE_NAME -); +pub const LONG_VERSION: &str = env!("RETH_LONG_VERSION"); /// The build profile name. pub const BUILD_PROFILE_NAME: &str = env!("RETH_BUILD_PROFILE"); From 8d14d579d84f56b1297c2ad668daf29da8e75536 Mon Sep 17 00:00:00 2001 From: duvbell Date: Tue, 24 Dec 2024 19:26:32 +0700 Subject: [PATCH 4/7] refactor: p2p client version --- crates/node/core/build.rs | 10 +++++++++- crates/node/core/src/version.rs | 9 +-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/crates/node/core/build.rs b/crates/node/core/build.rs index 9bda55b4f8e6..115965c25fdf 100644 --- a/crates/node/core/build.rs +++ b/crates/node/core/build.rs @@ -90,7 +90,15 @@ fn main() -> Result<(), Box> { ) ); - panic!("debug"); + // 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!("reth/v{pkg_version}-{sha_short}/{}", env::var("VERGEN_CARGO_TARGET_TRIPLE")?) + ); Ok(()) } diff --git a/crates/node/core/src/version.rs b/crates/node/core/src/version.rs index a8fbff39fdba..87ee1a8ee6f0 100644 --- a/crates/node/core/src/version.rs +++ b/crates/node/core/src/version.rs @@ -47,14 +47,7 @@ pub const BUILD_PROFILE_NAME: &str = env!("RETH_BUILD_PROFILE"); /// 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. /// From 12f8b2f3987a37385002af4ecb044b70fa9611ee Mon Sep 17 00:00:00 2001 From: duvbell Date: Tue, 24 Dec 2024 20:14:07 +0700 Subject: [PATCH 5/7] perf: simplify build profile name --- Cargo.lock | 37 ------------------------------------- Cargo.toml | 1 - crates/node/core/Cargo.toml | 1 - crates/node/core/build.rs | 17 +---------------- 4 files changed, 1 insertion(+), 55 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 968f8bf40aa1..89b27ce645ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2019,27 +2019,6 @@ version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" -[[package]] -name = "const_format" -version = "0.2.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "126f97965c8ad46d6d9163268ff28432e8f6a1196a55578867832e3049df63dd" -dependencies = [ - "const_format_proc_macros", - "konst", -] - -[[package]] -name = "const_format_proc_macros" -version = "0.2.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d57c2eccfb16dbac1f4e61e206105db5820c9d26c3c472bc17c774259ef7744" -dependencies = [ - "proc-macro2", - "quote", - "unicode-xid", -] - [[package]] name = "convert_case" version = "0.6.0" @@ -4659,21 +4638,6 @@ dependencies = [ "sha3-asm", ] -[[package]] -name = "konst" -version = "0.2.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "330f0e13e6483b8c34885f7e6c9f19b1a7bd449c673fbb948a51c99d66ef74f4" -dependencies = [ - "konst_macro_rules", -] - -[[package]] -name = "konst_macro_rules" -version = "0.2.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4933f3f57a8e9d9da04db23fb153356ecaf00cbd14aee46279c33dc80925c37" - [[package]] name = "kqueue" version = "1.0.8" @@ -8220,7 +8184,6 @@ dependencies = [ "alloy-primitives", "alloy-rpc-types-engine", "clap", - "const_format", "derive_more", "dirs-next", "eyre", diff --git a/Cargo.toml b/Cargo.toml index 7853c0da88e4..78867ec7dade 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/crates/node/core/Cargo.toml b/crates/node/core/Cargo.toml index 0ede9fe80c4d..96919b7de7e0 100644 --- a/crates/node/core/Cargo.toml +++ b/crates/node/core/Cargo.toml @@ -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 diff --git a/crates/node/core/build.rs b/crates/node/core/build.rs index 115965c25fdf..5ec5464c9146 100644 --- a/crates/node/core/build.rs +++ b/crates/node/core/build.rs @@ -29,22 +29,7 @@ fn main() -> Result<(), Box> { println!("cargo:rustc-env=VERGEN_GIT_SHA_SHORT={}", &sha[..8]); // Set the build profile - let out_dir = env::var("OUT_DIR")?; - let profile = if out_dir.contains('/') { - // Unix-style paths - let parts: Vec<_> = out_dir.split('/').collect(); - if parts.len() >= 4 { - parts[parts.len() - 4] - } else { - // Try Windows-style paths as fallback - let parts: Vec<_> = out_dir.split('\\').collect(); - parts[parts.len() - 4] - } - } else { - // Windows-style paths - let parts: Vec<_> = out_dir.split('\\').collect(); - parts[parts.len() - 4] - }; + let profile = env::var("PROFILE")?; println!("cargo:rustc-env=RETH_BUILD_PROFILE={profile}"); // Set formatted version strings From ddb8d3ef426c2fbd9276427e99349d5ce5530d9c Mon Sep 17 00:00:00 2001 From: duvbell Date: Tue, 24 Dec 2024 20:27:51 +0700 Subject: [PATCH 6/7] fix: multiple line for long version --- crates/node/core/build.rs | 19 +++++++++---------- crates/node/core/src/version.rs | 12 +++++++++++- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/crates/node/core/build.rs b/crates/node/core/build.rs index 5ec5464c9146..f9487a14f19b 100644 --- a/crates/node/core/build.rs +++ b/crates/node/core/build.rs @@ -62,18 +62,17 @@ fn main() -> Result<(), Box> { // 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={}", - format!( - "Version: {pkg_version}{version_suffix}\n\ - Commit SHA: {sha}\n\ - Build Timestamp: {}\n\ - Build Features: {}\n\ - Build Profile: {profile}", - env::var("VERGEN_BUILD_TIMESTAMP")?, - env::var("VERGEN_CARGO_FEATURES")?, - ) + "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 diff --git a/crates/node/core/src/version.rs b/crates/node/core/src/version.rs index 87ee1a8ee6f0..a526301a2249 100644 --- a/crates/node/core/src/version.rs +++ b/crates/node/core/src/version.rs @@ -31,7 +31,17 @@ pub const VERGEN_CARGO_FEATURES: &str = env!("VERGEN_CARGO_FEATURES"); pub const SHORT_VERSION: &str = env!("RETH_SHORT_VERSION"); /// The long version information for reth. -pub const LONG_VERSION: &str = env!("RETH_LONG_VERSION"); +pub const LONG_VERSION: &str = concat!( + env!("RETH_LONG_VERSION_0"), + "\n", + env!("RETH_LONG_VERSION_1"), + "\n", + env!("RETH_LONG_VERSION_2"), + "\n", + env!("RETH_LONG_VERSION_3"), + "\n", + env!("RETH_LONG_VERSION_4") +); /// The build profile name. pub const BUILD_PROFILE_NAME: &str = env!("RETH_BUILD_PROFILE"); From 89f9eb093c2c8f7f73786dddfc7e7cbd33a6fae3 Mon Sep 17 00:00:00 2001 From: duvbell Date: Wed, 25 Dec 2024 00:10:39 +0700 Subject: [PATCH 7/7] fix lint --- crates/node/core/build.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/crates/node/core/build.rs b/crates/node/core/build.rs index f9487a14f19b..2a4c2705ed46 100644 --- a/crates/node/core/build.rs +++ b/crates/node/core/build.rs @@ -39,10 +39,7 @@ fn main() -> Result<(), Box> { // - 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={}", - format!("{pkg_version}{version_suffix} ({sha_short})") - ); + println!("cargo:rustc-env=RETH_SHORT_VERSION={pkg_version}{version_suffix} ({sha_short})"); // LONG_VERSION // The long version information for reth. @@ -81,7 +78,7 @@ fn main() -> Result<(), Box> { // Example: reth/v0.1.0-alpha.1-428a6dc2f/aarch64-apple-darwin println!( "cargo:rustc-env=RETH_P2P_CLIENT_VERSION={}", - format!("reth/v{pkg_version}-{sha_short}/{}", env::var("VERGEN_CARGO_TARGET_TRIPLE")?) + format_args!("reth/v{pkg_version}-{sha_short}/{}", env::var("VERGEN_CARGO_TARGET_TRIPLE")?) ); Ok(())