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.
This commit is contained in:
Michael Sproul 2022-03-17 03:33:29 +00:00
parent 98f74041a0
commit e715db8b99
3 changed files with 25 additions and 1 deletions

View File

@ -21,6 +21,18 @@ jobs:
steps: steps:
- name: Check that the pull request is not targeting the stable branch - name: Check that the pull request is not targeting the stable branch
run: test ${{ github.base_ref }} != "stable" 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: cargo-fmt:
name: cargo-fmt name: cargo-fmt
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -229,6 +241,16 @@ jobs:
run: make lint run: make lint
- name: Certify Cargo.lock freshness - name: Certify Cargo.lock freshness
run: git diff --exit-code Cargo.lock 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: arbitrary-check:
name: arbitrary-check name: arbitrary-check
runs-on: ubuntu-latest runs-on: ubuntu-latest

View File

@ -18,7 +18,8 @@ status = [
"op-pool-tests", "op-pool-tests",
"doppelganger-protection-test", "doppelganger-protection-test",
"execution-engine-integration-ubuntu", "execution-engine-integration-ubuntu",
"cargo-vendor" "cargo-vendor",
"check-msrv"
] ]
use_squash_merge = true use_squash_merge = true
timeout_sec = 10800 timeout_sec = 10800

View File

@ -4,6 +4,7 @@ version = "2.1.4"
authors = ["Sigma Prime <contact@sigmaprime.io>"] authors = ["Sigma Prime <contact@sigmaprime.io>"]
edition = "2021" edition = "2021"
autotests = false autotests = false
rust-version = "1.58"
[features] [features]
# Writes debugging .ssz files to /tmp during block processing. # Writes debugging .ssz files to /tmp during block processing.