vergen - Emit cargo instructions from a build script
vergen, when used in conjunction with cargo build scripts can emit the following:
- Will emit
cargo:rustc-env=VAR=VALUEfor each feature you have enabled. These can be referenced with theenv!macro in your code. - Will emit
cargo:rerun-if-changed=.git/HEADif the git feature is enabled. This is done to ensure any git instructions are regenerated when commits are made. - Will emit
cargo:rerun-if-changed=.git/<path_to_ref>if the git feature is enabled. This is done to ensure any git instructions are regenerated when commits are made. - Can emit
cargo:warningoutputs if thefail_on_errorfeature is not enabled and the requested variable is defaulted through error or theidempotentflag. - Will emit
cargo:rerun-if-changed=build.rsto rerun instruction emission if thebuild.rsfile changed. - Will emit
cargo:rurun-if-env-changed=VERGEN_IDEMPOTENTto rerun instruction emission if theVERGEN_IDEMPOTENTenvironment variable has changed. - Will emit
cargo:rurun-if-env-changed=SOURCE_DATE_EPOCHto rerun instruction emission if theSOURCE_DATE_EPOCHenvironment variable has changed.
Current Release
Sponsors
Special thanks to the sponsors of this project
⚠️ This documention is for the version 8 beta ⚠️
If you wish to refer to version 7 you can find that branch here
MSRV
The current minimum supported rust version is 1.62.0
Example Usage
See the documentation at docs.rs for example usage
Notes about the optional git2 0.15 dependency
This update to git2 picked up some security related features. In docker environments especially, this requires a safe.directory configuration. There are a couple methods for achieving this.
- If you control the build, you can add
git config --global --add safe.directory /workspaceto the build file. - If you do not control the docker build, you can add
git config --global --add safe.directory /workspace &&before the actual command you are running when using docker run. - If you do not control the docker build, you can mount a
.gitconfigfile at/rootthat includes thesafe.directoryconfiguration. I use this method myself when building static binaries with clux/muslrust.
docker run -v cargo-cache:/root/.cargo/registry -v (pwd):/volume -v ~/.gitconfig:/root/.gitconfig:ro --rm -t clux/muslrust:stable cargo build --release
See https://github.com/rustyhorde/vergen/pull/126 for more discussion on the topic. If the solutions above do not work for your usecase, you can pin your vergen version to 7.4.3. Feel free to open issues about this. If it comes up enough, I could support a version of vergen with the older git2 dependency.
Contributing
See the documentation at CONTRIBUTING.md
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT) at your option.
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.