From 675f7e66ee4be701e9237f4409d2ecff97209f1c Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Fri, 13 Sep 2024 10:59:46 +1000 Subject: [PATCH 1/7] 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/7] 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", From 5990ecfe3e37b9ac39a904c027106414e532c722 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Fri, 13 Sep 2024 12:56:58 +1000 Subject: [PATCH 3/7] Add `make reproducible` --- Makefile | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Makefile b/Makefile index e6420a4c984..9aaa4bfa04e 100644 --- a/Makefile +++ b/Makefile @@ -44,6 +44,14 @@ install: --profile "$(PROFILE)" \ $(CARGO_INSTALL_EXTRA_FLAGS) +# Builds Lighthouse in a reproducible way such that two binaries for the same commit on the same +# architecture are bit-identical. We remap the source directory to `/project/` as that is what +# the Cross builds use. +reproducible: + env RUSTFLAGS="--remap-path-prefix=$(CURDIR)=/project" cargo build --bin lighthouse --locked \ + --features "$(FEATURES)" \ + --profile "$(PROFILE)" + # Builds the lcli binary in release (optimized). install-lcli: cargo install --path lcli --force --locked \ From 91ca883357a2fe3e124d6ae16fc3eee71c83f911 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Fri, 13 Sep 2024 14:56:28 +1000 Subject: [PATCH 4/7] Disable openssl build timestamp --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9aaa4bfa04e..761a767e92c 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,7 @@ install: # architecture are bit-identical. We remap the source directory to `/project/` as that is what # the Cross builds use. reproducible: - env RUSTFLAGS="--remap-path-prefix=$(CURDIR)=/project" cargo build --bin lighthouse --locked \ + env SOURCE_DATE_EPOCH="1" RUSTFLAGS="--remap-path-prefix=$(CURDIR)=/project -C split-debuginfo=packed" cargo build --bin lighthouse --locked \ --features "$(FEATURES)" \ --profile "$(PROFILE)" From e3d2197bff49f1e59ec99bdf1ed12b472253a6c7 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Mon, 23 Sep 2024 15:27:36 +1000 Subject: [PATCH 5/7] Set source epoch in Cross build.env --- Cross.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Cross.toml b/Cross.toml index 871391253d3..809a24839a2 100644 --- a/Cross.toml +++ b/Cross.toml @@ -1,3 +1,6 @@ +[build.env] +passthrough = ["SOURCE_DATE_EPOCH=1"] + [target.x86_64-unknown-linux-gnu] pre-build = ["apt-get install -y cmake clang-5.0"] From e34b0d443a28264af4c12b81314937a547a62678 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Mon, 23 Sep 2024 15:44:59 +1000 Subject: [PATCH 6/7] Don't adjust debuginfo unnecessarily --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 761a767e92c..e0798181b73 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,7 @@ install: # architecture are bit-identical. We remap the source directory to `/project/` as that is what # the Cross builds use. reproducible: - env SOURCE_DATE_EPOCH="1" RUSTFLAGS="--remap-path-prefix=$(CURDIR)=/project -C split-debuginfo=packed" cargo build --bin lighthouse --locked \ + env SOURCE_DATE_EPOCH="1" RUSTFLAGS="--remap-path-prefix=$(CURDIR)=/project" cargo build --bin lighthouse --locked \ --features "$(FEATURES)" \ --profile "$(PROFILE)" From f14463e4e21d48f8c2121c36a34e36fdee6f562b Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Mon, 23 Sep 2024 16:05:45 +1000 Subject: [PATCH 7/7] Revert "Include compiler version in `lighthouse --version`" This reverts commit 675f7e66ee4be701e9237f4409d2ecff97209f1c. --- Cargo.toml | 1 - lighthouse/Cargo.toml | 1 - lighthouse/src/main.rs | 25 ------------------------- 3 files changed, 27 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d8c6f487cfa..125231ad20e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -152,7 +152,6 @@ 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 c6b7ea50cbc..7c37aa6d67d 100644 --- a/lighthouse/Cargo.toml +++ b/lighthouse/Cargo.toml @@ -61,7 +61,6 @@ 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 cf8dc2321b2..e865fbd272e 100644 --- a/lighthouse/src/main.rs +++ b/lighthouse/src/main.rs @@ -35,7 +35,6 @@ 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(), @@ -43,7 +42,6 @@ pub static LONG_VERSION: LazyLock = LazyLock::new(|| { have_sha_extensions(), allocator_name(), build_profile_name(), - compiler_version(), cfg!(feature = "spec-minimal"), cfg!(feature = "gnosis"), ) @@ -87,29 +85,6 @@ 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() {