vergen

Struct Emitter

Source
pub struct Emitter { /* private fields */ }
Expand description

The Emitter will emit cargo instructions (i.e. cargo:rustc-env=NAME=VALUE) base on the configuration you enable.

Implementations§

Source§

impl Emitter

Source

pub fn new() -> Emitter

Instantiate the builder to configure the cargo instruction emits

Source

pub fn idempotent(&mut self) -> &mut Emitter

Enable the idempotent feature

NOTE - This feature can also be enabled via the VERGEN_IDEMPOTENT environment variable.

When this feature is enabled, certain vergen output (i.e. timestamps, sysinfo) will be set to an idempotent default. This will allow systems that depend on deterministic builds to override user requested vergen impurities. This will mainly allow for package maintainers to build packages that depend on vergen in a deterministic manner.

See this issue for more details

VariableSample
VERGEN_BUILD_DATEVERGEN_IDEMPOTENT_OUTPUT
VERGEN_BUILD_TIMESTAMPVERGEN_IDEMPOTENT_OUTPUT
§Example
Emitter::new().idempotent().emit()?;
// or
// set::env("VERGEN_IDEMPOTENT", "true");
Emitter::new().emit()?;
Source

pub fn fail_on_error(&mut self) -> &mut Emitter

Enable the fail_on_error feature

By default vergen will emit the instructions you requested. If for some reason those instructions cannot be generated correctly, placeholder values will be used instead. vergen will also emit cargo:warning instructions notifying you this has happened.

For example, if you configure vergen to emit VERGEN_GIT_* instructions and you run a build from a source tarball with no .git directory, the instructions will be populated with placeholder values, rather than information gleaned through git.

You can turn off this behavior by enabling fail_on_error.

§Example
Emitter::new().fail_on_error().emit()?;
Source

pub fn quiet(&mut self) -> &mut Emitter

Enable the quiet feature

Suppress the emission of the cargo:warning instructions.

§Example
Emitter::new().quiet().emit()?;
Source

pub fn custom_build_rs(&mut self, path: &'static str) -> &mut Emitter

Set a custom build.rs path if you are using a non-standard path

By default vergen will use build.rs as the build path for the cargo:rerun-if-changed emit. You can specify a custom build.rs path here if you have changed this default

§Example
Emitter::new().custom_build_rs("my/custom/build.rs").emit()?;
Source

pub fn add_instructions(&mut self, gen: &dyn Add) -> Result<&mut Emitter, Error>

Add a set of instructions to the emitter output

§Errors
Source

pub fn add_custom_instructions<K, V>( &mut self, gen: &impl AddCustom<K, V>, ) -> Result<&mut Emitter, Error>
where K: Into<String> + Ord, V: Into<String>,

Add a set of custom instructions to the emitter output

§Errors

Errors may be generated if fail_on_error has been configured.

Source

pub fn emit(&self) -> Result<(), Error>

Emit cargo instructions from your build script

§Errors
§Example
let emitter = Emitter::default().emit()?;
§Sample Output

NOTE - You won’t see this output unless you invoke cargo with the -vv flag. The instruction output is not displayed by default.

cargo:rustc-env=VERGEN_BUILD_DATE=2023-01-04
cargo:rustc-env=VERGEN_BUILD_TIMESTAMP=2023-01-04T15:38:11.097507114Z
cargo:rustc-env=VERGEN_CARGO_DEBUG=true
cargo:rustc-env=VERGEN_CARGO_FEATURES=build,git
cargo:rustc-env=VERGEN_CARGO_OPT_LEVEL=1
cargo:rustc-env=VERGEN_CARGO_TARGET_TRIPLE=x86_64-unknown-linux-gnu
cargo:rustc-env=VERGEN_GIT_BRANCH=feature/version8
cargo:rustc-env=VERGEN_GIT_COMMIT_AUTHOR_EMAIL=your@email.com
cargo:rustc-env=VERGEN_GIT_COMMIT_AUTHOR_NAME=Yoda
cargo:rustc-env=VERGEN_GIT_COMMIT_COUNT=476
cargo:rustc-env=VERGEN_GIT_COMMIT_DATE=2023-01-03
cargo:rustc-env=VERGEN_GIT_COMMIT_MESSAGE=The best message
cargo:rustc-env=VERGEN_GIT_COMMIT_TIMESTAMP=2023-01-03T14:08:12.000000000-05:00
cargo:rustc-env=VERGEN_GIT_DESCRIBE=7.4.4-103-g53ae8a6
cargo:rustc-env=VERGEN_GIT_SHA=53ae8a69ab7917a2909af40f2e5d015f5b29ae28
cargo:rustc-env=VERGEN_RUSTC_CHANNEL=nightly
cargo:rustc-env=VERGEN_RUSTC_COMMIT_DATE=2023-01-03
cargo:rustc-env=VERGEN_RUSTC_COMMIT_HASH=c7572670a1302f5c7e245d069200e22da9df0316
cargo:rustc-env=VERGEN_RUSTC_HOST_TRIPLE=x86_64-unknown-linux-gnu
cargo:rustc-env=VERGEN_RUSTC_LLVM_VERSION=15.0
cargo:rustc-env=VERGEN_RUSTC_SEMVER=1.68.0-nightly
cargo:rustc-env=VERGEN_SYSINFO_NAME=Arch Linux
cargo:rustc-env=VERGEN_SYSINFO_OS_VERSION=Linux  Arch Linux
cargo:rustc-env=VERGEN_SYSINFO_USER=jozias
cargo:rustc-env=VERGEN_SYSINFO_TOTAL_MEMORY=31 GiB
cargo:rustc-env=VERGEN_SYSINFO_CPU_VENDOR=AuthenticAMD
cargo:rustc-env=VERGEN_SYSINFO_CPU_CORE_COUNT=8
cargo:rustc-env=VERGEN_SYSINFO_CPU_NAME=cpu0,cpu1,cpu2,cpu3,cpu4,cpu5,cpu6,cpu7
cargo:rustc-env=VERGEN_SYSINFO_CPU_BRAND=AMD Ryzen Threadripper 1900X 8-Core Processor
cargo:rustc-env=VERGEN_SYSINFO_CPU_FREQUENCY=3792
cargo:rerun-if-changed=.git/HEAD
cargo:rerun-if-changed=.git/refs/heads/feature/version8
cargo:rerun-if-changed=build.rs
cargo:rerun-if-env-changed=VERGEN_IDEMPOTENT
cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH
Source

pub fn emit_and_set(&self) -> Result<(), Error>

Available on crate feature emit_and_set only.

Emit cargo instructions from your build script and set environment variables for use in build.rs

§Errors
§Example
Emitter::new().emit_and_set()?;

Trait Implementations§

Source§

impl Clone for Emitter

Source§

fn clone(&self) -> Emitter

Returns a copy 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 Emitter

Source§

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

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

impl Default for Emitter

Source§

fn default() -> Emitter

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Emitter

Source§

fn eq(&self, other: &Emitter) -> 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 StructuralPartialEq for Emitter

Auto Trait Implementations§

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize = _

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.