#[cfg(feature = "build-info")]
pub mod built_info {
include!(concat!(env!("OUT_DIR"), "/built.rs"));
}
#[cfg(feature = "build-info")]
pub fn version_info() -> String {
format!(
"{} {} ({})\nBuilt: {}\nCommit: {}\nRustc: {}",
built_info::PKG_NAME,
built_info::PKG_VERSION,
built_info::TARGET,
built_info::BUILT_TIME_UTC,
built_info::GIT_COMMIT_HASH.unwrap_or("unknown"),
built_info::RUSTC_VERSION
)
}
#[cfg(feature = "build-info")]
pub fn version_short() -> &'static str {
built_info::PKG_VERSION
}
#[cfg(feature = "build-info")]
pub fn package_name() -> &'static str {
built_info::PKG_NAME
}
#[cfg(feature = "build-info")]
pub fn git_commit() -> Option<&'static str> {
built_info::GIT_COMMIT_HASH
}
#[cfg(feature = "build-info")]
pub fn build_time() -> &'static str {
built_info::BUILT_TIME_UTC
}
#[cfg(feature = "build-info")]
pub fn target() -> &'static str {
built_info::TARGET
}
#[cfg(not(feature = "build-info"))]
pub fn version_info() -> String {
format!("{} {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"))
}
#[cfg(not(feature = "build-info"))]
pub fn version_short() -> &'static str {
env!("CARGO_PKG_VERSION")
}
#[cfg(not(feature = "build-info"))]
pub fn package_name() -> &'static str {
env!("CARGO_PKG_NAME")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_version_info_not_empty() {
let info = version_info();
assert!(!info.is_empty());
}
#[test]
fn test_version_short() {
let version = version_short();
assert!(!version.is_empty());
}
#[test]
fn test_package_name() {
let name = package_name();
assert_eq!(name, "sen");
}
}