pub struct Build { /* private fields */ }build only.Expand description
The VERGEN_BUILD_* configuration features
| Variable | Sample |
|---|---|
VERGEN_BUILD_DATE | 2021-02-25 |
VERGEN_BUILD_TIMESTAMP | 2021-02-25T23:28:39.493201+00:00 |
§Example
Emit all of the build instructions
let build = Build::all_build();
Emitter::new().add_instructions(&build)?.emit()?;Emit some of the build instructions
let build = Build::builder().build_timestamp(true).build();
Emitter::new().add_instructions(&build)?.emit()?;Override output with your own value
temp_env::with_var("VERGEN_BUILD_DATE", Some("01/01/2023"), || {
let result = || -> Result<()> {
let build = Build::builder().build_date(true).build();
Emitter::new().add_instructions(&build)?.emit()?;
Ok(())
}();
assert!(result.is_ok());
});§Example
This feature can also be used in conjuction with the SOURCE_DATE_EPOCH
environment variable to generate deterministic timestamps based off the
last modification time of the source/package
temp_env::with_var("SOURCE_DATE_EPOCH", Some("1671809360"), || {
let result = || -> Result<()> {
let build = Build::all_build();
Emitter::new().add_instructions(&build)?.emit()?;
Ok(())
}();
});The above will always generate the following output for the timestamp related instructions
cargo:rustc-env=VERGEN_BUILD_DATE=2022-12-23
cargo:rustc-env=VERGEN_BUILD_TIMESTAMP=2022-12-23T15:29:20.000000000Z§Example
This feature also recognizes the idempotent flag.
NOTE - SOURCE_DATE_EPOCH takes precedence over the idempotent flag. If you
use both, the output will be based off SOURCE_DATE_EPOCH. This would still be
deterministic.
let build = Build::builder().build();
Emitter::new().idempotent().add_instructions(&build)?.emit()?;The above will always generate the following output for the timestamp related instructions unless you also use quiet, then the warnings will be suppressed.
cargo:rustc-env=VERGEN_BUILD_DATE=VERGEN_IDEMPOTENT_OUTPUT
cargo:rustc-env=VERGEN_BUILD_TIMESTAMP=VERGEN_IDEMPOTENT_OUTPUT
cargo:warning=VERGEN_BUILD_DATE set to default
cargo:warning=VERGEN_BUILD_TIMESTAMP set to default
cargo:rerun-if-changed=build.rs
cargo:rerun-if-env-changed=VERGEN_IDEMPOTENT
cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH