1#![forbid(unsafe_code)]
10
11pub use chrono;
12use chrono::{DateTime, NaiveDate, Utc};
13use derive_more::Display;
14pub use semver;
15use semver::Version;
16#[cfg(feature = "serde")]
17use serde::{Deserialize, Serialize};
18
19#[cfg(feature = "serde")]
20mod versioned_string;
21#[cfg(feature = "serde")]
22pub use versioned_string::VersionedString;
23
24mod display;
25
26pub fn crate_version() -> Version {
28 Version::parse(env!("CARGO_PKG_VERSION")).unwrap()
29}
30
31#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
33#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
34pub struct BuildInfo {
35 pub timestamp: DateTime<Utc>,
37
38 pub profile: String,
40
41 pub optimization_level: OptimizationLevel,
43
44 pub crate_info: CrateInfo,
46
47 pub target: TargetInfo,
49
50 pub compiler: CompilerInfo,
52
53 pub version_control: Option<VersionControl>,
55}
56
57#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
59#[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
60pub enum OptimizationLevel {
61 O0,
62 O1,
63 O2,
64 O3,
65 Os,
66 Oz,
67}
68
69#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
71#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
72pub struct CrateInfo {
73 pub name: String,
75
76 pub version: Version,
78
79 pub authors: Vec<String>,
81
82 pub license: Option<String>,
84
85 pub enabled_features: Vec<String>,
87
88 pub available_features: Vec<String>,
90
91 pub dependencies: Vec<CrateInfo>,
94}
95
96#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
97#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
98pub struct TargetInfo {
99 pub triple: String,
101 pub family: String,
103 pub os: String,
105 pub cpu: CpuInfo,
107}
108
109#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
110#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
111pub struct CpuInfo {
112 pub arch: String,
114 pub pointer_width: u64,
116 pub endianness: Endianness,
118 pub features: Vec<String>,
120}
121
122#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
124#[derive(Display, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
125pub enum Endianness {
126 Big,
127 Little,
128}
129
130#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
132#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
133pub struct CompilerInfo {
134 pub version: Version,
136
137 pub commit_id: Option<String>,
139
140 pub commit_date: Option<NaiveDate>,
142
143 pub channel: CompilerChannel,
145
146 pub host_triple: String,
148}
149
150#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
152#[derive(Display, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
153pub enum CompilerChannel {
154 Dev,
155 Nightly,
156 Beta,
157 Stable,
158}
159
160#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
162#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
163pub enum VersionControl {
164 Git(GitInfo),
165}
166
167impl VersionControl {
168 pub fn git(&self) -> Option<&GitInfo> {
169 match self {
170 VersionControl::Git(git) => Some(git),
171 }
173 }
174}
175
176#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
183#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
184pub struct GitInfo {
185 pub commit_id: String,
187
188 pub commit_short_id: String,
193
194 pub commit_timestamp: DateTime<Utc>,
196
197 pub dirty: bool,
199
200 pub branch: Option<String>,
202
203 pub tags: Vec<String>,
205}