Skip to content

Commit 1a684e9

Browse files
authored
fix: trin cli flag displays wrong version info (#1615)
1 parent b1de71d commit 1a684e9

File tree

6 files changed

+96
-139
lines changed

6 files changed

+96
-139
lines changed

Cargo.lock

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

ethportal-api/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
name = "ethportal-api"
33
version = "0.4.0"
44
description = "Definitions for various Ethereum Portal Network JSONRPC APIs"
5-
build = "build.rs"
65
authors.workspace = true
76
categories.workspace = true
87
edition.workspace = true
@@ -45,7 +44,6 @@ serde-this-or-that.workspace = true
4544
serde_json.workspace = true
4645
sha2 = "0.10.1"
4746
sha3.workspace = true
48-
shadow-rs = "0.27"
4947
ssz_types.workspace = true
5048
superstruct = "0.7.0"
5149
thiserror.workspace = true
@@ -67,4 +65,4 @@ tracing.workspace = true
6765
tracing-subscriber.workspace = true
6866

6967
[build-dependencies]
70-
shadow-rs = "0.27"
68+
vergen = { version = "8.0.0", features = ["build", "cargo", "git", "gitcl", "rustc"] }

ethportal-api/build.rs

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,15 @@
1-
use std::{fs::File, io::Write};
2-
3-
use shadow_rs::SdResult;
4-
5-
fn main() -> SdResult<()> {
6-
shadow_rs::new_hook(hook)?;
7-
8-
Ok(())
9-
}
10-
11-
fn hook(mut file: &File) -> SdResult<()> {
12-
let env_var_git_hash = std::env::var("GIT_HASH").unwrap_or_default();
13-
writeln!(file, "const ENV_GIT_HASH: &str = \"{}\";", env_var_git_hash)?;
14-
15-
hook_method(file)?;
16-
17-
Ok(())
18-
}
19-
20-
fn hook_method(mut file: &File) -> SdResult<()> {
21-
let hook_fn = r#"
22-
pub const fn short_commit() -> &'static str {
23-
if shadow_rs::str_get!(SHORT_COMMIT, 0).is_some() {
24-
return SHORT_COMMIT;
25-
}
26-
27-
if shadow_rs::str_get!(ENV_GIT_HASH, 0).is_some() {
28-
ENV_GIT_HASH
29-
} else {
30-
"unknown"
31-
}
32-
}"#;
33-
34-
writeln!(file, "{}", hook_fn)?;
1+
use std::error::Error;
2+
3+
use vergen::EmitBuilder;
4+
5+
fn main() -> Result<(), Box<dyn Error>> {
6+
EmitBuilder::builder()
7+
.git_sha(true)
8+
.git_describe(false, true, None)
9+
.build_timestamp()
10+
.rustc_semver()
11+
.cargo_features()
12+
.cargo_target_triple()
13+
.emit()?;
3514
Ok(())
3615
}

ethportal-api/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,3 @@ pub use types::{
4848
portal::{RawContentKey, RawContentValue},
4949
};
5050
pub use web3::{Web3ApiClient, Web3ApiServer};
51-
52-
shadow_rs::shadow!(build_info);

ethportal-api/src/types/cli.rs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use clap::{
1010
use url::Url;
1111

1212
use crate::{
13-
build_info,
1413
types::{bootnodes::Bootnodes, network::Subnetwork},
14+
version::FULL_VERSION,
1515
};
1616

1717
pub const DEFAULT_WEB3_IPC_PATH: &str = "/tmp/trin-jsonrpc.ipc";
@@ -56,22 +56,6 @@ impl FromStr for Web3TransportType {
5656
}
5757

5858
const APP_NAME: &str = "trin";
59-
const VERSION: &str = const_format::formatcp!(
60-
"{version}-{hash} {build_os} {rust_version}",
61-
// Remove -alpha.1 versioning if it is present.
62-
// This must be done as it can conflict with eth versioning
63-
version = const_format::str_split!(build_info::PKG_VERSION, '-')[0],
64-
hash = build_info::short_commit(),
65-
build_os = build_info::BUILD_OS,
66-
// the rust version looks like that:
67-
// rustc 1.77.0 (aedd173a2 2024-03-17)
68-
// we remove everything in the brackets and replace spaces with nothing
69-
rust_version = const_format::str_replace!(
70-
const_format::str_split!(build_info::RUST_VERSION, '(')[0],
71-
' ',
72-
""
73-
)
74-
);
7559

7660
/// The storage capacity configurtion.
7761
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -91,7 +75,8 @@ pub enum StorageCapacityConfig {
9175
#[command(name = APP_NAME,
9276
author = "https://github.com/ethereum/trin/graphs/contributors",
9377
about = "Run an eth portal client",
94-
version = VERSION)]
78+
version = FULL_VERSION
79+
)]
9580
pub struct TrinConfig {
9681
#[arg(
9782
default_value = DEFAULT_WEB3_TRANSPORT,

ethportal-api/src/version.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,31 @@
1+
/// The latest git commit hash of the build.
2+
pub const TRIN_FULL_COMMIT: &str = env!("VERGEN_GIT_SHA");
3+
pub const TRIN_SHORT_COMMIT: &str = const_format::str_index!(TRIN_FULL_COMMIT, ..8);
4+
5+
/// Trin's version is the same as the git tag.
6+
pub const TRIN_VERSION: &str = const_format::str_split!(env!("VERGEN_GIT_DESCRIBE"), '-')[0];
7+
8+
/// The operating system of the build, linux, macos, windows etc.
9+
pub const BUILD_OPERATING_SYSTEM: &str =
10+
const_format::str_split!(env!("VERGEN_CARGO_TARGET_TRIPLE"), "-")[2];
11+
12+
/// The architecture of the build, x86_64, aarch64, etc.
13+
pub const BUILD_ARCHITECTURE: &str =
14+
const_format::str_split!(env!("VERGEN_CARGO_TARGET_TRIPLE"), "-")[0];
15+
16+
// /// The version of the programming language used to build the binary.
17+
pub const PROGRAMMING_LANGUAGE_VERSION: &str = env!("VERGEN_RUSTC_SEMVER");
18+
19+
pub const FULL_VERSION: &str = const_format::formatcp!(
20+
"{version}-{hash} {build_os}-{build_arch} rustc{rust_version}",
21+
version = TRIN_VERSION,
22+
hash = TRIN_SHORT_COMMIT,
23+
build_os = BUILD_OPERATING_SYSTEM,
24+
build_arch = BUILD_ARCHITECTURE,
25+
rust_version = PROGRAMMING_LANGUAGE_VERSION
26+
);
27+
128
/// Returns the trin version and git revision.
229
pub const fn get_trin_version() -> &'static str {
3-
crate::build_info::short_commit()
30+
TRIN_SHORT_COMMIT
431
}

0 commit comments

Comments
 (0)