Skip to content
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

Normal method for embedding git commit in the version? #527

Closed
lilith opened this issue Jun 11, 2016 · 5 comments
Closed

Normal method for embedding git commit in the version? #527

lilith opened this issue Jun 11, 2016 · 5 comments

Comments

@lilith
Copy link

lilith commented Jun 11, 2016

I want to be able to track down what version of the software a user is using, based on git commit ID.

I see this showing up in most Rust command-line tools, but I haven't figured out how it's done.

Any suggestions?

@kbknapp
Copy link
Member

kbknapp commented Jun 12, 2016

You can either manually add the commit hash and just add it your version with App::version as in:

const LATEST_COMMIT: &'static str = "abcd1234";
fn main() {
    App::new("prog").version(&*format!("v1.2.3 ({})", LATEST_COMMIT));
}

But what I think most people do is add a build.rs script to pull the latest commit hash automatically.

Although this isn't really anything specific to clap.

@lilith
Copy link
Author

lilith commented Jun 12, 2016

Thanks! I found this approach based on your suggestion:

  1. Write it out to a text file during build: https://github.com/rust-lang-nursery/rustup.rs/blob/master/build.rs
  2. Read the text file in at runtime: https://github.com/rust-lang-nursery/rustup.rs/blob/27f64753d016acbf93b833fc3618ce09f14ab9a3/src/rustup-cli/common.rs#L339

I'm distributing a single binary, so maybe I'll write code to write code. You can change .rs files in build.rs, right? Or do you know of a project that's already doing this?

Definitely not specific to clap, but I'd like to add an example when I figure it out, since it seems like a ubiquitous need.

@jhelwig
Copy link

jhelwig commented Jun 12, 2016

https://github.com/cstorey/git-build-version/ is an example of how to do this without requiring files be available at runtime.

@kbknapp kbknapp closed this as completed Jun 23, 2016
@zmlgirl
Copy link

zmlgirl commented Apr 27, 2023

for now it's a good idea to use creat shadow-rs.

@acro5piano
Copy link

Great example for integrating clap struct with shadow-rs.

baoyachi/shadow-rs#86 (comment)

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

No branches or pull requests

5 participants