#date-time #build-time #git-commit #time #commit #build #date

rbtag

A procedural macro to add build DateTime and git commit information at compile time

3 releases (breaking)

0.3.0 Jan 28, 2019
0.2.0 Jan 16, 2019
0.1.0 Jan 15, 2019

#1216 in Rust patterns

Download history 24843/week @ 2024-05-22 24296/week @ 2024-05-29 16811/week @ 2024-06-05 18743/week @ 2024-06-12 17193/week @ 2024-06-19 18384/week @ 2024-06-26 20778/week @ 2024-07-03 17133/week @ 2024-07-10 26191/week @ 2024-07-17 26153/week @ 2024-07-24 17204/week @ 2024-07-31 29770/week @ 2024-08-07 28519/week @ 2024-08-14 23087/week @ 2024-08-21 32029/week @ 2024-08-28 25815/week @ 2024-09-04

116,287 downloads per month
Used in 2 crates

MIT license

5KB

RBTAG

rbtag is a procedural macro designed to add build time information or git commit information to your crate or project.

Git Commit Info

To use the Git commit Info functionality just add #[derive(BuildInfo)] to a struct and call .get_build_commit() on it. The output looks like the following:

eaba6e2-dirty

OR

eaba6e2-clean

Where clean vs dirty indicates the presence of uncommited changes to tracked files in the repo.

NOTE If you have this code continue to return 'dirty', run git diff to see what files are causing the issue.

Build Time Info

To use the Git commit Info functionality just add #[derive(BuildDateTime)] to a struct and call .get_build_timestamp() on it. In order to comply with https://reproducible-builds.org/, two sources of time are possibly used the following precedence

  1. If the environmental variable SOURCE_DATE_EPOCH is set, the value in this variable will be used
  2. If the environmental variable is NOT set, the timestamp of the current git commit is used and displayed as a UNIX timestamp with no fractional component

Sample output:

The following is an example of running the below 'example' code with and without an environmental variable set

#$ cargo clean && env SOURCE_DATE_EPOCH='12345678909' cargo run
12345678901
90c2266-dirty
#? cargo clean && cargo run
1547647585
90c2266-dirty

Example

use rbtag::{BuildDateTime, BuildInfo};

#[derive(BuildDateTime, BuildInfo)]
struct BuildTag;

fn main() {
    println!("{}", BuildTag{}.get_build_timestamp());
    println!("{}", BuildTag{}.get_build_commit());
}

Dependencies

~2MB
~47K SLoC