Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add build info #638

Merged
merged 8 commits into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/scripts/ci-setup-i686-unknown-linux-gnu.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions .github/scripts/ci-setup-x86_64-unknown-linux-gnu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set -xe

sudo apt-get update
sudo apt-get install build-essential gcc-multilib -y
5 changes: 0 additions & 5 deletions .github/scripts/ci-setup.sh

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/pre-review-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 = []

Expand Down
3 changes: 3 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
built::write_built_file().expect("Failed to acquire build-time information");
}
55 changes: 55 additions & 0 deletions src/build_info.rs
Original file line number Diff line number Diff line change
@@ -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);
}
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub use mmtk::MMTK;

mod policy;

pub mod build_info;
pub mod memory_manager;
pub mod plan;
pub mod scheduler;
Expand Down