Skip to content

Commit 4904004

Browse files
authored
Add build info (#638)
This PR adds build info to mmtk-core, including mmtk-core version, git hash, and features. `built` is used to collect those information. This closes #634. * use Rust build script to invoke `built`. * add a public `mmtk::build_info` module. * CI invokes setup scripts based on the architecture triple.
1 parent a96e8f9 commit 4904004

8 files changed

+77
-6
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
set -xe
2+
3+
sudo apt-get update
4+
sudo apt-get install build-essential gcc-multilib -y
5+
6+
# Necessary libraries for 32bit mmtk build
7+
sudo dpkg --add-architecture i386
8+
sudo apt-get update
9+
sudo apt-get install zlib1g-dev:i386
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
set -xe
2+
3+
sudo apt-get update
4+
sudo apt-get install build-essential gcc-multilib -y

.github/scripts/ci-setup.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

.github/workflows/pre-review-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545

4646
# Setup Environments
4747
- name: Setup Environments
48-
run: ./.github/scripts/ci-setup.sh
48+
run: ./.github/scripts/ci-setup-${{ matrix.target.triple }}.sh
4949

5050
# Build
5151
- name: Build

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ readme = "README.md"
1111
categories = ["memory-management"]
1212
keywords = ["gc", "garbage", "collection", "garbage-collection", "allocation"]
1313
rust-version = "1.57.0"
14+
build = "build.rs"
1415

1516
[lib]
1617
name = "mmtk"
@@ -43,6 +44,9 @@ strum_macros = "0.24"
4344
[dev-dependencies]
4445
rand = "0.7.3"
4546

47+
[build-dependencies]
48+
built = { version = "0.5.1", features = ["git2"] }
49+
4650
[features]
4751
default = []
4852

build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
built::write_built_file().expect("Failed to acquire build-time information");
3+
}

src/build_info.rs

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

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pub use mmtk::MMTK;
5151

5252
mod policy;
5353

54+
pub mod build_info;
5455
pub mod memory_manager;
5556
pub mod plan;
5657
pub mod scheduler;

0 commit comments

Comments
 (0)