#git-commit #git-status #proc-macro #build #git-version #tree #tags

no-std build git-testament

Record git working tree status when compiling your crate

14 releases

0.2.6 Nov 28, 2024
0.2.5 Sep 20, 2023
0.2.4 Jan 18, 2023
0.2.2 Dec 30, 2022
0.1.6 May 7, 2019

#35 in Build Utils

Download history 1803/week @ 2024-08-17 1978/week @ 2024-08-24 2231/week @ 2024-08-31 2115/week @ 2024-09-07 2617/week @ 2024-09-14 2210/week @ 2024-09-21 1758/week @ 2024-09-28 1933/week @ 2024-10-05 2233/week @ 2024-10-12 2555/week @ 2024-10-19 1771/week @ 2024-10-26 1650/week @ 2024-11-02 2029/week @ 2024-11-09 3272/week @ 2024-11-16 3107/week @ 2024-11-23 3118/week @ 2024-11-30

11,730 downloads per month
Used in 33 crates (17 directly)

BSD-3-Clause

23KB
224 lines

Git Testament

BSD 3 Clause Main build status Latest docs Crates.IO

git-testament is a library to embed a testament as to the state of a git working tree during the build of a Rust program. It uses the power of procedural macros to embed commit, tag, and working-tree-state information into your program when it is built. This can then be used to report version information.

use git_testament::{git_testament, render_testament};

git_testament!(TESTAMENT);

fn main() {
    println!("My version information: {}", render_testament!(TESTAMENT));
}

The above code may print, for example, for a clean build from a 1.0.0 tag:

My version information: 1.0.0 (763aa159d 2019-04-02)

Or something like 1.0.0+14 (651af89ed 2019-04-02) dirty 4 modifications if the working tree is dirty and there have been some commits since the last tag.

To access the testament data (for example to render it yourself), the documentation describes all the details.

Reproducible builds

In the case that your build is not being done from a Git repository, you still want your testament to be useful to your users. Reproducibility of the binary is critical in that case. The Reproducible Builds team have defined a mechanism for this known as SOURCE_DATE_EPOCH which is an environment variable which can be set to ensure the build date is fixed for reproducibilty reasons. If you have no repo (or a repo but no commit) then git_testament!() will use the SOURCE_DATE_EPOCH environment variable (if present and parseable as a number of seconds since the UNIX epoch) to override now.

Use in no_std scenarios

This crate does not link to anything in the standard library, but it does rely by default on the alloc library being available. Disabling the alloc feature allows the crate to work in no_std environments where the alloc library is not available. You can still generate a GitTestament struct though it'll be less easy to work with. Instead it'd be recommended to use the git_testament_macros!() macro instead which provides a set of macros which produce string constants to use. This is less flexible/capable but can sometimes be easier to work with in these kinds of situations.

Dependencies

~1–1.5MB
~32K SLoC