#git-repository #build #build-script #cargo-build #revision #embed #io

build crate-git-revision

Embed git revision into crates built and published

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

#98 in Build Utils

Download history 4020/week @ 2024-04-21 3940/week @ 2024-04-28 4065/week @ 2024-05-05 3829/week @ 2024-05-12 1831/week @ 2024-05-19 3132/week @ 2024-05-26 3803/week @ 2024-06-02 3932/week @ 2024-06-09 4736/week @ 2024-06-16 3611/week @ 2024-06-23 2072/week @ 2024-06-30 3402/week @ 2024-07-07 5895/week @ 2024-07-14 3493/week @ 2024-07-21 6354/week @ 2024-07-28 4757/week @ 2024-08-04

20,992 downloads per month
Used in 76 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.8–1.7MB
~36K SLoC