#![forbid(unsafe_code)]
pub use chrono;
use chrono::{DateTime, NaiveDate, Utc};
use derive_more::Display;
pub use semver;
use semver::Version;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[cfg(feature = "serde")]
mod versioned_string;
#[cfg(feature = "serde")]
pub use versioned_string::VersionedString;
mod display;
pub fn crate_version() -> Version {
Version::parse(env!("CARGO_PKG_VERSION")).unwrap()
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
pub struct BuildInfo {
pub timestamp: DateTime<Utc>,
pub profile: String,
pub optimization_level: OptimizationLevel,
pub crate_info: CrateInfo,
pub target: TargetInfo,
pub compiler: CompilerInfo,
pub version_control: Option<VersionControl>,
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
pub enum OptimizationLevel {
O0,
O1,
O2,
O3,
Os,
Oz,
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
pub struct CrateInfo {
pub name: String,
pub version: Version,
pub authors: Vec<String>,
pub license: Option<String>,
pub enabled_features: Vec<String>,
pub available_features: Vec<String>,
pub dependencies: Vec<CrateInfo>,
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
pub struct TargetInfo {
pub triple: String,
pub family: String,
pub os: String,
pub cpu: CpuInfo,
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
pub struct CpuInfo {
pub arch: String,
pub pointer_width: u64,
pub endianness: Endianness,
pub features: Vec<String>,
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Display, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
pub enum Endianness {
Big,
Little,
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
pub struct CompilerInfo {
pub version: Version,
pub commit_id: Option<String>,
pub commit_date: Option<NaiveDate>,
pub channel: CompilerChannel,
pub host_triple: String,
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Display, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
pub enum CompilerChannel {
Dev,
Nightly,
Beta,
Stable,
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
pub enum VersionControl {
Git(GitInfo),
}
impl VersionControl {
pub fn git(&self) -> Option<&GitInfo> {
match self {
VersionControl::Git(git) => Some(git),
}
}
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
pub struct GitInfo {
pub commit_id: String,
pub commit_short_id: String,
pub commit_timestamp: DateTime<Utc>,
pub dirty: bool,
pub branch: Option<String>,
pub tags: Vec<String>,
}