mmtk/
build_info.rs

1//! Some information for the current MMTk build.
2
3mod raw {
4    // This includes a full list of the constants in built.rs generated by the 'built' crate.
5    // https://docs.rs/built/latest/built/index.html
6    include!(concat!(env!("OUT_DIR"), "/built.rs"));
7}
8
9/// MMTk crate version such as 0.14.0
10pub use raw::PKG_VERSION as MMTK_PKG_VERSION;
11
12/// Comma separated features enabled for this build
13pub use raw::FEATURES_STR as MMTK_FEATURES;
14
15lazy_static! {
16    /// Git version as short commit hash, such as a96e8f9, or a96e8f9-dirty, or unknown-git-version if MMTk
17    /// is not built from a git repo.
18    pub static ref MMTK_GIT_VERSION: &'static str = &MMTK_GIT_VERSION_STRING;
19    // Owned string
20    static ref MMTK_GIT_VERSION_STRING: String = match (raw::GIT_COMMIT_HASH, raw::GIT_DIRTY) {
21        (Some(hash), Some(dirty)) => format!("{}{}", hash.split_at(7).0, if dirty { "-dirty" } else { "" }),
22        (Some(hash), None) => format!("{}{}", hash.split_at(7).0, "-?"),
23        _ => "unknown-git-version".to_string(),
24    };
25
26    /// Full build info, including MMTk's name, version, git, and features in the build,
27    /// such as MMTk 0.14.0 (43e0ce8-dirty, DEFAULT, EXTREME_ASSERTIONS)
28    pub static ref MMTK_FULL_BUILD_INFO: &'static str = &MMTK_FULL_BUILD_INFO_STRING;
29    // Owned string
30    static ref MMTK_FULL_BUILD_INFO_STRING: String = format!("MMTk {} ({}, {})", MMTK_PKG_VERSION, *MMTK_GIT_VERSION, MMTK_FEATURES);
31}
32
33#[cfg(test)]
34mod tests {
35    #[test]
36    fn test_git_version() {
37        println!("Git version: {}", *crate::build_info::MMTK_GIT_VERSION);
38    }
39
40    #[test]
41    fn test_full_build_version() {
42        println!(
43            "Full build version: {}",
44            *crate::build_info::MMTK_FULL_BUILD_INFO
45        );
46    }
47
48    #[test]
49    fn test_pkg_version() {
50        println!("Package version: {}", crate::build_info::MMTK_PKG_VERSION);
51    }
52
53    #[test]
54    fn test_features() {
55        println!("Features: {}", crate::build_info::MMTK_FEATURES);
56    }
57}