#cargo #build #tool #instructions

build vergen

Generate build, git, and rustc related ‘cargo:rustc-env’ instructions via ‘build.rs’ for use in your code via the env! macro

40 releases (23 stable)

new 4.2.0 Mar 1, 2021
3.2.0 Feb 9, 2021
3.1.0 Mar 10, 2020
3.0.4 Oct 16, 2018
0.0.6 Mar 26, 2015

#2 in Development tools

Download history 12505/week @ 2020-11-15 11697/week @ 2020-11-22 12452/week @ 2020-11-29 11741/week @ 2020-12-06 11817/week @ 2020-12-13 10785/week @ 2020-12-20 9708/week @ 2020-12-27 13200/week @ 2021-01-03 11438/week @ 2021-01-10 13165/week @ 2021-01-17 14502/week @ 2021-01-24 12767/week @ 2021-01-31 13400/week @ 2021-02-07 16481/week @ 2021-02-14 17616/week @ 2021-02-21 18463/week @ 2021-02-28

55,894 downloads per month
Used in 89 crates (40 directly)

MIT/Apache

125KB
2.5K SLoC

vergen

Generate build, git, and rustc related 'cargo:rustc-env' instructions via 'build.rs' for use in your code via the env! macro

Current Release

docs.rs Crates.io Crates.io Crates.io codecov CI

Example Usage

See the documentation at docs.rs for example usage

Release 4 Breaking Changes

  • The main entry point for use has changed from generate_cargo_keys to vergen
  • There are now 4 features that allow you to control what instructions can be generated (build, cargo, git, and rustc).
    • The build feature enables the VERGEN_BUILD_* instructions.
    • The git feature enables the VERGEN_GIT_* instructions and the cargo:rerun-if-changed instructions.
    • The rustc feature enables the VERGEN_RUSTC_* instructions.
    • The cargo feature enables the VERGEN_CARGO_* instructions.
    • By default, all features are enabled.
    • You can build with all features disabled, which basically make the vergen function a no-op.
    • You can still use ConstantsFlags with the gen function to toggle individual cargo instructions, but it has been deprecated.
  • The generated instructions have been normalized. Therefore, you may need to update what env variable you are referring to in code. I've included a list below of the full set of instructions that can be generated for reference.
cargo:rustc-env=VERGEN_BUILD_TIMESTAMP=2021-02-25T23:28:39.493201+00:00
cargo:rustc-env=VERGEN_BUILD_SEMVER=4.1.0
cargo:rustc-env=VERGEN_GIT_BRANCH=feature/datetime-toggles
cargo:rustc-env=VERGEN_GIT_COMMIT_TIMESTAMP=2021-02-24T20:55:21+00:00
cargo:rustc-env=VERGEN_GIT_SEMVER=4.1.0-2-gf49246c
cargo:rustc-env=VERGEN_GIT_SHA=f49246ce334567bff9f950bfd0f3078184a2738a
cargo:rustc-env=VERGEN_RUSTC_CHANNEL=nightly
cargo:rustc-env=VERGEN_RUSTC_COMMIT_DATE=2021-02-24
cargo:rustc-env=VERGEN_RUSTC_COMMIT_HASH=a8486b64b0c87dabd045453b6c81500015d122d6
cargo:rustc-env=VERGEN_RUSTC_HOST_TRIPLE=x86_64-apple-darwin
cargo:rustc-env=VERGEN_RUSTC_LLVM_VERSION=11.0
cargo:rustc-env=VERGEN_RUSTC_SEMVER=1.52.0-nightly
cargo:rustc-env=VERGEN_CARGO_TARGET_TRIPLE=x86_64-unknown-linux-gnu
cargo:rustc-env=VERGEN_CARGO_PROFILE=debug
cargo:rustc-env=VERGEN_CARGO_FEATURES=git,build
cargo:rerun-if-changed=/Users/kon8116/projects/rust-lang/vergen/.git/HEAD
cargo:rerun-if-changed=/Users/kon8116/projects/rust-lang/vergen/.git/refs/heads/feature/datetime-toggles
  • Under the hood, the Commands used for git have been removed in lieu of using the git2 library directly.
  • git2 is also used to determine the HEAD path and the path that it refers to for the cargo:rerun-if-changed instructions. This is more reliable then the manual method that was in place before.
  • I've migrated the CI stuff from Travis to GitHub Actions.

Contributing

See the documentation at CONTRIBUTING.md

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~1.1–3.5MB
~75K SLoC