Skip to content

Commit 3026ad8

Browse files
authored
Minimal supported rust version (#567)
Add MSRV to the manifest file and test the MSRV in CI workflows using a matrix
1 parent cacded4 commit 3026ad8

File tree

12 files changed

+95
-53
lines changed

12 files changed

+95
-53
lines changed

.github/scripts/ci-build.sh

+2-5
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ for_all_features "cargo build"
1111
# Build release
1212
for_all_features "cargo build --release"
1313

14-
# For x86_64-linux, also see if we can build for i686
14+
# target-specific features
1515
if [[ $arch == "x86_64" && $os == "linux" ]]; then
16-
cargo build --target i686-unknown-linux-gnu
17-
for_all_features "cargo build --target i686-unknown-linux-gnu"
18-
for_all_features "cargo build --release --target i686-unknown-linux-gnu"
1916
cargo build --features perf_counter
20-
fi
17+
fi

.github/scripts/ci-style.sh

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@ for_all_features "cargo clippy --tests"
1313
# check for dummyvm
1414
cargo clippy --manifest-path=vmbindings/dummyvm/Cargo.toml
1515

16-
# For x86_64-linux, also check for i686
16+
# target-specific features
1717
if [[ $arch == "x86_64" && $os == "linux" ]]; then
18-
for_all_features "cargo clippy --target i686-unknown-linux-gnu"
19-
for_all_features "cargo clippy --release --target i686-unknown-linux-gnu"
2018
cargo clippy --features perf_counter
2119
cargo clippy --release --features perf_counter
2220
cargo clippy --tests --features perf_counter
23-
fi
21+
fi
2422

2523
# check format
2624
cargo fmt -- --check

.github/scripts/ci-test.sh

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ export RUST_BACKTRACE=1
44

55
for_all_features "cargo test"
66

7-
# For x86_64-linux, also check for i686
7+
# target-specific features
88
if [[ $arch == "x86_64" && $os == "linux" ]]; then
9-
for_all_features "cargo test --target i686-unknown-linux-gnu"
109
cargo test --features perf_counter
1110
fi
1211

.github/workflows/cargo-msrv.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Minimal Supported Rust Version
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
8+
jobs:
9+
msrv:
10+
runs-on: ubuntu-18.04
11+
steps:
12+
- uses: actions/checkout@v2
13+
- name: Install Rust toolchain
14+
uses: actions-rs/toolchain@v1
15+
with:
16+
toolchain: stable
17+
override: true
18+
- name: Install cargo-msrv
19+
run: cargo install cargo-msrv
20+
# Verify the MSRV defined in Cargo.toml
21+
- name: Verify MSRV
22+
run: cargo msrv verify
23+
# If the previous step fails, find MSRV
24+
- name: Find MSRV
25+
if: failure()
26+
run: cargo msrv

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

+28-4
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,40 @@ on:
66
- master
77

88
jobs:
9+
# Setup dynamic test matrix
10+
setup-test-matrix:
11+
runs-on: ubuntu-latest
12+
outputs:
13+
rust: ${{ steps.rust.outputs.array }}
14+
steps:
15+
- uses: actions/checkout@v2
16+
# Get rust version
17+
- id: rust
18+
run: |
19+
export MSRV=`cargo read-manifest | python -c 'import json,sys; print(json.load(sys.stdin)["rust_version"])'`
20+
export TEST=`cat rust-toolchain`
21+
echo "::set-output name=array::[\"$MSRV\", \"$TEST\"]"
22+
923
pre-code-review-checks:
10-
runs-on: ubuntu-18.04
11-
timeout-minutes: 30
24+
needs: setup-test-matrix
25+
strategy:
26+
fail-fast: false
27+
matrix:
28+
target:
29+
- { os: ubuntu-18.04, triple: x86_64-unknown-linux-gnu }
30+
- { os: ubuntu-18.04, triple: i686-unknown-linux-gnu }
31+
rust: ${{ fromJson(needs.setup-test-matrix.outputs.rust )}}
32+
33+
name: ${{ matrix.target.triple }} / ${{ matrix.rust }}
34+
runs-on: ${{ matrix.target.os }}
35+
1236
steps:
1337
- uses: actions/checkout@v2
14-
- name: Install latest nightly
38+
- name: Install Rust
1539
uses: actions-rs/toolchain@v1
1640
with:
41+
toolchain: ${{ matrix.rust }}-${{ matrix.target.triple }}
1742
components: rustfmt, clippy
18-
target: i686-unknown-linux-gnu
1943
# This overwrites the default toolchain with the toolchain specified above.
2044
override: true
2145

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ repository = "https://github.com/mmtk/mmtk-core"
1010
readme = "README.md"
1111
categories = ["memory-management"]
1212
keywords = ["gc", "garbage", "collection", "garbage-collection", "allocation"]
13+
rust-version = "1.57.0"
1314

1415
[lib]
1516
name = "mmtk"

README.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,9 @@ We maintain an up to date list of the prerequisite for building MMTk and its bin
2020

2121
## Build
2222

23-
MMTk can build with a stable Rust toolchain. However,
24-
as the Rust language and its libraries (crates) are frequently evolving, we recommend using the toolchain specified in the [`rust-toolchain`](rust-toolchain) file.
23+
MMTk can build with a stable Rust toolchain. The minimal supported Rust version is 1.57.0, and MMTk is tested with 1.59.0.
2524

2625
```console
27-
$ export RUSTUP_TOOLCHAIN=`cat rust-toolchain`
28-
2926
$ cargo build
3027
```
3128

examples/build.py

+16-25
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ def exec_and_redirect(args, env=None):
3939
if p.returncode != 0:
4040
exit(p.returncode)
4141

42+
# Get the active toolchain, something like this: stable-x86_64-unknown-linux-gnu
43+
active_toolchain = str(subprocess.check_output(["rustup", "show", "active-toolchain"]).decode('utf-8')).split(' ')[0]
44+
print("Active rust toolchain: " + active_toolchain)
45+
if "x86_64" in active_toolchain:
46+
m32 = False
47+
elif "i686" in active_toolchain:
48+
m32 = True
49+
else:
50+
print("Unknown toolchain: " + active_toolchain)
51+
sys.exit(1)
4252

4353
system = platform.system()
4454
assert system == "Darwin" or system == "Linux"
@@ -71,40 +81,21 @@ def exec_and_redirect(args, env=None):
7181
shutil.copyfile("{}/target/release/libmmtk_dummyvm{}".format(vmbinding, SUFFIX),
7282
"./libmmtk{}".format(SUFFIX))
7383

74-
if system == "Linux":
75-
exec_and_redirect(cmd + ["--target=i686-unknown-linux-gnu"])
76-
exec_and_redirect(
77-
cmd + ["--release", "--target=i686-unknown-linux-gnu"])
78-
shutil.copyfile(
79-
"{}/target/i686-unknown-linux-gnu/release/libmmtk_dummyvm{}".format(vmbinding, SUFFIX),
80-
"./libmmtk_32{}".format(SUFFIX))
81-
82-
exec_and_redirect([
84+
cmd = [
8385
"clang",
8486
"-lmmtk",
8587
"-L.",
8688
"-I{}/api".format(vmbinding),
8789
"-O3",
8890
"-o",
8991
"test_mmtk",
90-
"./examples/main.c"])
91-
92-
if system == "Linux":
93-
exec_and_redirect([
94-
"clang",
95-
"-lmmtk_32",
96-
"-L.",
97-
"-I{}/api".format(vmbinding),
98-
"-O3", "-m32",
99-
"-o",
100-
"test_mmtk_32",
101-
"./examples/main.c"])
92+
]
93+
if m32:
94+
cmd.append("-m32")
95+
cmd.append("./examples/main.c")
96+
exec_and_redirect(cmd)
10297

10398
for plan in PLANS:
10499
exec_and_redirect(["./test_mmtk"], env={LIBRARY_PATH: ".", "MMTK_PLAN": plan})
105-
if system == "Linux":
106-
exec_and_redirect(["./test_mmtk_32"], env={LIBRARY_PATH: ".", "MMTK_PLAN": plan})
107100

108101
os.remove("./test_mmtk")
109-
if system == "Linux":
110-
os.remove("./test_mmtk_32")

rust-toolchain

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
stable
1+
1.59.0

src/util/metadata/side_metadata/helpers.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ pub(crate) fn ensure_munmap_contiguos_metadata_space(
4747
spec: &SideMetadataSpec,
4848
) -> usize {
4949
// nearest page-aligned starting address
50-
let mmap_start = address_to_meta_address(spec, start).align_down(BYTES_IN_PAGE);
50+
let metadata_start = address_to_meta_address(spec, start);
51+
let mmap_start = metadata_start.align_down(BYTES_IN_PAGE);
5152
// nearest page-aligned ending address
52-
let mmap_size =
53-
address_to_meta_address(spec, start + size).align_up(BYTES_IN_PAGE) - mmap_start;
53+
let metadata_size = (size + ((1 << addr_rshift(spec)) - 1)) >> addr_rshift(spec);
54+
let mmap_size = (metadata_start + metadata_size).align_up(BYTES_IN_PAGE) - mmap_start;
5455
if mmap_size > 0 {
5556
ensure_munmap_metadata(mmap_start, mmap_size);
5657
}
@@ -70,10 +71,11 @@ pub(crate) fn try_mmap_contiguous_metadata_space(
7071
debug_assert!(size % BYTES_IN_PAGE == 0);
7172

7273
// nearest page-aligned starting address
73-
let mmap_start = address_to_meta_address(spec, start).align_down(BYTES_IN_PAGE);
74+
let metadata_start = address_to_meta_address(spec, start);
75+
let mmap_start = metadata_start.align_down(BYTES_IN_PAGE);
7476
// nearest page-aligned ending address
75-
let mmap_size =
76-
address_to_meta_address(spec, start + size).align_up(BYTES_IN_PAGE) - mmap_start;
77+
let metadata_size = (size + ((1 << addr_rshift(spec)) - 1)) >> addr_rshift(spec);
78+
let mmap_size = (metadata_start + metadata_size).align_up(BYTES_IN_PAGE) - mmap_start;
7779
if mmap_size > 0 {
7880
if !no_reserve {
7981
MMAPPER.ensure_mapped(mmap_start, mmap_size >> LOG_BYTES_IN_PAGE)

vmbindings/dummyvm/src/object_model.rs

+3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ pub struct VMObjectModel {}
99

1010
// This is intentionally set to a non-zero value to see if it breaks.
1111
// Change this if you want to test other values.
12+
#[cfg(target_pointer_width = "64")]
1213
pub const OBJECT_REF_OFFSET: usize = 6;
14+
#[cfg(target_pointer_width = "32")]
15+
pub const OBJECT_REF_OFFSET: usize = 2;
1316

1417
impl ObjectModel<DummyVM> for VMObjectModel {
1518
const GLOBAL_LOG_BIT_SPEC: VMGlobalLogBitSpec = VMGlobalLogBitSpec::in_header(0);

vmbindings/dummyvm/src/tests/handle_mmap_oom.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@ use mmtk::util::opaque_pointer::*;
33
use mmtk::util::memory;
44
use crate::DummyVM;
55

6+
#[cfg(target_pointer_width = "32")]
7+
const LARGE_SIZE: usize = 4_294_967_295;
8+
#[cfg(target_pointer_width = "64")]
9+
const LARGE_SIZE: usize = 1_000_000_000_000;
10+
611
#[test]
712
pub fn test_handle_mmap_oom() {
813
let panic_res = std::panic::catch_unwind(move || {
914
let start = unsafe { Address::from_usize(0x100_0000 )};
10-
let one_terabyte = 1000000000000;
1115
// mmap 1 terabyte memory - we expect this will fail due to out of memory.
1216
// If that's not the case, increase the size we mmap.
13-
let mmap_res = memory::dzmmap_noreplace(start, one_terabyte);
17+
let mmap_res = memory::dzmmap_noreplace(start, LARGE_SIZE);
1418

1519
memory::handle_mmap_error::<DummyVM>(mmap_res.err().unwrap(), VMThread::UNINITIALIZED);
1620
});

0 commit comments

Comments
 (0)