#build-script #cargo-build #git #build #git-version #version #cargo

build grev

A crate for working with git revision information from a build script

4 releases

0.1.3 Jan 6, 2023
0.1.2 Jan 3, 2023
0.1.1 Dec 24, 2022
0.1.0 Dec 24, 2022

#403 in Build Utils

Download history 464/week @ 2024-07-27 352/week @ 2024-08-03 819/week @ 2024-08-10 391/week @ 2024-08-17 198/week @ 2024-08-24 744/week @ 2024-08-31 150/week @ 2024-09-07 350/week @ 2024-09-14 304/week @ 2024-09-21 315/week @ 2024-09-28 698/week @ 2024-10-05 920/week @ 2024-10-12 537/week @ 2024-10-19 733/week @ 2024-10-26 381/week @ 2024-11-02 394/week @ 2024-11-09

2,447 downloads per month
Used in 9 crates (8 directly)

Apache-2.0 OR MIT

16KB
225 lines

pipeline crates.io Docs rustc

grev

A crate for working with git revision information from a build script.


lib.rs:

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").

Dependencies

~135KB