#git #build #tags #env-var #build-time #build-tool #variables

build git_describe_build_tool

Retrieve Git tag, store as environment variable at build time

2 stable releases

1.0.2 May 15, 2022

#772 in Build Utils

Download history 57/week @ 2024-07-27 120/week @ 2024-08-03 50/week @ 2024-08-10 101/week @ 2024-08-17 143/week @ 2024-08-24 85/week @ 2024-08-31 79/week @ 2024-09-07 76/week @ 2024-09-14 123/week @ 2024-09-21 31/week @ 2024-09-28 32/week @ 2024-10-05 3/week @ 2024-10-12 48/week @ 2024-10-19 6/week @ 2024-10-26 23/week @ 2024-11-02 45/week @ 2024-11-09

122 downloads per month

MIT license

5KB

git_describe_build_tool

Retrieve Git tag, store as environment variable at build time

The command git describe --tags

... finds the most recent tag that is reachable from a commit. If the tag points to the commit, then only the tag is shown. Otherwise, it suffixes the tag name with the number of additional commits on top of the tagged object and the abbreviated object name of the most recent commit. The result is a "human-readable" object name which can also be used to identify the commit to other git commands ...

-- Git Manual

Example

To use, simply add as a build dependency to your cargo.toml

[package]
build = "build.rs"

[build-dependencies]
git_describe_build_tool = "~1.0.0"

Then, add build.rs

use git_describe_build_tool::prelude::*;

fn main() {
    git_build_script();
}

Then, in your code, whenever you want to reference the current version use the env! macro

pub const GIT_COMMIT_DESCRIBE: &str = env!("GIT_COMMIT_DESCRIBE");

assert_eq! {
    "0.11.0-51-g4446464",
    GIT_COMMIT_DESCRIBE
}

License: MIT

No runtime deps