From 675f7e66ee4be701e9237f4409d2ecff97209f1c Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Fri, 13 Sep 2024 10:59:46 +1000 Subject: [PATCH 1/2] Include compiler version in `lighthouse --version` --- Cargo.toml | 1 + lighthouse/Cargo.toml | 1 + lighthouse/src/main.rs | 25 +++++++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 125231ad20e..d8c6f487cfa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -152,6 +152,7 @@ reqwest = { version = "0.11", default-features = false, features = ["blocking", ring = "0.16" rpds = "0.11" rusqlite = { version = "0.28", features = ["bundled"] } +rustc_version = "0.4.1" serde = { version = "1", features = ["derive"] } serde_json = "1" serde_repr = "0.1" diff --git a/lighthouse/Cargo.toml b/lighthouse/Cargo.toml index 7c37aa6d67d..c6b7ea50cbc 100644 --- a/lighthouse/Cargo.toml +++ b/lighthouse/Cargo.toml @@ -61,6 +61,7 @@ database_manager = { path = "../database_manager" } slasher = { workspace = true } validator_manager = { path = "../validator_manager" } logging = { workspace = true } +rustc_version = { workspace = true } [dev-dependencies] tempfile = { workspace = true } diff --git a/lighthouse/src/main.rs b/lighthouse/src/main.rs index e865fbd272e..cf8dc2321b2 100644 --- a/lighthouse/src/main.rs +++ b/lighthouse/src/main.rs @@ -35,6 +35,7 @@ pub static LONG_VERSION: LazyLock = LazyLock::new(|| { SHA256 hardware acceleration: {}\n\ Allocator: {}\n\ Profile: {}\n\ + Compiler: {}\n\ Specs: mainnet (true), minimal ({}), gnosis ({})", SHORT_VERSION.as_str(), bls_library_name(), @@ -42,6 +43,7 @@ pub static LONG_VERSION: LazyLock = LazyLock::new(|| { have_sha_extensions(), allocator_name(), build_profile_name(), + compiler_version(), cfg!(feature = "spec-minimal"), cfg!(feature = "gnosis"), ) @@ -85,6 +87,29 @@ fn build_profile_name() -> String { .to_string() } +fn compiler_version() -> String { + let version = rustc_version::version_meta().expect("should be able to fetch compiler version"); + let commit_hash_chars = 7; + format!( + "Rust v{} {} ({})", + version.semver, + compiler_channel(&version.channel), + version + .commit_hash + .map_or("??".to_string(), |hash| hash[..commit_hash_chars] + .to_string()), + ) +} + +fn compiler_channel(channel: &rustc_version::Channel) -> &'static str { + match channel { + rustc_version::Channel::Stable => "stable", + rustc_version::Channel::Beta => "beta", + rustc_version::Channel::Nightly => "nightly", + rustc_version::Channel::Dev => "dev", + } +} + fn main() { // Enable backtraces unless a RUST_BACKTRACE value has already been explicitly provided. if std::env::var("RUST_BACKTRACE").is_err() { From b296ac9ebaa87b0861e6f3d78732abb60edc3322 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Fri, 13 Sep 2024 11:14:39 +1000 Subject: [PATCH 2/2] Fix cargo lock --- Cargo.lock | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.lock b/Cargo.lock index 94eb9038447..a92db10f9d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5035,6 +5035,7 @@ dependencies = [ "lighthouse_version", "logging", "malloc_utils", + "rustc_version 0.4.1", "sensitive_url", "serde", "serde_json",