Skip to content
Open
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
27 changes: 3 additions & 24 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 @@ -94,6 +94,7 @@ resolver = "2"

[workspace.package]
edition = "2024"
version = "8.0.0-rc.2"

[workspace.dependencies]
account_utils = { path = "common/account_utils" }
Expand Down
2 changes: 1 addition & 1 deletion account_manager/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "account_manager"
version = "0.3.5"
version = { workspace = true }
authors = [
"Paul Hauner <paul@paulhauner.com>",
"Luke Anderson <luke@sigmaprime.io>",
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "beacon_node"
version = "8.0.0-rc.2"
version = { workspace = true }
authors = [
"Paul Hauner <paul@paulhauner.com>",
"Age Manning <Age@AgeManning.com",
Expand Down
2 changes: 1 addition & 1 deletion boot_node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "boot_node"
version = "8.0.0-rc.2"
version = { workspace = true }
authors = ["Sigma Prime <contact@sigmaprime.io>"]
edition = { workspace = true }

Expand Down
3 changes: 1 addition & 2 deletions common/lighthouse_version/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
[package]
name = "lighthouse_version"
version = "0.1.0"
version = { workspace = true }
authors = ["Sigma Prime <contact@sigmaprime.io>"]
edition = { workspace = true }
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
git-version = "0.3.4"

[dev-dependencies]
regex = { workspace = true }
81 changes: 81 additions & 0 deletions common/lighthouse_version/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
use std::env;
use std::fs;
use std::path::Path;
use std::process::Command;

const CLIENT_NAME: &str = "Lighthouse";

fn main() {
println!("cargo:rerun-if-changed=build.rs");

let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let manifest_path = Path::new(&manifest_dir);

// The crate version is inherited from the workspace.
let semantic_version = env::var("CARGO_PKG_VERSION").unwrap();

// Hardcode the .git/ path.
// This assumes the `lighthouse_version` crate will never move.
let git_dir = manifest_path.join("../../.git");

if git_dir.exists() {
// HEAD either contains a commit hash directly (detached HEAD), or a reference to a branch.
let head_path = git_dir.join("HEAD");
if head_path.exists() {
println!("cargo:rerun-if-changed={}", head_path.display());

if let Ok(head_content) = fs::read_to_string(&head_path) {
let head_content = head_content.trim();

// If HEAD is a reference, also check that file.
if let Some(ref_path) = head_content.strip_prefix("ref: ") {
let full_ref_path = git_dir.join(ref_path);
if full_ref_path.exists() {
println!("cargo:rerun-if-changed={}", full_ref_path.display());
}
}
}
}
}

// Construct Lighthouse version string without commit hash.
let base_version = format!("{}/v{}", CLIENT_NAME, semantic_version);

let commit_hash = get_git_hash(7);
let commit_prefix = get_git_hash(8);

// If commit hash is valid, construct the full version string.
let version = if !commit_hash.is_empty() && commit_hash.len() >= 7 {
format!("{}-{}", base_version, commit_hash)
} else {
base_version
};

println!("cargo:rustc-env=GIT_VERSION={}", version);
println!("cargo:rustc-env=GIT_COMMIT_PREFIX={}", commit_prefix);
println!("cargo:rustc-env=CLIENT_NAME={}", CLIENT_NAME);
println!("cargo:rustc-env=SEMANTIC_VERSION={}", semantic_version);
}

fn get_git_hash(len: usize) -> String {
Command::new("git")
.args(["rev-parse", &format!("--short={}", len), "HEAD"])
.output()
.ok()
.and_then(|output| {
if output.status.success() {
String::from_utf8(output.stdout).ok()
} else {
None
}
})
.map(|s| s.trim().to_string())
.unwrap_or_else(|| {
// Fallback commit prefix for execution engine reporting.
if len == 8 {
"00000000".to_string()
} else {
String::new()
}
})
}
50 changes: 18 additions & 32 deletions common/lighthouse_version/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,49 +1,25 @@
use git_version::git_version;
use std::env::consts;

/// Returns the current version of this build of Lighthouse.
///
/// A plus-sign (`+`) is appended to the git commit if the tree is dirty.
/// Commit hash is omitted if the sources don't include git information.
///
/// ## Example
///
/// `Lighthouse/v1.5.1-67da032+`
pub const VERSION: &str = git_version!(
args = [
"--always",
"--dirty=+",
"--abbrev=7",
// NOTE: using --match instead of --exclude for compatibility with old Git
"--match=thiswillnevermatchlol"
],
prefix = "Lighthouse/v8.0.0-rc.2-",
fallback = "Lighthouse/v8.0.0-rc.2"
);
/// `Lighthouse/v8.0.0-67da032`
pub const VERSION: &str = env!("GIT_VERSION");

/// Returns the first eight characters of the latest commit hash for this build.
///
/// No indication is given if the tree is dirty. This is part of the standard
/// for reporting the client version to the execution engine.
pub const COMMIT_PREFIX: &str = git_version!(
args = [
"--always",
"--abbrev=8",
// NOTE: using --match instead of --exclude for compatibility with old Git
"--match=thiswillnevermatchlol"
],
prefix = "",
suffix = "",
cargo_prefix = "",
cargo_suffix = "",
fallback = "00000000"
);
pub const COMMIT_PREFIX: &str = env!("GIT_COMMIT_PREFIX");
Comment on lines -13 to +16
Copy link
Member Author

Choose a reason for hiding this comment

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

We could also consider moving to an 8 character commit hash. Currently we provide both a 7 character hash (for --version, etc) and an 8 character hash (for execution engine reporting). If we can use 8 character hashes for everything, that would reduce some complexity


/// Returns `VERSION`, but with platform information appended to the end.
///
/// ## Example
///
/// `Lighthouse/v1.5.1-67da032+/x86_64-linux`
/// `Lighthouse/v8.0.0-67da032/x86_64-linux`
pub fn version_with_platform() -> String {
format!("{}/{}-{}", VERSION, consts::ARCH, consts::OS)
}
Expand All @@ -52,16 +28,16 @@ pub fn version_with_platform() -> String {
///
/// ## Example
///
/// `1.5.1`
/// `8.0.0`
pub fn version() -> &'static str {
"8.0.0-rc.2"
env!("SEMANTIC_VERSION")
}

/// Returns the name of the current client running.
///
/// This will usually be "Lighthouse"
pub fn client_name() -> &'static str {
"Lighthouse"
env!("CLIENT_NAME")
}

#[cfg(test)]
Expand All @@ -72,7 +48,7 @@ mod test {
#[test]
fn version_formatting() {
let re = Regex::new(
r"^Lighthouse/v[0-9]+\.[0-9]+\.[0-9]+(-(rc|beta).[0-9])?(-[[:xdigit:]]{7})?\+?$",
r"^Lighthouse/v[0-9]+\.[0-9]+\.[0-9]+(-(rc|beta)\.[0-9])?(-[[:xdigit:]]{7})?$",
)
.unwrap();
assert!(
Expand All @@ -91,4 +67,14 @@ mod test {
version()
);
}

#[test]
fn client_name_is_lighthouse() {
assert_eq!(client_name(), "Lighthouse");
}

#[test]
fn version_contains_semantic_version() {
assert!(VERSION.contains(version()));
}
}
2 changes: 1 addition & 1 deletion lcli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "lcli"
description = "Lighthouse CLI (modeled after zcli)"
version = "8.0.0-rc.2"
version = { workspace = true }
authors = ["Paul Hauner <paul@paulhauner.com>"]
edition = { workspace = true }

Expand Down
2 changes: 1 addition & 1 deletion lighthouse/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "lighthouse"
version = "8.0.0-rc.2"
version = { workspace = true }
authors = ["Sigma Prime <contact@sigmaprime.io>"]
edition = { workspace = true }
autotests = false
Expand Down
34 changes: 0 additions & 34 deletions scripts/change_version.sh

This file was deleted.

2 changes: 1 addition & 1 deletion validator_client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "validator_client"
version = "0.3.5"
version = { workspace = true }
authors = ["Sigma Prime <contact@sigmaprime.io>"]
edition = { workspace = true }

Expand Down
Loading