Build

Struct Build 

Source
pub struct Build { /* private fields */ }
Available on crate feature build only.
Expand description

The VERGEN_BUILD_* configuration features

VariableSample
VERGEN_BUILD_DATE2021-02-25
VERGEN_BUILD_TIMESTAMP2021-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

Implementations§

Source§

impl Build

Source

pub fn builder() -> BuildBuilder

Create an instance of Build using the builder syntax

Source§

impl Build

Source

pub fn all_build() -> Build

Enable all of the VERGEN_BUILD_* options

§Errors

The build function can error

Trait Implementations§

Source§

impl Add for Build

Source§

fn add_map_entries( &self, idempotent: bool, cargo_rustc_env: &mut BTreeMap<VergenKey, String>, _cargo_rerun_if_changed: &mut Vec<String>, cargo_warning: &mut Vec<String>, ) -> Result<(), Error>

Try to add instructions entries to the various given arguments. Read more
Source§

fn add_default_entries( &self, config: &DefaultConfig, cargo_rustc_env_map: &mut BTreeMap<VergenKey, String>, _cargo_rerun_if_changed: &mut Vec<String>, cargo_warning: &mut Vec<String>, ) -> Result<(), Error>

Based on the given configuration, emit either default idempotent output or generate a failue. Read more
Source§

impl Clone for Build

Source§

fn clone(&self) -> Build

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Build

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Build

Source§

fn eq(&self, other: &Build) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Build

Source§

impl StructuralPartialEq for Build

Auto Trait Implementations§

§

impl Freeze for Build

§

impl RefUnwindSafe for Build

§

impl Send for Build

§

impl Sync for Build

§

impl Unpin for Build

§

impl UnwindSafe for Build

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,