Skip to main content

fips_core/
version.rs

1//! Build version information for FIPS binaries.
2
3use std::sync::LazyLock;
4
5/// Package version from Cargo.toml.
6pub const VERSION: &str = env!("CARGO_PKG_VERSION");
7
8/// Short git commit hash (empty if not available).
9const GIT_HASH: &str = env!("FIPS_GIT_HASH");
10
11/// Dirty flag ("-dirty" or empty).
12const GIT_DIRTY: &str = env!("FIPS_GIT_DIRTY");
13
14/// Build target triple.
15const TARGET: &str = env!("FIPS_TARGET");
16
17/// Short version string for `-V`: `0.1.0 (rev abc1234567)`
18#[allow(clippy::const_is_empty)]
19static SHORT_VERSION: LazyLock<String> = LazyLock::new(|| {
20    if GIT_HASH.is_empty() {
21        VERSION.to_string()
22    } else {
23        format!("{VERSION} (rev {GIT_HASH}{GIT_DIRTY})")
24    }
25});
26
27/// Long version string for `--version` with build metadata.
28static LONG_VERSION: LazyLock<String> =
29    LazyLock::new(|| format!("{}\ntarget: {TARGET}", *SHORT_VERSION));
30
31pub fn short_version() -> &'static str {
32    &SHORT_VERSION
33}
34
35pub fn long_version() -> &'static str {
36    &LONG_VERSION
37}