Crate vergen[][src]

Defines the vergen function.

vergen, when used in conjunction with the Build Scripts support in cargo, generates a file in OUT_DIR (defined by cargo) with up to 7 build time constants. This file can then be use with include! to pull the constants into your source for use.

Example Cargo.toml

[package]
#..
build = "build.rs"

[dependencies]
#..

[build-dependencies]
vergen = "1"

Example build.rs

extern crate vergen;

use vergen::{ConstantsFlags, COMPILE_TIME, Result, vergen};

fn main() {
    let mut flags = ConstantsFlags::all();
    flags.toggle(COMPILE_TIME);
    vergen(flags).expect("Unable to generate constants!");
}

Example version.rs (All Flags Enabled)

/// Compile Time (UTC)
const COMPILE_TIME: &str = "2018-08-09T15:15:57.282334589+00:00";

/// Compile Time - Short (UTC)
const COMPILE_TIME_SHORT: &str = "2018-08-09";

/// Commit SHA
const SHA: &str = "75b390dc6c05a6a4aa2791cc7b3934591803bc22";

/// Commit SHA - Short
const SHA_SHORT: &str = "75b390d";

/// Commit Date
const COMMIT_DATE: &str = "'2018-08-08'";

/// Target Triple
const TARGET_TRIPLE: &str = "x86_64-unknown-linux-gnu";

/// Semver
const SEMVER: &str = "v0.1.0-pre.0";

/// Semver (Lightweight)
const SEMVER_LIGHTWEIGHT: &str = "v0.1.0-pre.0";

Include the constants in your code

This example is not tested
include!(concat!(env!("OUT_DIR"), "/version.rs"));

format!("{} {} blah {}", COMMIT_TIME, SHA, SEMVER)

Structs

ConstantsFlags

Constants Flags

Constants

COMMIT_DATE

Generate the commit date constant.

COMPILE_TIME

Generate the compile time constant.

COMPILE_TIME_SHORT

Generate the compile date constant.

SEMVER

Generate the semver constant.

SEMVER_LIGHTWEIGHT

Generate the semver constant, including lightweight tags.

SHA

Generate the SHA constant.

SHA_SHORT

Generate the short SHA constant.

TARGET_TRIPLE

Generate the target triple constant.

Functions

vergen

Create a version.rs file in OUT_DIR, and write up to 7 constants into it.

Type Definitions

Result

Convenient wrapper around std::Result.