Skip to content

Conversation

@macladson
Copy link
Member

Issue Addressed

#8311

Proposed Changes

Removes the git_version crate from lighthouse_version and implements git HEAD tracking manually.
This removes the (mostly) broken dirty tracking but prevents spurious recompilation of the lighthouse_version crate.

This also reworks the way crate versions are handled by utilizing workspace version inheritance and Cargo environment variables.
This means the only place where Lighthouse's version is defined is in the top level Cargo.toml for the workspace. All relevant binaries then inherit this version. This largely makes the change_version.sh script useless so I've removed it, although we could keep a version which just alters the workspace version (if we need to maintain compatibility with certain build/release tooling.

When is a Rebuild Triggered?

  1. When the build.rs file is changed.
  2. When the HEAD commit changes (added, removed, rebased, etc)
  3. When the branch changes (this includes changing to the current branch, and creating a detached HEAD)

Note that working/staged changes will not trigger a recompile of lighthouse_version.

Additional Info

There might exist certain edge cases with packed git refs where a recompile might not get triggered after a git garbage collection cycle but I suspect this will be quite rare.

@macladson macladson added code-quality devex ready-for-review The code is ready for review labels Oct 30, 2025
Comment on lines -13 to +16
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");
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

Comment on lines -26 to -31
update_cargo_toml ../account_manager/Cargo.toml
update_cargo_toml ../beacon_node/Cargo.toml
update_cargo_toml ../boot_node/Cargo.toml
update_cargo_toml ../lcli/Cargo.toml
update_cargo_toml ../lighthouse/Cargo.toml
update_cargo_toml ../validator_client/Cargo.toml
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm using workspace version inheritance for the binaries that were explicitly listed here, but we could also include the other ones (database_manager, validator_manager, slasher) to keep it consistent

Copy link
Member

@pawanjay176 pawanjay176 left a comment

Choose a reason for hiding this comment

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

This is amazing! I have been annoyed with this behaviour for years. Thanks for fixing it.
rust-analyzer runs so much quicker now that it doesn't recompile lighthouse_version each time.

Copy link
Member

@michaelsproul michaelsproul left a comment

Choose a reason for hiding this comment

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

Looks great! So glad to have this fixed finally!

@michaelsproul michaelsproul added ready-for-merge This PR is ready to merge. and removed ready-for-review The code is ready for review labels Nov 3, 2025
@mergify mergify bot added the queued label Nov 3, 2025
mergify bot added a commit that referenced this pull request Nov 3, 2025
@mergify mergify bot merged commit 2c9b670 into sigp:unstable Nov 3, 2025
36 checks passed
@mergify mergify bot removed the queued label Nov 3, 2025
@macladson macladson deleted the fix-lighthouse-version branch November 3, 2025 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants