Skip to content

Add Git information to cargo-gpu's --version CLI subcommand#623

Open
Steveplays28 wants to merge 1 commit into
Rust-GPU:mainfrom
Steveplays28:feat/add-git-info-to-cargo-gpu-cli-version-subcommand
Open

Add Git information to cargo-gpu's --version CLI subcommand#623
Steveplays28 wants to merge 1 commit into
Rust-GPU:mainfrom
Steveplays28:feat/add-git-info-to-cargo-gpu-cli-version-subcommand

Conversation

@Steveplays28

@Steveplays28 Steveplays28 commented Jun 28, 2026

Copy link
Copy Markdown

Old:

$ cargo-gpu --version
cargo-gpu 0.10.0-alpha.1

New:

$ cargo-gpu --version
cargo-gpu 0.10.0-alpha.1 (2e5047eb4b; 2026-06-28)

I left the short version subcommand (-V) unchanged.

@nazar-pc nazar-pc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@Steveplays28

Steveplays28 commented Jun 29, 2026

Copy link
Copy Markdown
Author

@nazar-pc well okay, fair.
I'll keep the Git CLI invocation that was there before

@Steveplays28 Steveplays28 marked this pull request as draft June 29, 2026 06:36
@Steveplays28 Steveplays28 force-pushed the feat/add-git-info-to-cargo-gpu-cli-version-subcommand branch from 2e5047e to 85f9e81 Compare June 29, 2026 06:49
Added the commit hash and date to the `--version` CLI subcommand.
@Steveplays28 Steveplays28 force-pushed the feat/add-git-info-to-cargo-gpu-cli-version-subcommand branch from 85f9e81 to 9ffe19b Compare June 29, 2026 07:05
@Steveplays28 Steveplays28 marked this pull request as ready for review June 29, 2026 07:06
@Steveplays28

Steveplays28 commented Jun 29, 2026

Copy link
Copy Markdown
Author

I added a helper function for invoking Git, added cargo:rerun-if-changed lines and got the date through the Git CLI. Thanks for checking the PR, Nazar.

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 nazar-pc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks much better, thanks 🙂

Comment thread crates/cargo-gpu/build.rs
Comment on lines +7 to +14
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()
);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@Steveplays28 Steveplays28 Jun 29, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

from what I read on StackOverflow it is but I haven't tested without those rerun-if-changed lines 😅

@Steveplays28 Steveplays28 Jun 29, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@Steveplays28 Steveplays28 Jun 30, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants