vergen_lib/
constants.rs

1// Copyright (c) 2022 vergen developers
2//
3// Licensed under the Apache License, Version 2.0
4// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0> or the MIT
5// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
6// option. All files in the project carrying such notice may not be copied,
7// modified, or distributed except according to those terms.
8
9//! Internal Constants
10
11/// The default idempotent output string
12pub const VERGEN_IDEMPOTENT_DEFAULT: &str = "VERGEN_IDEMPOTENT_OUTPUT";
13
14#[cfg(any(
15    feature = "build",
16    feature = "cargo",
17    feature = "git",
18    feature = "rustc",
19    feature = "si"
20))]
21pub use self::features::*;
22
23/// The names used by [`crate::VergenKey`] for each enabled output
24#[cfg(any(
25    feature = "build",
26    feature = "cargo",
27    feature = "git",
28    feature = "rustc",
29    feature = "si"
30))]
31pub mod features {
32    /// The timestamp of the current build
33    #[cfg(feature = "build")]
34    pub const BUILD_TIMESTAMP_NAME: &str = "VERGEN_BUILD_TIMESTAMP";
35    /// The date of the current build
36    #[cfg(feature = "build")]
37    pub const BUILD_DATE_NAME: &str = "VERGEN_BUILD_DATE";
38
39    /// The current branch name
40    #[cfg(feature = "git")]
41    pub const GIT_BRANCH_NAME: &str = "VERGEN_GIT_BRANCH";
42    /// The most recent commit author email address
43    #[cfg(feature = "git")]
44    pub const GIT_COMMIT_AUTHOR_EMAIL: &str = "VERGEN_GIT_COMMIT_AUTHOR_EMAIL";
45    /// The most recent commit author name
46    #[cfg(feature = "git")]
47    pub const GIT_COMMIT_AUTHOR_NAME: &str = "VERGEN_GIT_COMMIT_AUTHOR_NAME";
48    /// The commit count
49    #[cfg(feature = "git")]
50    pub const GIT_COMMIT_COUNT: &str = "VERGEN_GIT_COMMIT_COUNT";
51    /// The most recent commit message
52    #[cfg(feature = "git")]
53    pub const GIT_COMMIT_MESSAGE: &str = "VERGEN_GIT_COMMIT_MESSAGE";
54    /// The most recent commit date
55    #[cfg(feature = "git")]
56    pub const GIT_COMMIT_DATE_NAME: &str = "VERGEN_GIT_COMMIT_DATE";
57    /// The most recent commit timestamp
58    #[cfg(feature = "git")]
59    pub const GIT_COMMIT_TIMESTAMP_NAME: &str = "VERGEN_GIT_COMMIT_TIMESTAMP";
60    /// The output of git describe
61    #[cfg(feature = "git")]
62    pub const GIT_DESCRIBE_NAME: &str = "VERGEN_GIT_DESCRIBE";
63    /// The most recent commit SHA
64    #[cfg(feature = "git")]
65    pub const GIT_SHA_NAME: &str = "VERGEN_GIT_SHA";
66    /// The current dirty status
67    #[cfg(feature = "git")]
68    pub const GIT_DIRTY_NAME: &str = "VERGEN_GIT_DIRTY";
69
70    /// The channel of rustc used for the build (stable, beta, nightly)
71    #[cfg(feature = "rustc")]
72    pub const RUSTC_CHANNEL_NAME: &str = "VERGEN_RUSTC_CHANNEL";
73    /// The host triple of rustc used for the build
74    #[cfg(feature = "rustc")]
75    pub const RUSTC_HOST_TRIPLE_NAME: &str = "VERGEN_RUSTC_HOST_TRIPLE";
76    /// The version of rustc used for the build
77    #[cfg(feature = "rustc")]
78    pub const RUSTC_SEMVER_NAME: &str = "VERGEN_RUSTC_SEMVER";
79    /// The commit hash of rustc used for the build
80    #[cfg(feature = "rustc")]
81    pub const RUSTC_COMMIT_HASH: &str = "VERGEN_RUSTC_COMMIT_HASH";
82    /// The commit date of rustc used for the build
83    #[cfg(feature = "rustc")]
84    pub const RUSTC_COMMIT_DATE: &str = "VERGEN_RUSTC_COMMIT_DATE";
85    /// The LLVM version underlying rustc used for the build (if applicable)
86    #[cfg(feature = "rustc")]
87    pub const RUSTC_LLVM_VERSION: &str = "VERGEN_RUSTC_LLVM_VERSION";
88
89    /// The value of the `DEBUG` environment variable at build time
90    #[cfg(feature = "cargo")]
91    pub const CARGO_DEBUG: &str = "VERGEN_CARGO_DEBUG";
92    /// The current dependency list (potentiall filtered)
93    #[cfg(feature = "cargo")]
94    pub const CARGO_DEPENDENCIES: &str = "VERGEN_CARGO_DEPENDENCIES";
95    /// The value of the `CARGO_FEATURES` environment variable at build time
96    #[cfg(feature = "cargo")]
97    pub const CARGO_FEATURES: &str = "VERGEN_CARGO_FEATURES";
98    /// The value of the `OPT_LEVEL` environment variable at build time
99    #[cfg(feature = "cargo")]
100    pub const CARGO_OPT_LEVEL: &str = "VERGEN_CARGO_OPT_LEVEL";
101    /// The value of the `TARGET_TRIPLE` environment variable at build time
102    #[cfg(feature = "cargo")]
103    pub const CARGO_TARGET_TRIPLE: &str = "VERGEN_CARGO_TARGET_TRIPLE";
104
105    /// The system name
106    #[cfg(feature = "si")]
107    pub const SYSINFO_NAME: &str = "VERGEN_SYSINFO_NAME";
108    /// The OS version
109    #[cfg(feature = "si")]
110    pub const SYSINFO_OS_VERSION: &str = "VERGEN_SYSINFO_OS_VERSION";
111    /// The user that ran the build
112    #[cfg(feature = "si")]
113    pub const SYSINFO_USER: &str = "VERGEN_SYSINFO_USER";
114    /// The total memory on the system used to run the build
115    #[cfg(feature = "si")]
116    pub const SYSINFO_MEMORY: &str = "VERGEN_SYSINFO_TOTAL_MEMORY";
117    /// The CPU vender on the system used to run the build
118    #[cfg(feature = "si")]
119    pub const SYSINFO_CPU_VENDOR: &str = "VERGEN_SYSINFO_CPU_VENDOR";
120    /// The CPU core count on the system use to run the build
121    #[cfg(feature = "si")]
122    pub const SYSINFO_CPU_CORE_COUNT: &str = "VERGEN_SYSINFO_CPU_CORE_COUNT";
123    /// The CPU name on the system use to run the build
124    #[cfg(feature = "si")]
125    pub const SYSINFO_CPU_NAME: &str = "VERGEN_SYSINFO_CPU_NAME";
126    /// The CPU brand on the system use to run the build
127    #[cfg(feature = "si")]
128    pub const SYSINFO_CPU_BRAND: &str = "VERGEN_SYSINFO_CPU_BRAND";
129    /// The CPU frequency on the system use to run the build
130    #[cfg(feature = "si")]
131    pub const SYSINFO_CPU_FREQUENCY: &str = "VERGEN_SYSINFO_CPU_FREQUENCY";
132}
133
134/// An empty list of names to use with [`crate::VergenKey`] when
135/// no features are enabled.
136#[cfg(not(any(
137    feature = "build",
138    feature = "cargo",
139    feature = "git",
140    feature = "rustc",
141    feature = "si"
142)))]
143pub mod features {}
144
145#[cfg(all(
146    test,
147    any(
148        feature = "build",
149        feature = "cargo",
150        feature = "git",
151        feature = "rustc",
152        feature = "si"
153    )
154))]
155mod test {
156    use super::*;
157
158    #[cfg(feature = "build")]
159    #[test]
160    fn build_constants_dont_change() {
161        // Build Constants
162        assert_eq!(BUILD_TIMESTAMP_NAME, "VERGEN_BUILD_TIMESTAMP");
163        assert_eq!(BUILD_DATE_NAME, "VERGEN_BUILD_DATE");
164    }
165
166    #[cfg(feature = "cargo")]
167    #[test]
168    fn cargo_constants_dont_change() {
169        // cargo Constants
170        assert_eq!(CARGO_TARGET_TRIPLE, "VERGEN_CARGO_TARGET_TRIPLE");
171        assert_eq!(CARGO_FEATURES, "VERGEN_CARGO_FEATURES");
172    }
173
174    #[cfg(feature = "git")]
175    #[test]
176    fn git_constants_dont_change() {
177        // git Constants
178        assert_eq!(GIT_BRANCH_NAME, "VERGEN_GIT_BRANCH");
179        assert_eq!(GIT_COMMIT_AUTHOR_EMAIL, "VERGEN_GIT_COMMIT_AUTHOR_EMAIL");
180        assert_eq!(GIT_COMMIT_AUTHOR_NAME, "VERGEN_GIT_COMMIT_AUTHOR_NAME");
181        assert_eq!(GIT_COMMIT_COUNT, "VERGEN_GIT_COMMIT_COUNT");
182        assert_eq!(GIT_COMMIT_MESSAGE, "VERGEN_GIT_COMMIT_MESSAGE");
183        assert_eq!(GIT_COMMIT_DATE_NAME, "VERGEN_GIT_COMMIT_DATE");
184        assert_eq!(GIT_COMMIT_TIMESTAMP_NAME, "VERGEN_GIT_COMMIT_TIMESTAMP");
185        assert_eq!(GIT_DESCRIBE_NAME, "VERGEN_GIT_DESCRIBE");
186        assert_eq!(GIT_SHA_NAME, "VERGEN_GIT_SHA");
187        assert_eq!(GIT_DIRTY_NAME, "VERGEN_GIT_DIRTY");
188    }
189
190    #[cfg(feature = "rustc")]
191    #[test]
192    fn rustc_constants_dont_change() {
193        // rustc Constants
194        assert_eq!(RUSTC_SEMVER_NAME, "VERGEN_RUSTC_SEMVER");
195        assert_eq!(RUSTC_CHANNEL_NAME, "VERGEN_RUSTC_CHANNEL");
196        assert_eq!(RUSTC_HOST_TRIPLE_NAME, "VERGEN_RUSTC_HOST_TRIPLE");
197        assert_eq!(RUSTC_COMMIT_HASH, "VERGEN_RUSTC_COMMIT_HASH");
198        assert_eq!(RUSTC_COMMIT_DATE, "VERGEN_RUSTC_COMMIT_DATE");
199        assert_eq!(RUSTC_LLVM_VERSION, "VERGEN_RUSTC_LLVM_VERSION");
200    }
201
202    #[cfg(feature = "si")]
203    #[test]
204    fn sysinfo_constants_dont_change() {
205        // sysinfo Constants
206        assert_eq!(SYSINFO_NAME, "VERGEN_SYSINFO_NAME");
207        assert_eq!(SYSINFO_OS_VERSION, "VERGEN_SYSINFO_OS_VERSION");
208        assert_eq!(SYSINFO_USER, "VERGEN_SYSINFO_USER");
209        assert_eq!(SYSINFO_MEMORY, "VERGEN_SYSINFO_TOTAL_MEMORY");
210        assert_eq!(SYSINFO_CPU_VENDOR, "VERGEN_SYSINFO_CPU_VENDOR");
211        assert_eq!(SYSINFO_CPU_CORE_COUNT, "VERGEN_SYSINFO_CPU_CORE_COUNT");
212        assert_eq!(SYSINFO_CPU_NAME, "VERGEN_SYSINFO_CPU_NAME");
213        assert_eq!(SYSINFO_CPU_BRAND, "VERGEN_SYSINFO_CPU_BRAND");
214        assert_eq!(SYSINFO_CPU_FREQUENCY, "VERGEN_SYSINFO_CPU_FREQUENCY");
215    }
216}