#[cfg(feature = "version")]
fn main() {
use std::env;
vergen::EmitBuilder::builder()
.git_describe(false, true, None)
.git_dirty(true)
.git_sha(false)
.build_timestamp()
.cargo_features()
.cargo_target_triple()
.emit_and_set()
.unwrap();
let sha = env::var("VERGEN_GIT_SHA").unwrap();
let sha_short = &sha[..7];
let is_dev = {
let is_dirty = env::var("VERGEN_GIT_DIRTY").unwrap() == "true";
let not_on_tag =
env::var("VERGEN_GIT_DESCRIBE").unwrap().ends_with(&format!("-g{sha_short}"));
is_dirty || not_on_tag
};
let version_suffix = if is_dev { "-dev" } else { "" };
let version = env::var("CARGO_PKG_VERSION").unwrap();
let version_suffixed = format!("{version}{version_suffix}");
let timestamp = env::var("VERGEN_BUILD_TIMESTAMP").unwrap();
let short_version = format!("{version_suffixed} ({sha_short} {timestamp})");
println!("cargo:rustc-env=SHORT_VERSION={short_version}");
let out_dir = env::var("OUT_DIR").unwrap();
let profile = out_dir.rsplit(std::path::MAIN_SEPARATOR).nth(3).unwrap();
let mut cargo_features = env::var("VERGEN_CARGO_FEATURES").unwrap();
let ignore = ["clap", "version", "serde"];
for feature in ignore {
cargo_features = cargo_features
.replace(&format!(",{feature}"), "")
.replace(&format!("{feature},"), "")
.replace(feature, "");
}
let long_version = format!(
"Version: {version}\n\
Commit SHA: {sha}\n\
Build Timestamp: {timestamp}\n\
Build Features: {cargo_features}\n\
Build Profile: {profile}",
);
assert_eq!(long_version.lines().count(), 5); for (i, line) in long_version.lines().enumerate() {
println!("cargo:rustc-env=LONG_VERSION{i}={line}");
}
}
#[cfg(not(feature = "version"))]
fn main() {}