Crate grev

source ·
Expand description

This library provides the means for including partly opinionated git revision identifiers inside a Rust project (typically a binary). It provides a set of functions, all meant to be invoked from a build script, which inquire the current git revision being built against.

Typical usage could look like this:

use grev::git_revision_auto;

fn main() -> Result<()> {
  let dir = env!("CARGO_MANIFEST_DIR");
  if let Some(git_rev) = git_revision_auto(dir)? {
    println!(
      "cargo:rustc-env=VERSION={} ({})",
      env!("CARGO_PKG_VERSION"),
      git_rev
    );
  } else {
    println!("cargo:rustc-env=VERSION={}", env!("CARGO_PKG_VERSION"));
  }
  Ok(())
}

This logic, contained in a Cargo build script (typically build.rs, located in a project’s root), will cause the environment variable VERSION to be set unconditionally when building the program. It will contain the package version and, if available, the git revision at which the build happened (including a modifier indicating if local changes were present). If building at a git tag, the revision string will include this tag. The main program would then inquire the version string using env!("VERSION").

Functions

get_revisionDeprecated
Retrieve a git revision identifier that either includes the tag we are on or the shortened SHA-1. It also contains an indication (+) whether local changes were present.
git_revisionDeprecated
Retrieve a git revision identifier that either includes the tag we are on or the shortened SHA-1. It also contains an indication (+) whether local changes were present.
Retrieve a git revision identifier that either includes the tag we are on or the shortened SHA-1. It also contains an indication (+) whether local changes were present.
Retrieve a git revision identifier that either includes the tag we are on or the shortened SHA-1.