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

Include compiler version in lighthouse --version #6392

Closed
wants to merge 2 commits into from
Closed
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
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions lighthouse/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
25 changes: 25 additions & 0 deletions lighthouse/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ pub static LONG_VERSION: LazyLock<String> = LazyLock::new(|| {
SHA256 hardware acceleration: {}\n\
Allocator: {}\n\
Profile: {}\n\
Compiler: {}\n\
Specs: mainnet (true), minimal ({}), gnosis ({})",
SHORT_VERSION.as_str(),
bls_library_name(),
bls_hardware_acceleration(),
have_sha_extensions(),
allocator_name(),
build_profile_name(),
compiler_version(),
cfg!(feature = "spec-minimal"),
cfg!(feature = "gnosis"),
)
Expand Down Expand Up @@ -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");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will error if the command rustc -vV fails to run.

https://docs.rs/rustc_version/0.4.1/src/rustc_version/lib.rs.html#201
https://docs.rs/rustc_version/0.4.1/src/rustc_version/lib.rs.html#180

Is this run on compilation of on every run of LH?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh shit I think you're right, this is running at runtime 🤦‍♂️

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() {
Expand Down
Loading