diff --git a/.github/workflows/miri.yml b/.github/workflows/miri.yml new file mode 100644 index 000000000..38eaa4afd --- /dev/null +++ b/.github/workflows/miri.yml @@ -0,0 +1,33 @@ +--- # rust-bitcoin CI: If you edit this file please update README.md +on: # yamllint disable-line rule:truthy + push: + branches: + - master + - 'test-ci/**' + pull_request: + +name: Miri + +jobs: + Miri: + name: Miri + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - name: "Checkout repo" + uses: actions/checkout@v4 + - name: "Read nightly version" + id: read_toolchain + run: echo "nightly_version=$(cat nightly-version)" >> $GITHUB_OUTPUT + - name: "Select toolchain" + uses: dtolnay/rust-toolchain@v1 + with: + toolchain: ${{ steps.read_toolchain.outputs.nightly_version }} + components: miri + - name: "Setup miri" + run: cargo miri setup + - name: "Set dependencies" + run: cp Cargo-recent.lock Cargo.lock + - name: "Run test script" + run: ./contrib/test-miri.sh diff --git a/contrib/test-miri.sh b/contrib/test-miri.sh new file mode 100755 index 000000000..6ca2dab51 --- /dev/null +++ b/contrib/test-miri.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +set -euox pipefail + +cd "$(dirname "$0")/.." + +. contrib/test_vars.sh + +target_features="$(rustc --print target-features | awk '{ if ($1 == "") { exit 0 } if (NR != 1 && $1 != "crt-static") { if (NR == 2) { printf "+%s", $1 } else { printf ",+%s", $1 } } }')" + +for crate in $CRATES; +do + # The secp256k1 crate cannot be miri-checked because of FFI, so we have to exclude it + if cargo tree --manifest-path "$crate/Cargo.toml" | grep -q secp256k1; + then + echo "$crate depends on secp256k1, skipping..." >&2 + continue + fi + # Running miri is expensive and not needed for crates that don't contain unsafe + if RUSTFLAGS="-C target-feature=$target_features -F unsafe-code" cargo check -q --all-features --target x86_64-unknown-linux-gnu 2>/dev/null; + then + echo "No unsafe code in $crate, skipping..." >&2 + continue + fi + + RUSTFLAGS="-C target-feature=$target_features" RUSTDOCFLAGS="-C target-feature=$target_features" MIRIFLAGS=-Zmiri-backtrace=full cargo miri test --manifest-path "$crate/Cargo.toml" --all-features --target x86_64-unknown-linux-gnu +done diff --git a/nightly-version b/nightly-version index acb9b0b5a..526b67eb7 100644 --- a/nightly-version +++ b/nightly-version @@ -1 +1 @@ -nightly-2024-09-04 +nightly-2024-09-07