diff --git a/.github/workflows/README.md b/.github/workflows/README.md new file mode 100644 index 000000000..f98f5160d --- /dev/null +++ b/.github/workflows/README.md @@ -0,0 +1,42 @@ +# rust-bitcoin workflow notes + +We are attempting to run max 20 parallel jobs using GitHub actions (usage limit for free tier). + +ref: https://docs.github.com/en/actions/learn-github-actions/usage-limits-billing-and-administration + +The minimal/recent lock files are handled by CI (`rust.yml`). + +## Jobs + +Run from `rust.yml` unless stated otherwise. Total 21 jobs but +`Prepare` is quick and must be run first anyway. + +0. `Prepare` +1. `Stable - minimal` +2. `Stable - recent` +3. `Nightly - minimal` +4. `Nightly - recent` +5. `MSRV - minimal` +6. `MSRV - recent` +7. `Lint` +8. `Docs` +9. `Docsrs` +10. `Bench` +11. `Format` +12. `ASAN` +13. `Arch32Bit` +14. `API` + +15. `Cross testing - aarch64-unknown-linux-gnu` +16. `Cross testing - i686-unknown-linux-gnu` +17. `Cross testing - x86_64-pc-windows-gnu` +18. `Cross testing - x86_64-unknown-linux-gnu` +19. `Cross testing - aarch64-unknown-linux-musl` +20. `Cross testing - arm-unknown-linux-gnueabi` +21. `Cross testing - arm-unknown-linux-gnueabihf` +22. `Cross testing - armv7-unknown-linux-gnueabihf` +23. `Cross testing - powerpc-unknown-linux-gnu` +24. `Cross testing - powerpc64le-unknown-linux-gnu` +25. `Cross testing - riscv64gc-unknown-linux-gnu` +26. `Cross testing - s390x-unknown-linux-gnu` +27. `Cross testing - x86_64-unknown-linux-musl` diff --git a/.github/workflows/cron-semi-weekly-update-nightly.yml b/.github/workflows/cron-semi-weekly-update-nightly.yml new file mode 100644 index 000000000..51f7afa2e --- /dev/null +++ b/.github/workflows/cron-semi-weekly-update-nightly.yml @@ -0,0 +1,41 @@ +name: Update Nightly rustc +on: + schedule: + - cron: "0 0 * * 1,4" # runs every Monday and Thursday at 00:00 + workflow_dispatch: # allows manual triggering +jobs: + format: + name: Update nightly rustc + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@nightly + - name: Update rust.yml to use latest nightly + run: | + set -x + # Not every night has a nightly, so extract the date from whatever + # version of the compiler dtolnay/rust-toolchain gives us. + NIGHTLY_DATE=$(rustc +nightly --verbose --version | sed -ne 's/^commit-date: //p') + # Update the nightly version in the reference file. + echo "nightly-${NIGHTLY_DATE}" > nightly-version + echo "nightly_date=${NIGHTLY_DATE}" >> $GITHUB_ENV + # Some days there is no new nightly. In this case don't make an empty PR. + if ! git diff --exit-code > /dev/null; then + echo "Updated nightly. Opening PR." + echo "changes_made=true" >> $GITHUB_ENV + else + echo "Attempted to update nightly but the latest-nightly date did not change. Not opening any PR." + echo "changes_made=false" >> $GITHUB_ENV + fi + - name: Create Pull Request + if: env.changes_made == 'true' + uses: peter-evans/create-pull-request@v6 + with: + token: ${{ secrets.APOELSTRA_CREATE_PR_TOKEN }} + author: Update Nightly Rustc Bot + committer: Update Nightly Rustc Bot + title: Automated daily update to rustc (to nightly-${{ env.nightly_date }}) + body: | + Automated update to Github CI workflow `rust.yml` by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action + commit-message: Automated update to Github CI to rustc nightly-${{ env.nightly_date }} + branch: create-pull-request/daily-nightly-update diff --git a/.github/workflows/cross.yml b/.github/workflows/cross.yml index fb92c84d7..d45e3dffd 100644 --- a/.github/workflows/cross.yml +++ b/.github/workflows/cross.yml @@ -17,7 +17,7 @@ jobs: # - i686-pc-windows-msvc # not supported by cross - i686-unknown-linux-gnu # - x86_64-apple-darwin # proprietary apple stuff - - x86_64-pc-windows-gnu + # - x86_64-pc-windows-gnu # causes CI to fail with: "Application tried to create a window, but no driver could be loaded" # - x86_64-pc-windows-msvc # not supported by cross - x86_64-unknown-linux-gnu ############ Tier 2 with Host Tools @@ -37,20 +37,16 @@ jobs: - x86_64-unknown-linux-musl # - x86_64-unknown-netbsd # error in tests "error: test failed, to rerun pass '--lib'", disabled for now steps: - - name: Checkout Crate - uses: actions/checkout@v2 + - name: "Checkout repo" + uses: actions/checkout@v4 - uses: Swatinem/rust-cache@v1.2.0 with: key: ${{ matrix.feature }}${{ matrix.os }} - - name: Checkout Toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - name: Install target + - name: "Select toolchain" + uses: dtolnay/rust-toolchain@stable + - name: "Install target" run: rustup target add ${{ matrix.arch }} - - name: install cross + - name: "Install cross" run: cargo install cross - - name: run cross test + - name: "Run cross test" run: cross test --target ${{ matrix.arch }} diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index f435fdda7..33cd5cfaf 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -1,133 +1,284 @@ -on: [push, pull_request] +--- # 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: Continuous integration jobs: - Stable: + Prepare: + runs-on: ubuntu-latest + outputs: + nightly_version: ${{ steps.read_toolchain.outputs.nightly_version }} + steps: + - name: "Checkout repo" + uses: actions/checkout@v4 + - name: "Read nightly version" + id: read_toolchain + run: echo "nightly_version=$(cat nightly-version)" >> $GITHUB_OUTPUT + + Stable: # 2 jobs, one per lock file. name: Test - stable toolchain runs-on: ubuntu-latest strategy: fail-fast: false + matrix: + dep: [minimal, recent] steps: - - name: Checkout Crate - uses: actions/checkout@v3 - - name: Checkout Toolchain - # https://github.com/dtolnay/rust-toolchain + - name: "Checkout repo" + uses: actions/checkout@v4 + - name: "Checkout maintainer tools" + uses: actions/checkout@v4 + with: + repository: rust-bitcoin/rust-bitcoin-maintainer-tools + rev: b2ac115 + path: maintainer-tools + - name: "Select toolchain" uses: dtolnay/rust-toolchain@stable - - name: Running test script - env: - DO_LINT: true - DO_DOCS: true - DO_FEATURE_MATRIX: true - run: ./contrib/test.sh + - name: "Set dependencies" + run: cp Cargo-${{ matrix.dep }}.lock Cargo.lock + - name: "Run test script" + run: ./maintainer-tools/ci/run_task.sh stable - Beta: - name: Test - beta toolchain + Nightly: # 2 jobs, one per lock file. + name: Test - nightly toolchain + needs: Prepare runs-on: ubuntu-latest strategy: fail-fast: false + matrix: + dep: [minimal, recent] steps: - - name: Checkout Crate - uses: actions/checkout@v3 - - name: Checkout Toolchain - uses: dtolnay/rust-toolchain@beta - - name: Running test script - run: ./contrib/test.sh + - name: "Checkout repo" + uses: actions/checkout@v4 + - name: "Checkout maintainer tools" + uses: actions/checkout@v4 + with: + repository: rust-bitcoin/rust-bitcoin-maintainer-tools + rev: b2ac115 + path: maintainer-tools + - name: "Select toolchain" + uses: dtolnay/rust-toolchain@v1 + with: + toolchain: ${{ needs.Prepare.outputs.nightly_version }} + - name: "Set dependencies" + run: cp Cargo-${{ matrix.dep }}.lock Cargo.lock + - name: "Run test script" + run: ./maintainer-tools/ci/run_task.sh nightly - Nightly: - name: Test - nightly toolchain + MSRV: # 2 jobs, one per lock file. + name: Test - 1.56.1 toolchain runs-on: ubuntu-latest strategy: fail-fast: false + matrix: + dep: [minimal, recent] steps: - - name: Checkout Crate - uses: actions/checkout@v3 - - name: Checkout Toolchain + - name: "Checkout repo" + uses: actions/checkout@v4 + - name: "Checkout maintainer tools" + uses: actions/checkout@v4 + with: + repository: rust-bitcoin/rust-bitcoin-maintainer-tools + rev: b2ac115 + path: maintainer-tools + - name: "Select toolchain" + uses: dtolnay/rust-toolchain@stable + with: + toolchain: "1.56.1" + - name: "Set dependencies" + run: cp Cargo-${{ matrix.dep }}.lock Cargo.lock + - name: "Run test script" + run: ./maintainer-tools/ci/run_task.sh msrv + + Lint: + name: Lint - nightly toolchain + needs: Prepare + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + dep: [recent] + steps: + - name: "Checkout repo" + uses: actions/checkout@v4 + - name: "Checkout maintainer tools" + uses: actions/checkout@v4 + with: + repository: rust-bitcoin/rust-bitcoin-maintainer-tools + rev: b2ac115 + path: maintainer-tools + - name: "Select toolchain" + uses: dtolnay/rust-toolchain@v1 + with: + toolchain: ${{ needs.Prepare.outputs.nightly_version }} + - name: Install clippy + run: rustup component add clippy + - name: "Set dependencies" + run: cp Cargo-${{ matrix.dep }}.lock Cargo.lock + - name: "Run test script" + run: ./maintainer-tools/ci/run_task.sh lint + + Docs: + name: Docs - stable toolchain + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + dep: [recent] + steps: + - name: "Checkout repo" + uses: actions/checkout@v4 + - name: "Checkout maintainer tools" + uses: actions/checkout@v4 + with: + repository: rust-bitcoin/rust-bitcoin-maintainer-tools + rev: b2ac115 + path: maintainer-tools + - name: "Select toolchain" + uses: dtolnay/rust-toolchain@stable + - name: "Set dependencies" + run: cp Cargo-${{ matrix.dep }}.lock Cargo.lock + - name: "Run test script" + run: ./maintainer-tools/ci/run_task.sh docs + + Docsrs: + name: Docs - nightly toolchain + needs: Prepare + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + dep: [recent] + steps: + - name: "Checkout repo" + uses: actions/checkout@v4 + - name: "Checkout maintainer tools" + uses: actions/checkout@v4 + with: + repository: rust-bitcoin/rust-bitcoin-maintainer-tools + rev: b2ac115 + path: maintainer-tools + - name: "Select toolchain" + uses: dtolnay/rust-toolchain@v1 + with: + toolchain: ${{ needs.Prepare.outputs.nightly_version }} + - name: "Set dependencies" + run: cp Cargo-${{ matrix.dep }}.lock Cargo.lock + - name: "Run test script" + run: ./maintainer-tools/ci/run_task.sh docsrs + + Bench: + name: Bench - nightly toolchain + needs: Prepare + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + dep: [recent] + steps: + - name: "Checkout repo" + uses: actions/checkout@v4 + - name: "Checkout maintainer tools" + uses: actions/checkout@v4 + with: + repository: rust-bitcoin/rust-bitcoin-maintainer-tools + rev: b2ac115 + path: maintainer-tools + - name: "Select toolchain" + uses: dtolnay/rust-toolchain@v1 + with: + toolchain: ${{ needs.Prepare.outputs.nightly_version }} + - name: "Set dependencies" + run: cp Cargo-${{ matrix.dep }}.lock Cargo.lock + - name: "Run test script" + run: ./maintainer-tools/ci/run_task.sh bench + + Format: + name: Format - nightly toolchain + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - name: "Checkout repo" + uses: actions/checkout@v4 + - name: "Select toolchain" uses: dtolnay/rust-toolchain@nightly - - name: Install src - run: rustup component add rust-src - - name: Running test script - env: - DO_FMT: true - DO_BENCH: true - DO_DOCSRS: true - DO_ASAN: true - run: ./contrib/test.sh + - name: "Install rustfmt" + run: rustup component add rustfmt + - name: "Check formatting" + run: cargo +nightly fmt --all -- --check - MSRV: - name: Test - 1.56.1 toolchain + ASAN: # 1 job, run sanitizer from script. + name: ASAN - nightly toolchain + needs: Prepare runs-on: ubuntu-latest strategy: fail-fast: false + matrix: + dep: [recent] steps: - - name: Checkout Crate - uses: actions/checkout@v3 - - name: Checkout Toolchain - uses: dtolnay/rust-toolchain@1.56.1 - - name: Running test script - env: - DO_FEATURE_MATRIX: true - run: ./contrib/test.sh + - name: "Checkout repo" + uses: actions/checkout@v4 + - name: "Select toolchain" + uses: dtolnay/rust-toolchain@v1 + with: + toolchain: ${{ needs.Prepare.outputs.nightly_version }} + - name: "Install rust-src" + run: rustup component add rust-src + - name: "Set dependencies" + run: cp Cargo-${{ matrix.dep }}.lock Cargo.lock + - name: "Run sanitizer script" + run: ./contrib/sanitizer.sh Arch32bit: name: Test 32-bit version runs-on: ubuntu-latest steps: - - name: Checkout Crate + - name: "Checkout repo" uses: actions/checkout@v3 - - name: Checkout Toolchain + - name: "Checkout toolchain" uses: dtolnay/rust-toolchain@stable - - name: Add architecture i386 + - name: "Add architecture i386" run: sudo dpkg --add-architecture i386 - - name: Install i686 gcc + - name: "Install i686 gcc" run: sudo apt-get update -y && sudo apt-get install -y gcc-multilib - - name: Install target + - name: "Install target" run: rustup target add i686-unknown-linux-gnu - - name: Run test on i686 + - name: "Run test on i686" run: cargo test --target i686-unknown-linux-gnu - Cross: - name: Cross test - if: ${{ !github.event.act }} - runs-on: ubuntu-latest - steps: - - name: Checkout Crate - uses: actions/checkout@v3 - - name: Checkout Toolchain - uses: dtolnay/rust-toolchain@stable - - name: Install target - run: rustup target add s390x-unknown-linux-gnu - - name: install cross - run: cargo install cross --locked - - name: run cross test - run: cross test --target s390x-unknown-linux-gnu - WASM: - name: WASM + name: WASM - stable toolchain runs-on: ubuntu-latest + strategy: + fail-fast: false + # Note we do not use the recent lock file for wasm testing. steps: - - name: Checkout Crate - uses: actions/checkout@v3 - - name: Install clang - run: sudo apt-get install -y clang - - name: Checkout Toolchain + - name: "Checkout repo" + uses: actions/checkout@v4 + - name: "Select toolchain" uses: dtolnay/rust-toolchain@stable - - name: Running WASM tests - env: - DO_WASM: true - run: ./contrib/test.sh + - name: "Run wasm script" + run: cd hashes && ./contrib/wasm.sh API: - name: Check for changes to the public API + needs: Prepare + name: API - nightly toolchain runs-on: ubuntu-latest strategy: fail-fast: false steps: - - name: Checkout Crate - uses: actions/checkout@v3 - - name: Checkout Toolchain - uses: dtolnay/rust-toolchain@nightly - - name: Install cargo-public-api + - name: "Checkout repo" + uses: actions/checkout@v4 + - name: "Select toolchain" + uses: dtolnay/rust-toolchain@v1 + with: + toolchain: ${{ needs.Prepare.outputs.nightly_version }} + - name: "Install cargo-public-api" run: cargo install --locked cargo-public-api - - name: Running API checker script + - name: "Run API checker script" run: ./contrib/check-for-api-changes.sh diff --git a/contrib/_test.sh b/contrib/_test.sh deleted file mode 100755 index e18b23146..000000000 --- a/contrib/_test.sh +++ /dev/null @@ -1,124 +0,0 @@ -#!/usr/bin/env bash - -set -ex - -REPO_DIR=$(git rev-parse --show-toplevel) -FEATURES="hashes global-context lowmemory rand recovery serde std alloc hashes-std rand-std" - -cargo --version -rustc --version - -# Work out if we are using a nightly toolchain. -NIGHTLY=false -if cargo --version | grep nightly; then - NIGHTLY=true -fi - -# Pin dependencies as required if we are using MSRV toolchain. -if cargo --version | grep "1\.48"; then - cargo update -p wasm-bindgen-test --precise 0.3.34 - cargo update -p serde_test --precise 1.0.175 -fi - -# Test if panic in C code aborts the process (either with a real panic or with SIGILL) -cargo test -- --ignored --exact 'tests::test_panic_raw_ctx_should_terminate_abnormally' 2>&1 \ - | tee /dev/stderr \ - | grep "SIGILL\\|\[libsecp256k1] illegal argument. " - -# Make all cargo invocations verbose -export CARGO_TERM_VERBOSE=true - -# Defaults / sanity checks -cargo build --locked --all -cargo test --locked --all - -if [ "$DO_FEATURE_MATRIX" = true ]; then - cargo build --locked --all --no-default-features - cargo test --locked --all --no-default-features - - # All features - cargo build --locked --all --no-default-features --features="$FEATURES" - cargo test --locked --all --no-default-features --features="$FEATURES" - # Single features - for feature in ${FEATURES} - do - cargo build --locked --all --no-default-features --features="$feature" - cargo test --locked --all --no-default-features --features="$feature" - done - # Features tested with 'std' feature enabled. - for feature in ${FEATURES} - do - cargo build --locked --all --no-default-features --features="std,$feature" - cargo test --locked --all --no-default-features --features="std,$feature" - done - # Other combos - RUSTFLAGS='--cfg=secp256k1_fuzz' RUSTDOCFLAGS='--cfg=secp256k1_fuzz' cargo test --locked --all - RUSTFLAGS='--cfg=secp256k1_fuzz' RUSTDOCFLAGS='--cfg=secp256k1_fuzz' cargo test --locked --all --features="$FEATURES" - cargo test --locked --all --features="rand serde" - - if [ "$NIGHTLY" = true ]; then - cargo test --locked --all --all-features - RUSTFLAGS='--cfg=secp256k1_fuzz' RUSTDOCFLAGS='--cfg=secp256k1_fuzz' cargo test --locked --all --all-features - fi - - # Examples - cargo run --locked --example sign_verify --features=hashes-std - cargo run --locked --example sign_verify_recovery --features=recovery,hashes-std - cargo run --locked --example generate_keys --features=rand-std -fi - -if [ "$DO_LINT" = true ] -then - cargo clippy --locked --all-features --all-targets -- -D warnings - cargo clippy --locked --example sign_verify --features=hashes-std -- -D warnings - cargo clippy --locked --example sign_verify_recovery --features=recovery,hashes-std -- -D warnings - cargo clippy --locked --example generate_keys --features=rand-std -- -D warnings -fi - -# Build the docs if told to (this only works with the nightly toolchain) -if [ "$DO_DOCSRS" = true ]; then - RUSTDOCFLAGS="--cfg docsrs -D warnings -D rustdoc::broken-intra-doc-links" cargo +nightly doc --all-features -fi - -# Build the docs with a stable toolchain, in unison with the DO_DOCSRS command -# above this checks that we feature guarded docs imports correctly. -if [ "$DO_DOCS" = true ]; then - RUSTDOCFLAGS="-D warnings" cargo +stable doc --all-features -fi - -# Address Sanitizer -if [ "$DO_ASAN" = true ]; then - clang --version - cargo clean - CC='clang -fsanitize=address -fno-omit-frame-pointer' \ - RUSTFLAGS='-Zsanitizer=address -Clinker=clang -Cforce-frame-pointers=yes' \ - ASAN_OPTIONS='detect_leaks=1 detect_invalid_pointer_pairs=1 detect_stack_use_after_return=1' \ - cargo test --lib --all --features="$FEATURES" -Zbuild-std --target x86_64-unknown-linux-gnu - cargo clean - # The -Cllvm-args=-msan-eager-checks=0 flag was added to overcome this issue: - # https://github.com/rust-bitcoin/rust-secp256k1/pull/573#issuecomment-1399465995 - CC='clang -fsanitize=memory -fno-omit-frame-pointer' \ - RUSTFLAGS='-Zsanitizer=memory -Zsanitizer-memory-track-origins -Cforce-frame-pointers=yes -Cllvm-args=-msan-eager-checks=0' \ - cargo test --lib --all --features="$FEATURES" -Zbuild-std --target x86_64-unknown-linux-gnu - - cargo run --release --manifest-path=./no_std_test/Cargo.toml | grep -q "Verified Successfully" - cargo run --release --features=alloc --manifest-path=./no_std_test/Cargo.toml | grep -q "Verified alloc Successfully" -fi - -# Run formatter if told to. -if [ "$DO_FMT" = true ]; then - if [ "$NIGHTLY" = false ]; then - echo "DO_FMT requires a nightly toolchain (consider using RUSTUP_TOOLCHAIN)" - exit 1 - fi - rustup component add rustfmt - cargo fmt --check || exit 1 -fi - -# Bench if told to, only works with non-stable toolchain (nightly, beta). -if [ "$DO_BENCH" = true ] -then - RUSTFLAGS='--cfg=bench' cargo bench --features=recovery,rand-std -fi - -exit 0 diff --git a/contrib/extra_tests.sh b/contrib/extra_tests.sh new file mode 100755 index 000000000..b70d8e396 --- /dev/null +++ b/contrib/extra_tests.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +set -ex + +REPO_DIR=$(git rev-parse --show-toplevel) + +main() { + source_test_vars # Get feature list. + local features="$FEATURES_WITH_STD" + + RUSTFLAGS='--cfg=secp256k1_fuzz' RUSTDOCFLAGS='--cfg=secp256k1_fuzz' cargo test --locked --all + RUSTFLAGS='--cfg=secp256k1_fuzz' RUSTDOCFLAGS='--cfg=secp256k1_fuzz' cargo test --locked --all --features="$features" + + cargo test --locked --all --features="rand serde" +} + +# ShellCheck can't follow non-constant source, `test_vars_script` is correct. +# shellcheck disable=SC1090 +source_test_vars() { + local test_vars_script="$REPO_DIR/contrib/test_vars.sh" + + verbose_say "Sourcing $test_vars_script" + + if [ -e "$test_vars_script" ]; then + # Set crate specific variables. + . "$test_vars_script" + else + err "Missing $test_vars_script" + fi +} + +# +# Main script +# +main "$@" +exit 0 diff --git a/contrib/sanitizer.sh b/contrib/sanitizer.sh new file mode 100755 index 000000000..7cd973b1c --- /dev/null +++ b/contrib/sanitizer.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +# +# Run the Address/Memory Sanitizer tests. + +set -euox pipefail + +REPO_DIR=$(git rev-parse --show-toplevel) + +main() { + source_test_vars # Get feature list. + local features="$FEATURES_WITH_STD" + + clang --version + cargo clean + + CC='clang -fsanitize=address -fno-omit-frame-pointer' \ + RUSTFLAGS='-Zsanitizer=address -Clinker=clang -Cforce-frame-pointers=yes' \ + ASAN_OPTIONS='detect_leaks=1 detect_invalid_pointer_pairs=1 detect_stack_use_after_return=1' \ + cargo test --lib --all --features="$features" -Zbuild-std --target x86_64-unknown-linux-gnu + cargo clean + + # The -Cllvm-args=-msan-eager-checks=0 flag was added to overcome this issue: + # https://github.com/rust-bitcoin/rust-secp256k1/pull/573#issuecomment-1399465995 + CC='clang -fsanitize=memory -fno-omit-frame-pointer' \ + RUSTFLAGS='-Zsanitizer=memory -Zsanitizer-memory-track-origins -Cforce-frame-pointers=yes -Cllvm-args=-msan-eager-checks=0' \ + cargo test --lib --all --features="$features" -Zbuild-std --target x86_64-unknown-linux-gnu + + cargo run --release --manifest-path=./no_std_test/Cargo.toml | grep -q "Verified Successfully" + cargo run --release --features=alloc --manifest-path=./no_std_test/Cargo.toml | grep -q "Verified alloc Successfully" +} + +# ShellCheck can't follow non-constant source, `test_vars_script` is correct. +# shellcheck disable=SC1090 +source_test_vars() { + local test_vars_script="$REPO_DIR/contrib/test_vars.sh" + + verbose_say "Sourcing $test_vars_script" + + if [ -e "$test_vars_script" ]; then + # Set crate specific variables. + . "$test_vars_script" + else + err "Missing $test_vars_script" + fi +} + +# +# Main script +# +main "$@" +exit 0 diff --git a/contrib/test.sh b/contrib/test.sh deleted file mode 100755 index fa6c14a7e..000000000 --- a/contrib/test.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env bash - -set -ex - -REPO_DIR=$(git rev-parse --show-toplevel) -DEPS="recent minimal" - -# Webassembly stuff -# -# The wasm-pack command does not correctly pass args to cargo so we cannot use --locked and test -# with per-commited lockfiles (recent/minimal). Just run the WASM tests from here instead. -if [ "$DO_WASM" = true ]; then - clang --version - CARGO_TARGET_DIR=wasm cargo install --force wasm-pack - printf '\n[lib]\ncrate-type = ["cdylib", "rlib"]\n' >> Cargo.toml - CC=clang wasm-pack build - CC=clang wasm-pack test --node - - exit 0 -fi - -for dep in $DEPS -do - cp "Cargo-$dep.lock" Cargo.lock - $REPO_DIR/contrib/_test.sh - - if [ "$dep" = recent ]; - then - # We always test committed dependencies but we want to warn if they could've been updated - cargo update - if diff Cargo-recent.lock Cargo.lock; - then - echo "Dependencies are up to date" - else - echo "::warning file=Cargo-recent.lock::Dependencies could be updated" - fi - fi -done - -exit 0 diff --git a/contrib/test_vars.sh b/contrib/test_vars.sh new file mode 100644 index 000000000..e6f3f6baa --- /dev/null +++ b/contrib/test_vars.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +# disable verify unused vars, despite the fact that they are used when sourced +# shellcheck disable=SC2034 + +# Test all these features with "std" enabled. +FEATURES_WITH_STD="hashes global-context lowmemory rand recovery serde std alloc hashes-std rand-std" + +# Test all these features with "no-std" enabled. +# rust-miniscript only: https://github.com/rust-bitcoin/rust-miniscript/issues/681 +FEATURES_WITH_NO_STD="" + +# Test all these features without "std" enabled. +FEATURES_WITHOUT_STD="hashes global-context lowmemory rand recovery serde alloc" + +# Run these examples. +EXAMPLES="sign_verify:hashes-std sign_verify_recovery:hashes-std,recovery generate_keys:rand-std" diff --git a/contrib/wasm.sh b/contrib/wasm.sh new file mode 100755 index 000000000..3d8bd8b9b --- /dev/null +++ b/contrib/wasm.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +# +# Run the WASM tests. +# +# The wasm-pack command does not correctly pass args to cargo so we cannot use --locked and test +# with per-commited lockfiles (recent/minimal). Just run the WASM tests from here instead. + +set -euox pipefail + +clang --version +CARGO_TARGET_DIR=wasm cargo install --force wasm-pack +printf '\n[lib]\ncrate-type = ["cdylib", "rlib"]\n' >> Cargo.toml +CC=clang wasm-pack build +CC=clang wasm-pack test --node diff --git a/justfile b/justfile index d98737dc2..fd75907af 100644 --- a/justfile +++ b/justfile @@ -3,36 +3,40 @@ default: # Cargo build everything. build: - cargo build --all-targets --all-features + cargo build --workspace --all-targets --all-features # Cargo check everything. check: - cargo check --all-targets --all-features + cargo check --workspace --all-targets --all-features # Lint everything. lint: - cargo clippy --all-targets --all-features -- --deny warnings + cargo +$(cat ./nightly-version) clippy --workspace --all-targets --all-features -- --deny warnings + +# Run cargo fmt +fmt: + cargo +$(cat ./nightly-version) fmt --all # Check the formatting format: - cargo +nightly fmt --check + cargo +$(cat ./nightly-version) fmt --all --check # Quick and dirty CI useful for pre-push checks. sane: lint - cargo test --quiet --all-targets --no-default-features > /dev/null || exit 1 - cargo test --quiet --all-targets > /dev/null || exit 1 - cargo test --quiet --all-targets --all-features > /dev/null || exit 1 + cargo test --quiet --workspace --all-targets --no-default-features > /dev/null || exit 1 + cargo test --quiet --workspace --all-targets > /dev/null || exit 1 + cargo test --quiet --workspace --all-targets --all-features > /dev/null || exit 1 # doctests don't get run from workspace root with `cargo test`. - cargo test --quiet --doc || exit 1 + cargo test --quiet --workspace --doc || exit 1 # Make an attempt to catch feature gate problems in doctests - cargo test --manifest-path Cargo.toml --doc --no-default-features > /dev/null || exit 1 - -# Check for API changes. -check-api: - ./contrib/check-for-api-changes.sh + cargo test --doc --no-default-features > /dev/null || exit 1 -# Update the lock files. +# Update the recent and minimal lock files. update-lock-files: ./contrib/update-lock-files.sh + +# Check for API changes. +check-api: + ./contrib/check-for-api-changes.sh diff --git a/nightly-version b/nightly-version new file mode 100644 index 000000000..e70649f10 --- /dev/null +++ b/nightly-version @@ -0,0 +1 @@ +nightly-2024-05-04