From 433699fd9892b5bf45f348358b3e2989208cf479 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Wed, 1 Mar 2023 14:09:31 +1100 Subject: [PATCH 1/2] Enable alloc feature in with-allocator As the crate name suggests `with_allocator` requires the "alloc" feature to be enabled. --- embedded/with-allocator/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embedded/with-allocator/Cargo.toml b/embedded/with-allocator/Cargo.toml index d4010dc02..b6c0615cf 100644 --- a/embedded/with-allocator/Cargo.toml +++ b/embedded/with-allocator/Cargo.toml @@ -11,7 +11,7 @@ cortex-m-rt = "0.6.10" cortex-m-semihosting = "0.3.3" panic-halt = "0.2.0" alloc-cortex-m = "0.4.1" -bech32 = { path="../../", default-features = false } +bech32 = { path="../../", default-features = false, features = ["alloc"] } [[bin]] name = "with-allocator" From 7873c858788b560531bef495cfb1440aefb5a9cd Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Wed, 1 Mar 2023 13:59:31 +1100 Subject: [PATCH 2/2] Rework GitHub actions Rework the github actions to fix the many bugs Tobin recently introduced. - Use dtolnay instead of actions-rs (non-embedded only) - Put fmt and clippy control into the CI script --- .github/workflows/rust.yml | 120 ++++++++++++++++++------------------- contrib/test.sh | 26 +++++++- 2 files changed, 82 insertions(+), 64 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 25873088c..a5c95bf61 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -1,82 +1,79 @@ -on: [pull_request] +on: [push, pull_request] name: Continuous Integration jobs: - Test: - name: Test Suite + Stable: + name: Test - stable toolchain runs-on: ubuntu-latest strategy: - matrix: - rust: - - 1.41.1 - - stable - - nightly + fail-fast: false steps: - name: Checkout Crate - - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Checkout Toolchain - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ matrix.rust }} - override: true - - name: Run Test Script - env: ${{ matrix.rust }} + # https://github.com/dtolnay/rust-toolchain + uses: dtolnay/rust-toolchain@stable + - name: Running test script + env: + DO_LINT: true run: ./contrib/test.sh - fmt: - name: Rustfmt + Beta: + name: Test - beta toolchain runs-on: ubuntu-latest + strategy: + fail-fast: false steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - override: true - - run: rustup component add rustfmt - - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check + - name: Checkout Crate + uses: actions/checkout@v3 + - name: Checkout Toolchain + uses: dtolnay/rust-toolchain@beta + - name: Running test script + run: ./contrib/test.sh - clippy: - name: Clippy + Nightly: + name: Test - nightly toolchain runs-on: ubuntu-latest strategy: - matrix: - rust: - - stable + fail-fast: false steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ matrix.rust }} - override: true - - run: rustup component add clippy - - uses: actions-rs/cargo@v1 - with: - command: clippy - args: -- -D warnings + - name: Checkout Crate + uses: actions/checkout@v3 + - name: Checkout Toolchain + uses: dtolnay/rust-toolchain@nightly + - name: Running test script + env: + DO_FMT: true + run: ./contrib/test.sh + + MSRV: + name: Test - 1.41.1 toolchain + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - name: Checkout Crate + uses: actions/checkout@v3 + - name: Checkout Toolchain + uses: dtolnay/rust-toolchain@1.41.1 + - name: Running test script + run: ./contrib/test.sh EmbeddedWithAlloc: name: no_std with alloc runs-on: ubuntu-latest + strategy: + fail-fast: false steps: - - name: Checkout - uses: actions/checkout@v2 + - name: Checkout Crate + uses: actions/checkout@v3 - name: Set up QEMU run: sudo apt update && sudo apt install -y qemu-system-arm gcc-arm-none-eabi - name: Checkout Toolchain - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@nightly with: - profile: minimal - toolchain: nightly - override: true - components: rust-src - target: thumbv7m-none-eabi + targets: thumbv7m-none-eabi - name: Run env: RUSTFLAGS: "-C link-arg=-Tlink.x" @@ -87,14 +84,11 @@ jobs: name: no_std no alloc runs-on: ubuntu-latest strategy: + fail-fast: false steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - uses: actions-rs/cargo@v1 - with: - command: rustc - args: -- -C link-arg=-nostartfiles + - name: Checkout Crate + uses: actions/checkout@v3 + - name: Checkout Toolchain + uses: dtolnay/rust-toolchain@stable + - name: Run + run: cd embedded/no-allocator && cargo rustc -- -C link-arg=-nostartfiles diff --git a/contrib/test.sh b/contrib/test.sh index cb1ad4ff8..4ad7facc2 100755 --- a/contrib/test.sh +++ b/contrib/test.sh @@ -6,15 +6,39 @@ set -ex +FEATURES="std alloc" + +# Some tests require certain toolchain types. +NIGHTLY=false +if cargo --version | grep nightly; then + NIGHTLY=true +fi + # Sanity, check tools exist. cargo --version rustc --version +# Run the linter if told to. +if [ "$DO_LINT" = true ] +then + cargo clippy --all-features --all-targets -- -D warnings +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 +fi + # Check without features ("strict" is a CI feature only, see above). cargo build --no-default-features --features="strict" cargo test --no-default-features --features="strict" -# Check "std" feature (implies "alloc"). +# Check "std" feature (implies "alloc", so this is equivalent to --all-features). cargo build --no-default-features --features="strict std" cargo test --no-default-features --features="strict std"