1use std::sync::LazyLock;
4
5#[rustfmt::skip] const GIT_BRANCH: &str = env!("BUILD_GIT_BRANCH");
6#[allow(dead_code)]
7#[rustfmt::skip] const GIT_HASH: &str = env!("BUILD_GIT_HASH");
8#[rustfmt::skip] const GIT_DESCRIBE: &str = env!("BUILD_GIT_DESCRIBE");
9#[rustfmt::skip] const GIT_DATE: &str = env!("BUILD_GIT_DATE");
10#[rustfmt::skip] const BUILD_DEBUG: &str = env!("BUILD_CARGO_DEBUG");
11#[rustfmt::skip] const BUILD_TARGET: &str = env!("BUILD_CARGO_TARGET");
12
13pub fn rustc_version() -> &'static str {
15 static RUSTC_VERSION: LazyLock<String> = LazyLock::new(|| {
16 let meta = rustc_version_runtime::version_meta();
17 format!("{} {:?}", meta.short_version_string, meta.channel)
18 });
19
20 &RUSTC_VERSION
21}
22
23pub fn build_profile() -> &'static str {
25 if BUILD_DEBUG == "true" {
26 "debug"
27 } else {
28 "release"
29 }
30}
31
32#[rustfmt::skip]
34pub fn version_info() -> &'static str {
35 static VERSION_INFO: LazyLock<String> = LazyLock::new(||{
36 let prof = build_profile();
37 let rustc = rustc_version();
38
39 format!(
40"Build: {prof}
41Branch: {GIT_BRANCH} {GIT_DESCRIBE} {GIT_DATE}
42{rustc}"
43 )
44 });
45
46 &VERSION_INFO
47}
48
49pub fn version_info_vec() -> &'static Vec<String> {
51 static VERSION_INFO_VEC: LazyLock<Vec<String>> = LazyLock::new(|| {
52 let prof = build_profile();
53 let rustc = rustc_version();
54 vec![
55 format!("Build: {BUILD_TARGET} {prof}"),
56 format!("Branch: {GIT_BRANCH}"),
57 format!("Version: {GIT_DESCRIBE}"),
58 format!("Last Updated: {GIT_DATE}"),
59 rustc.to_string(),
60 ]
61 });
62
63 &VERSION_INFO_VEC
64}