From e715db8b99643161ae0eda9112ff5e2d01be7316 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Thu, 17 Mar 2022 03:33:29 +0000 Subject: [PATCH] Add minimum supported Rust version (#3082) ## Proposed Changes Set a minimum supported Rust version (MSRV) in the `Cargo.toml` for the Lighthouse binary so that attempts to compile it with an outdated compiler fail immediately with a clear error. To ensure that the codebase builds with the MSRV I've also added a Github actions job that runs `cargo check` using the MSRV extracted from `Cargo.toml`. This will force us to keep it up to date. I opted to use `cargo check` rather than Clippy because Clippy frequently introduces new lints that we adopt, so our MSRV for Clippy is usually the most recent Rust version, while the MSRV for building Lighthouse is older. --- .github/workflows/test-suite.yml | 22 ++++++++++++++++++++++ bors.toml | 3 ++- lighthouse/Cargo.toml | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-suite.yml b/.github/workflows/test-suite.yml index 0b29751106..b19fc1e0b0 100644 --- a/.github/workflows/test-suite.yml +++ b/.github/workflows/test-suite.yml @@ -21,6 +21,18 @@ jobs: steps: - name: Check that the pull request is not targeting the stable branch run: test ${{ github.base_ref }} != "stable" + extract-msrv: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Extract Minimum Supported Rust Version (MSRV) + run: | + metadata=$(cargo metadata --no-deps --format-version 1) + msrv=$(echo $metadata | jq -r '.packages | map(select(.name == "lighthouse")) | .[0].rust_version') + echo "::set-output name=MSRV::$msrv" + id: extract_msrv + outputs: + MSRV: ${{ steps.extract_msrv.outputs.MSRV }} cargo-fmt: name: cargo-fmt runs-on: ubuntu-latest @@ -229,6 +241,16 @@ jobs: run: make lint - name: Certify Cargo.lock freshness run: git diff --exit-code Cargo.lock + check-msrv: + name: check-msrv + runs-on: ubuntu-latest + needs: [cargo-fmt, extract-msrv] + steps: + - uses: actions/checkout@v1 + - name: Install Rust @ MSRV (${{ needs.extract-msrv.outputs.MSRV }}) + run: rustup override set ${{ needs.extract-msrv.outputs.MSRV }} + - name: Run cargo check + run: cargo check --workspace arbitrary-check: name: arbitrary-check runs-on: ubuntu-latest diff --git a/bors.toml b/bors.toml index f63901ef4b..d7d1e98762 100644 --- a/bors.toml +++ b/bors.toml @@ -18,7 +18,8 @@ status = [ "op-pool-tests", "doppelganger-protection-test", "execution-engine-integration-ubuntu", - "cargo-vendor" + "cargo-vendor", + "check-msrv" ] use_squash_merge = true timeout_sec = 10800 diff --git a/lighthouse/Cargo.toml b/lighthouse/Cargo.toml index 7c9809403d..932ef9ae62 100644 --- a/lighthouse/Cargo.toml +++ b/lighthouse/Cargo.toml @@ -4,6 +4,7 @@ version = "2.1.4" authors = ["Sigma Prime "] edition = "2021" autotests = false +rust-version = "1.58" [features] # Writes debugging .ssz files to /tmp during block processing.