1use std::fmt::Write;
7
8lazy_static::lazy_static! {
9 static ref GIT_VERSION: String = {
10 let mut ver = String::new();
11 match option_env!("VERGEN_GIT_SHA") {
12 Some(v) if v != "VERGEN_IDEMPOTENT_OUTPUT" => {
13 ver += "g";
14 ver += v;
15 if let Some("true") = option_env!("VERGEN_GIT_DIRTY") {
16 ver += "-dirty";
17 }
18 }
19 _ => {}
20 }
21 ver
22 };
23 static ref BUILD_TAG: String = {
24 let mut tag = env!("VERGEN_CARGO_TARGET_TRIPLE").to_string();
25 if cfg!(debug_assertions) {
26 write!(tag, "/debug").unwrap();
27 }
28 tag
29 };
30}
31
32pub fn full_version(semver: &str) -> String {
33 let mut ver = semver.to_string();
34 if !GIT_VERSION.is_empty() {
35 write!(ver, "-{}", &*GIT_VERSION).unwrap();
36 }
37 if !BUILD_TAG.is_empty() {
38 write!(ver, " {}", &*BUILD_TAG).unwrap();
39 }
40 ver
41}
42
43lazy_static::lazy_static! {
44 pub static ref SCX_CARGO_VERSION: &'static str = env!("CARGO_PKG_VERSION");
45 pub static ref SCX_FULL_VERSION: String = full_version(*SCX_CARGO_VERSION);
46}
47
48#[cfg(test)]
49mod tests {
50 #[test]
51 fn test_cargo_ver() {
52 println!("{}", *super::SCX_CARGO_VERSION);
54 }
55
56 #[test]
57 fn test_full_ver() {
58 println!("{}", *super::SCX_FULL_VERSION);
60 }
61}