diff --git a/.github/scripts/ci-setup-i686-unknown-linux-gnu.sh b/.github/scripts/ci-setup-i686-unknown-linux-gnu.sh new file mode 100755 index 0000000000..f051dffaa0 --- /dev/null +++ b/.github/scripts/ci-setup-i686-unknown-linux-gnu.sh @@ -0,0 +1,9 @@ +set -xe + +sudo apt-get update +sudo apt-get install build-essential gcc-multilib -y + +# Necessary libraries for 32bit mmtk build +sudo dpkg --add-architecture i386 +sudo apt-get update +sudo apt-get install zlib1g-dev:i386 diff --git a/.github/scripts/ci-setup-x86_64-unknown-linux-gnu.sh b/.github/scripts/ci-setup-x86_64-unknown-linux-gnu.sh new file mode 100755 index 0000000000..36b3306791 --- /dev/null +++ b/.github/scripts/ci-setup-x86_64-unknown-linux-gnu.sh @@ -0,0 +1,4 @@ +set -xe + +sudo apt-get update +sudo apt-get install build-essential gcc-multilib -y diff --git a/.github/scripts/ci-setup.sh b/.github/scripts/ci-setup.sh deleted file mode 100755 index d4dfc2ef24..0000000000 --- a/.github/scripts/ci-setup.sh +++ /dev/null @@ -1,5 +0,0 @@ -set -xe - -# Necessary libraries for 32bit mmtk build -sudo apt-get update -sudo apt-get install build-essential gcc-multilib -y \ No newline at end of file diff --git a/.github/workflows/pre-review-ci.yml b/.github/workflows/pre-review-ci.yml index 902b6d0083..e1e068ac3e 100644 --- a/.github/workflows/pre-review-ci.yml +++ b/.github/workflows/pre-review-ci.yml @@ -45,7 +45,7 @@ jobs: # Setup Environments - name: Setup Environments - run: ./.github/scripts/ci-setup.sh + run: ./.github/scripts/ci-setup-${{ matrix.target.triple }}.sh # Build - name: Build diff --git a/Cargo.toml b/Cargo.toml index c9ae4747a2..1d6f0e494e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ readme = "README.md" categories = ["memory-management"] keywords = ["gc", "garbage", "collection", "garbage-collection", "allocation"] rust-version = "1.57.0" +build = "build.rs" [lib] name = "mmtk" @@ -43,6 +44,9 @@ strum_macros = "0.24" [dev-dependencies] rand = "0.7.3" +[build-dependencies] +built = { version = "0.5.1", features = ["git2"] } + [features] default = [] diff --git a/build.rs b/build.rs new file mode 100644 index 0000000000..d8f91cb913 --- /dev/null +++ b/build.rs @@ -0,0 +1,3 @@ +fn main() { + built::write_built_file().expect("Failed to acquire build-time information"); +} diff --git a/src/build_info.rs b/src/build_info.rs new file mode 100644 index 0000000000..9f09fc6227 --- /dev/null +++ b/src/build_info.rs @@ -0,0 +1,55 @@ +mod raw { + // This includes a full list of the constants in built.rs generated by the 'built' crate. + // https://docs.rs/built/latest/built/index.html + include!(concat!(env!("OUT_DIR"), "/built.rs")); +} + +/// MMTk crate version such as 0.14.0 +pub const MMTK_PKG_VERSION: &str = raw::PKG_VERSION; + +/// Comma separated features enabled for this build +pub const MMTK_FEATURES: &str = raw::FEATURES_STR; + +lazy_static! { + /// Git version as short commit hash, such as a96e8f9, or a96e8f9, or unknown-git-version if MMTk + /// is not built from a git repo. + pub static ref MMTK_GIT_VERSION: &'static str = &MMTK_GIT_VERSION_STRING; + // Owned string + static ref MMTK_GIT_VERSION_STRING: String = match (raw::GIT_COMMIT_HASH, raw::GIT_DIRTY) { + (Some(hash), Some(dirty)) => format!("{}{}", hash.split_at(7).0, if dirty { "-dirty" } else { "" }), + (Some(hash), None) => format!("{}{}", hash.split_at(7).0, "-?"), + _ => "unknown-git-version".to_string(), + }; + + /// Full build info, including MMTk's name, version, git, and features in the build, + /// such as MMTk 0.14.0 (43e0ce8-dirty, DEFAULT, EXTREME_ASSERTIONS) + pub static ref MMTK_FULL_BUILD_INFO: &'static str = &MMTK_FULL_BUILD_INFO_STRING; + // Owned string + static ref MMTK_FULL_BUILD_INFO_STRING: String = format!("MMTk {} ({}, {})", MMTK_PKG_VERSION, *MMTK_GIT_VERSION, MMTK_FEATURES); +} + +#[cfg(test)] +mod tests { + #[test] + fn test_git_version() { + println!("Git version: {}", *crate::build_info::MMTK_GIT_VERSION); + } + + #[test] + fn test_full_build_version() { + println!( + "Full build version: {}", + *crate::build_info::MMTK_FULL_BUILD_INFO + ); + } + + #[test] + fn test_pkg_version() { + println!("Package version: {}", crate::build_info::MMTK_PKG_VERSION); + } + + #[test] + fn test_features() { + println!("Features: {}", crate::build_info::MMTK_FEATURES); + } +} diff --git a/src/lib.rs b/src/lib.rs index a3ad865601..3f54639923 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -51,6 +51,7 @@ pub use mmtk::MMTK; mod policy; +pub mod build_info; pub mod memory_manager; pub mod plan; pub mod scheduler;