5 releases

0.0.6 Feb 17, 2023
0.0.5 Jan 3, 2023
0.0.4 Dec 5, 2022
0.0.3 Nov 28, 2022
0.0.2 Oct 19, 2022

#209 in Build Utils

Download history 3630/week @ 2024-06-19 3298/week @ 2024-06-26 2242/week @ 2024-07-03 5537/week @ 2024-07-10 4441/week @ 2024-07-17 4468/week @ 2024-07-24 5687/week @ 2024-07-31 3844/week @ 2024-08-07 3176/week @ 2024-08-14 4222/week @ 2024-08-21 4883/week @ 2024-08-28 4295/week @ 2024-09-04 3852/week @ 2024-09-11 4043/week @ 2024-09-18 3695/week @ 2024-09-25 3050/week @ 2024-10-02

15,930 downloads per month
Used in 78 crates (14 directly)

Apache-2.0

13KB
197 lines

crate-git-revision

Embed the git revision of a crate in its build.

Supports embedding the version from a local or remote git repository the build is occurring in, as well as when cargo install or depending on a crate published to crates.io.

It extracts the git revision in two ways:

  • From the .cargo_vcs_info.json file embedded in published crates.
  • From the git repository the build is occurring from in unpublished crates.

Injects an environment variable GIT_REVISION into the build that contains the full git revision, with a -dirty suffix if the working directory is dirty.

Requires the use of a build.rs build script. See Build Scripts for more details on how Rust build scripts work.

Examples

Add the following to the crate's Cargo.toml file:

[build_dependencies]
crate-git-revision = "0.0.2"

Add the following to the crate's build.rs file:

crate_git_revision::init();

Add the following to the crate's lib.rs or main.rs file:

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

License: Apache-2.0

Dependencies

~0.7–1.6MB
~35K SLoC