rustyhorde / vergen

Generate cargo instructions at compile time in build scripts for use with the env! or option_env! macros
Apache License 2.0
370 stars 55 forks source link

Consistency between the documentation and the outputs #262

Closed jreniel closed 10 months ago

jreniel commented 10 months ago

When I do: println!("git describe: {}", env!("VERGEN_GIT_DESCRIBE")); I just get: git describe: 45e8eb8

But I actually wanted to "git_describe": "0.0.0-7-gc96c096", Which is how it is described in the docs. That is, I was expecting it to prepend the semantic version to the hash. How can I achieve this? Also, I definitely upvote https://github.com/rustyhorde/vergen/issues/237 so that we would get something more similar to: 0.0.0-7-gc96c096-dirty

CraZySacX commented 10 months ago

What git feature do you have configured (gitcl, gitoxide or git2)? gitcl runs git describe --always (here) git2 runs the code here gitoxide run the code here

They all support the dirty flag via the git_describe configuration function

CraZySacX commented 10 months ago

Closing as this particular dirty output is currently supported. Will also be adding a VERGEN_GIT_DIRTY variable as requested in #237 . Feel free to re-open if these don't satisfy your request.

jreniel commented 10 months ago

Thanks, @CraZySacX, I was about to reply, as I'm just starting my day. I don't need to reopen, but I'm not exactly clear how to configure through the EmitBuilder. It would be nice to have some updated examples. All in all I want to thank you for your hard work with this crate and for keeping it accessible for the community.

CraZySacX commented 10 months ago

Here is how it's configured (the first argument turns on dirty, the second looks for latest tag, and the third allows an optional pattern match on tag names). Sample output below as well:

use anyhow::Result;
use vergen::EmitBuilder;

pub fn main() -> Result<()> {
    EmitBuilder::builder()
        .all_git()
        .git_describe(true, true, None)
        .emit()
}
Describe (    git): 0.1.0-1-gcfece0a
jreniel commented 10 months ago

Thanks for your help! =) =) =)