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, Result, vergen}; fn main() { let mut flags = ConstantsFlags::all(); flags.toggle(ConstantsFlags::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 |
Functions
vergen |
Create a |
Type Definitions
Result |
Convenient wrapper around |