-
Notifications
You must be signed in to change notification settings - Fork 136
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
fix: trin cli flag displays wrong version info #1615
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,15 @@ | ||
use std::{fs::File, io::Write}; | ||
|
||
use shadow_rs::SdResult; | ||
|
||
fn main() -> SdResult<()> { | ||
shadow_rs::new_hook(hook)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn hook(mut file: &File) -> SdResult<()> { | ||
let env_var_git_hash = std::env::var("GIT_HASH").unwrap_or_default(); | ||
writeln!(file, "const ENV_GIT_HASH: &str = \"{}\";", env_var_git_hash)?; | ||
|
||
hook_method(file)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn hook_method(mut file: &File) -> SdResult<()> { | ||
let hook_fn = r#" | ||
pub const fn short_commit() -> &'static str { | ||
if shadow_rs::str_get!(SHORT_COMMIT, 0).is_some() { | ||
return SHORT_COMMIT; | ||
} | ||
if shadow_rs::str_get!(ENV_GIT_HASH, 0).is_some() { | ||
ENV_GIT_HASH | ||
} else { | ||
"unknown" | ||
} | ||
}"#; | ||
|
||
writeln!(file, "{}", hook_fn)?; | ||
use std::error::Error; | ||
|
||
use vergen::EmitBuilder; | ||
|
||
fn main() -> Result<(), Box<dyn Error>> { | ||
EmitBuilder::builder() | ||
.git_sha(true) | ||
.git_describe(false, true, None) | ||
.build_timestamp() | ||
.rustc_semver() | ||
.cargo_features() | ||
.cargo_target_triple() | ||
.emit()?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,31 @@ | ||
/// The latest git commit hash of the build. | ||
pub const TRIN_FULL_COMMIT: &str = env!("VERGEN_GIT_SHA"); | ||
pub const TRIN_SHORT_COMMIT: &str = const_format::str_index!(TRIN_FULL_COMMIT, ..8); | ||
|
||
/// Trin's version is the same as the git tag. | ||
pub const TRIN_VERSION: &str = const_format::str_split!(env!("VERGEN_GIT_DESCRIBE"), '-')[0]; | ||
|
||
/// The operating system of the build, linux, macos, windows etc. | ||
pub const BUILD_OPERATING_SYSTEM: &str = | ||
const_format::str_split!(env!("VERGEN_CARGO_TARGET_TRIPLE"), "-")[2]; | ||
|
||
/// The architecture of the build, x86_64, aarch64, etc. | ||
pub const BUILD_ARCHITECTURE: &str = | ||
const_format::str_split!(env!("VERGEN_CARGO_TARGET_TRIPLE"), "-")[0]; | ||
|
||
// /// The version of the programming language used to build the binary. | ||
pub const PROGRAMMING_LANGUAGE_VERSION: &str = env!("VERGEN_RUSTC_SEMVER"); | ||
|
||
pub const FULL_VERSION: &str = const_format::formatcp!( | ||
"{version}-{hash} {build_os}-{build_arch} rustc{rust_version}", | ||
version = TRIN_VERSION, | ||
hash = TRIN_SHORT_COMMIT, | ||
build_os = BUILD_OPERATING_SYSTEM, | ||
build_arch = BUILD_ARCHITECTURE, | ||
rust_version = PROGRAMMING_LANGUAGE_VERSION | ||
); | ||
|
||
/// Returns the trin version and git revision. | ||
pub const fn get_trin_version() -> &'static str { | ||
crate::build_info::short_commit() | ||
TRIN_SHORT_COMMIT | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're going to either have to set a
GIT_HASH
env var here, or update our 2 dockerfiles so that it'll pick up the env var hereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/sigp/lighthouse/blob/stable/Dockerfile
https://github.com/paradigmxyz/reth/blob/main/Dockerfile
both Lighthouse and Reth copy the whole folder, if we do that it would resolve this issue and we could remove
trin/docker/Dockerfile
Lines 8 to 11 in ddbd9ff
and passing the git hash in with the CI,
As only copying in the crates would be problematic for vergen
Reth uses this https://github.com/LukeMathWalker/cargo-chef?tab=readme-ov-file#benefits-of-cargo-chef package, which I think will resolve our caching problems we were trying to solve by copying crates individually, this should also make it so we have to update our crates less so the code is more maintainable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will make a PR updating our dockerfiles with what I said above in mind
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#1619
Here is a PR which resolves your concern, once both of these PR's are merged it will work as expected