Add Git information to cargo-gpu's --version CLI subcommand#623
Add Git information to cargo-gpu's --version CLI subcommand#623Steveplays28 wants to merge 1 commit into
--version CLI subcommand#623Conversation
nazar-pc
left a comment
There was a problem hiding this comment.
It is just my opinion, but it seems really wasteful to add such a massive dependency tree for such a tiny feature.
You essentially added more than 1000 lines of dependencies just to obtain VERGEN_GIT_COMMIT_DATE environment variable, which doesn't make sense to me. Everything else was already there.
Adding commit hash is a single line change instead of current +1346 -80, adding date is a bit more than that, but still less than what this PR does.
|
@nazar-pc well okay, fair. |
2e5047e to
85f9e81
Compare
Added the commit hash and date to the `--version` CLI subcommand.
85f9e81 to
9ffe19b
Compare
|
I added a helper function for invoking Git, added My bad for not doing it in this simple way in the first place, I agree that this is better. Less time needed to compile and less code to maintain |
nazar-pc
left a comment
There was a problem hiding this comment.
This looks much better, thanks 🙂
| println!("cargo:rerun-if-changed={git_directory}/HEAD"); | ||
| println!("cargo:rerun-if-changed={git_directory}/packed-refs"); | ||
| if let Ok(git_head) = std::fs::read_to_string(format!("{git_directory}/HEAD")) && let Some(git_ref) = git_head.strip_prefix("ref: ") { | ||
| println!( | ||
| "cargo:rerun-if-changed={git_directory}/{}", | ||
| git_ref.trim() | ||
| ); | ||
| } |
There was a problem hiding this comment.
Are you sure these rerun-if-changed are actually needed?
If installed from git repository, the revision will have to change, and the whole crate will be recompiled anyway.
I'm not sure what is the situation where these are actually necessary.
There was a problem hiding this comment.
from what I read on StackOverflow it is but I haven't tested without those rerun-if-changed lines 😅
There was a problem hiding this comment.
I just tested it, if I make a commit without those rerun-if-changed lines, then re-compile with e.g. cargo run -p cargo-gpu -- --version, COMMIT_HASH doesn't update
so you could get a situation where you think the program is compiled from an old commit when it isn't
There was a problem hiding this comment.
You already know what version you have locally, so I don't think it matters in that case. And if it is not local, then it is installed from git repo and will be treated as a separate crate anyway.
There was a problem hiding this comment.
I still think it would be a bug to leave out cargo:rerun-if-changed. If you were to run cargo build and copy the binary for local use, it would contain an incorrect commit hash and date.
It could be confusing to someone in the future.
Old:
New:
$ cargo-gpu --version cargo-gpu 0.10.0-alpha.1 (2e5047eb4b; 2026-06-28)I left the short version subcommand (
-V) unchanged.