From bd065f70b0714474bad2539127a04f9d3d56f4a1 Mon Sep 17 00:00:00 2001 From: Paul Sajna Date: Fri, 30 Dec 2022 19:19:47 -0800 Subject: [PATCH] CI update (#655) - Rework crates.json - Build the HAL for every PAC with every relevant feature - Remove deprecated actions-rs workflows - Deny clippy errors but allow warnings --- .github/actions/list-BSPs/action.yml | 2 +- .github/actions/list-HAL-variants/action.yml | 17 ++ .github/pull_request_template.md | 5 +- .github/workflows/build-bsp.yml | 60 ++---- .github/workflows/build-hal.yml | 49 +++++ .github/workflows/bump-crates.yml | 8 +- .github/workflows/generate-docs.yml | 23 +-- .github/workflows/release-crates.yml | 24 +-- .github/workflows/rustfmt.yml | 16 +- boards/edgebadge/examples/neopixel_button.rs | 16 +- boards/edgebadge/examples/neopixel_tilt.rs | 6 +- crates.json | 201 +++++++++++++++---- 12 files changed, 283 insertions(+), 144 deletions(-) create mode 100644 .github/actions/list-HAL-variants/action.yml create mode 100644 .github/workflows/build-hal.yml diff --git a/.github/actions/list-BSPs/action.yml b/.github/actions/list-BSPs/action.yml index b083c3c9891..a502392d17e 100644 --- a/.github/actions/list-BSPs/action.yml +++ b/.github/actions/list-BSPs/action.yml @@ -13,4 +13,4 @@ runs: shell: bash run: | matrix_json=$(cat crates.json | jq -Mr -c '{ "bsp": (.boards | keys ), "toolchain": ["stable", "nightly"] }') - echo "::set-output name=matrix::${matrix_json}" + echo "matrix=${matrix_json}" >> $GITHUB_OUTPUT diff --git a/.github/actions/list-HAL-variants/action.yml b/.github/actions/list-HAL-variants/action.yml new file mode 100644 index 00000000000..2c53c6b49ee --- /dev/null +++ b/.github/actions/list-HAL-variants/action.yml @@ -0,0 +1,17 @@ +name: 'Compute HAL matrix' +description: 'Prepares the build environment' + +outputs: + matrix: + description: "HAL Build matrix" + value: ${{ steps.compute-matrix.outputs.matrix }} +runs: + using: "composite" + steps: + - run: sudo apt-get install -y jq + shell: bash + - id: compute-matrix + shell: bash + run: | + matrix_json=$(cat crates.json | jq -Mr -c '{ "pac": (.hal_build_variants | keys ), "toolchain": ["stable", "nightly"] }') + echo "matrix=${matrix_json}" >> $GITHUB_OUTPUT diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index d9424a59381..d4696f62909 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -8,4 +8,7 @@ ## If Adding a new Board - [ ] Board CI added to `crates.json` - - [ ] Board is properly following "Tier 2" conventions, unless otherwise decided to be "Tier 1" \ No newline at end of file + - [ ] Board is properly following "Tier 2" conventions, unless otherwise decided to be "Tier 1" + +## If Adding a new cargo `feature` to the HAL + - [ ] Feature is added to the test matrix for applicable boards / PACs in `crates.json` diff --git a/.github/workflows/build-bsp.yml b/.github/workflows/build-bsp.yml index a8ba87e6f17..d95d66bfec2 100644 --- a/.github/workflows/build-bsp.yml +++ b/.github/workflows/build-bsp.yml @@ -8,7 +8,7 @@ jobs: matrix: ${{ steps.set-matrix.outputs.matrix }} steps: - name: Checkout sources - uses: actions/checkout@v2 + uses: actions/checkout@v3 - id: set-matrix uses: ./.github/actions/list-BSPs @@ -20,53 +20,31 @@ jobs: matrix: ${{fromJson(needs.setup.outputs.matrix)}} steps: - name: Checkout sources - uses: actions/checkout@v2 - - name: Install Rust (thumbv6m) - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ matrix.toolchain }} - override: true - target: thumbv6m-none-eabi - components: clippy - - name: Install Rust (thumbv7em) - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ matrix.toolchain }} - override: true - target: thumbv7em-none-eabihf - components: clippy + uses: actions/checkout@v3 - - name: Test ${{ matrix.bsp }} + - name: Install Rust + run: | + rustup set profile minimal + rustup override set ${{ matrix.toolchain }} + target=$(cat ./crates.json | jq -Mr --arg board '${{ matrix.bsp }}' -c '.boards | .[$board] | .target') + rustup target add ${target} + rustup component add clippy + + - name: Setup cache + uses: Swatinem/rust-cache@v2 + + - name: Build ${{ matrix.bsp }} run: | build_invocation=$(cat ./crates.json | jq -Mr --arg board '${{ matrix.bsp }}' -c '.boards | .[$board] | .build') set -ex cd boards/${{ matrix.bsp }} $(${build_invocation}) - - uses: actions-rs/clippy-check@v1 + - name: Clippy ${{ matrix.bsp }} if: ${{ matrix.toolchain == 'nightly' }} - with: - token: ${{ secrets.GITHUB_TOKEN }} - name: Clippy ${{ matrix.bsp }} - args: --all-features --manifest-path=boards/${{ matrix.bsp }}/Cargo.toml - - build_hal: - runs-on: ubuntu-latest - steps: - - name: Checkout sources - uses: actions/checkout@v2 - - name: Install Rust (thumbv6m) - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - target: thumbv6m-none-eabi - components: clippy - - name: Build HAL run: | set -ex - cd hal - cargo build --features="library" \ No newline at end of file + build_invocation=$(cat ./crates.json | jq -Mr --arg board '${{ matrix.bsp }}' -c '.boards | .[$board] | .build') + clippy_invocation=$(echo ${build_invocation} | sed 's/cargo build/cargo clippy/g') + cd boards/${{ matrix.bsp }} + $(${clippy_invocation}) diff --git a/.github/workflows/build-hal.yml b/.github/workflows/build-hal.yml new file mode 100644 index 00000000000..404d4401dab --- /dev/null +++ b/.github/workflows/build-hal.yml @@ -0,0 +1,49 @@ +name: Build HAL +on: [push, pull_request] + +jobs: + setup: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + steps: + - name: Checkout sources + uses: actions/checkout@v3 + - id: set-matrix + uses: ./.github/actions/list-HAL-variants + + build: + runs-on: ubuntu-latest + continue-on-error: ${{ matrix.toolchain == 'nightly' }} + needs: setup + strategy: + matrix: ${{fromJson(needs.setup.outputs.matrix)}} + steps: + - name: Checkout sources + uses: actions/checkout@v3 + + - name: Install Rust + run: | + rustup set profile minimal + rustup override set ${{ matrix.toolchain }} + target=$(cat ./crates.json | jq -Mr --arg pac "${{matrix.pac}}" -c '.hal_build_variants["${{matrix.pac}}"].target') + rustup target add ${target} + rustup component add clippy + + - name: Setup cache + uses: Swatinem/rust-cache@v2 + + - name: Build HAL for ${{ matrix.pac }} + run: | + set -ex + features=$(cat ./crates.json | jq -Mr --arg pac "${{matrix.pac}}" -c '.hal_build_variants["${{matrix.pac}}"].features | join(",")') + target=$(cat ./crates.json | jq -Mr --arg pac "${{matrix.pac}}" -c '.hal_build_variants["${{matrix.pac}}"].target') + cargo build --features=${features} --target=${target} --manifest-path=./hal/Cargo.toml + + - name: Clippy HAL for ${{ matrix.pac }} + if: ${{ matrix.toolchain == 'nightly' }} + run: | + set -ex + features=$(cat ./crates.json | jq -Mr --arg pac "${{matrix.pac}}" -c '.hal_build_variants["${{matrix.pac}}"].features | join(",")') + target=$(cat ./crates.json | jq -Mr --arg pac "${{matrix.pac}}" -c '.hal_build_variants["${{matrix.pac}}"].target') + cargo clippy --features=${features} --target=${target} --manifest-path=./hal/Cargo.toml diff --git a/.github/workflows/bump-crates.yml b/.github/workflows/bump-crates.yml index 1d8fe803a84..b2f688b302d 100644 --- a/.github/workflows/bump-crates.yml +++ b/.github/workflows/bump-crates.yml @@ -28,8 +28,10 @@ jobs: runs-on: ubuntu-latest steps: - name: Set up Rust - uses: hecrj/setup-rust-action@v1 - - uses: actions/checkout@v2 + run: | + rustup set profile minimal + rustup override set stable + - uses: actions/checkout@v3 - name: Setup shell: bash run: | @@ -108,7 +110,7 @@ jobs: git diff > bump.patch - name: Upload diff - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: bump.patch path: bump.patch diff --git a/.github/workflows/generate-docs.yml b/.github/workflows/generate-docs.yml index cdce77e5a61..8631ca2c5f8 100644 --- a/.github/workflows/generate-docs.yml +++ b/.github/workflows/generate-docs.yml @@ -12,21 +12,14 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout sources - uses: actions/checkout@v2 - - name: Install Rust (thumbv6m) - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - target: thumbv6m-none-eabi - - name: Install Rust (thumbv7em) - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - target: thumbv7em-none-eabihf + uses: actions/checkout@v3 + + - name: Install Rust + run: | + rustup set profile minimal + rustup override set ${{ matrix.toolchain }} + rustup target add thumbv6m-none-eabi + rustup target add thumbv7em-none-eabihf - name: Generate HAL docs if: github.event.inputs.gen_hal_docs == 'yes' diff --git a/.github/workflows/release-crates.yml b/.github/workflows/release-crates.yml index 2c2773672c4..4a25e5f1c55 100644 --- a/.github/workflows/release-crates.yml +++ b/.github/workflows/release-crates.yml @@ -18,24 +18,12 @@ jobs: release-crates: runs-on: ubuntu-latest steps: - - name: Set up Rust - uses: hecrj/setup-rust-action@v1 - - uses: actions/checkout@v2 - - name: Install thumbv6m - uses: actions-rs/toolchain@v1 - with: - profile: minimal - override: true - toolchain: stable - target: thumbv6m-none-eabi - - name: Install thumbv7em - uses: actions-rs/toolchain@v1 - with: - profile: minimal - override: true - toolchain: stable - target: thumbv7em-none-eabihf - + - name: Install Rust + run: | + rustup set profile minimal + rustup override set stable + rustup target add thumbv6m-none-eabi + rustup target add thumbv7em-none-eabihf - name: Login run: cargo login ${CRATES_IO_TOKEN} diff --git a/.github/workflows/rustfmt.yml b/.github/workflows/rustfmt.yml index dad7468ab09..d00787d04c8 100644 --- a/.github/workflows/rustfmt.yml +++ b/.github/workflows/rustfmt.yml @@ -13,10 +13,12 @@ jobs: format: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - toolchain: nightly - components: rustfmt - override: true - - run: ./rustfmt.sh + - name: Checkout sources + uses: actions/checkout@v3 + - name: Install Rust + run: | + rustup set profile minimal + rustup override set nightly + rustup component add rustfmt + - name: Rustfmt + run: ./rustfmt.sh diff --git a/boards/edgebadge/examples/neopixel_button.rs b/boards/edgebadge/examples/neopixel_button.rs index 006aa299931..4c95338bc0d 100644 --- a/boards/edgebadge/examples/neopixel_button.rs +++ b/boards/edgebadge/examples/neopixel_button.rs @@ -50,9 +50,7 @@ fn main() -> ! { for event in buttons.events() { match event { Keys::LeftDown => { - if pos_joy > 0 { - pos_joy -= 1; - } + pos_joy = pos_joy.saturating_sub(1); } Keys::RightDown => { if pos_joy < 4 { @@ -60,9 +58,7 @@ fn main() -> ! { } } Keys::BDown => { - if pos_button > 0 { - pos_button -= 1; - } + pos_button = pos_button.saturating_sub(1); } Keys::ADown => { if pos_button < 4 { @@ -75,13 +71,7 @@ fn main() -> ! { //finally paint the two leds at position, accel priority let _ = neopixel.write((0..NUM_LEDS).map(|i| { - if i == pos_joy { - hsv2rgb(Hsv { - hue: color_button, - sat: 255, - val: 32, - }) - } else if i == pos_button { + if i == pos_joy || i == pos_button { hsv2rgb(Hsv { hue: color_button, sat: 255, diff --git a/boards/edgebadge/examples/neopixel_tilt.rs b/boards/edgebadge/examples/neopixel_tilt.rs index 21b762afc8f..01a6535efad 100644 --- a/boards/edgebadge/examples/neopixel_tilt.rs +++ b/boards/edgebadge/examples/neopixel_tilt.rs @@ -116,10 +116,8 @@ impl TiltState { if self.pos > 0 { self.pos -= 1; } - } else { - if self.pos < 4 { - self.pos += 1; - } + } else if self.pos < 4 { + self.pos += 1; } self.tilt = 0; } diff --git a/crates.json b/crates.json index e5177704acd..7a4ca8603ab 100644 --- a/crates.json +++ b/crates.json @@ -2,149 +2,184 @@ "boards": { "arduino_mkr1000": { "tier": 2, - "build": "cargo build --examples --all-features" + "build": "cargo build --examples --all-features", + "target": "thumbv6m-none-eabi" }, "arduino_mkrvidor4000": { "tier": 2, - "build": "cargo build --examples --all-features" + "build": "cargo build --examples --all-features", + "target": "thumbv6m-none-eabi" }, "arduino_mkrzero": { "tier": 2, - "build": "cargo build --examples --all-features" + "build": "cargo build --examples --all-features", + "target": "thumbv6m-none-eabi" }, "arduino_nano33iot": { "tier": 2, - "build": "cargo build --examples --all-features" + "build": "cargo build --examples --all-features", + "target": "thumbv6m-none-eabi" }, "atsame54_xpro": { "tier": 2, - "build": "cargo build --examples --all-features" + "build": "cargo build --examples --all-features", + "target": "thumbv7em-none-eabihf" }, "circuit_playground_express": { "tier": 2, - "build": "cargo build --examples --all-features" + "build": "cargo build --examples --all-features", + "target": "thumbv6m-none-eabi" }, "edgebadge": { "tier": 2, - "build": "cargo build --examples --all-features" + "build": "cargo build --examples --all-features", + "target": "thumbv7em-none-eabihf" }, "feather_m0": { "tier": 1, - "build": "cargo build --examples" + "build": "cargo build --examples", + "target": "thumbv6m-none-eabi" }, "feather_m4": { "tier": 1, - "build": "cargo build --examples --all-features" + "build": "cargo build --examples --all-features", + "target": "thumbv7em-none-eabihf" }, "gemma_m0": { "tier": 2, - "build": "cargo build --examples --all-features" + "build": "cargo build --examples --all-features", + "target": "thumbv6m-none-eabi" }, "grand_central_m4": { "tier": 2, - "build": "cargo build --examples --all-features" + "build": "cargo build --examples --all-features", + "target": "thumbv7em-none-eabihf" }, "itsybitsy_m0": { "tier": 2, - "build": "cargo build --examples --all-features" + "build": "cargo build --examples --all-features", + "target": "thumbv6m-none-eabi" }, "itsybitsy_m4": { "tier": 2, - "build": "cargo build --examples --all-features" + "build": "cargo build --examples --all-features", + "target": "thumbv7em-none-eabihf" }, "metro_m0": { "tier": 1, - "build": "cargo build --examples --all-features" + "build": "cargo build --examples --all-features", + "target": "thumbv6m-none-eabi" }, "metro_m4": { "tier": 1, - "build": "cargo build --examples --all-features" + "build": "cargo build --examples --all-features", + "target": "thumbv7em-none-eabihf" }, "neo_trinkey": { "tier": 2, - "build": "cargo build --examples --all-features" + "build": "cargo build --examples --all-features", + "target": "thumbv6m-none-eabi" }, "neokey_trinkey": { "tier": 2, - "build": "cargo build --examples --all-features" + "build": "cargo build --examples --all-features", + "target": "thumbv6m-none-eabi" }, "p1am_100": { "tier": 2, - "build": "cargo build --examples --all-features" + "build": "cargo build --examples --all-features", + "target": "thumbv6m-none-eabi" }, "pfza_proto1": { "tier": 2, - "build": "cargo build --examples --all-features" + "build": "cargo build --examples --all-features", + "target": "thumbv7em-none-eabihf" }, "pygamer": { "tier": 2, - "build": "cargo build --examples --all-features" + "build": "cargo build --examples --all-features", + "target": "thumbv7em-none-eabihf" }, "pyportal": { "tier": 2, - "build": "cargo build --examples --all-features" + "build": "cargo build --examples --all-features", + "target": "thumbv7em-none-eabihf" }, "samd11_bare": { "tier": 1, - "build": "cargo build --release --examples --all-features" + "build": "cargo build --examples --all-features", + "target": "thumbv6m-none-eabi" }, "samd21_mini": { "tier": 2, - "build": "cargo build --examples --all-features" + "build": "cargo build --examples --all-features", + "target": "thumbv6m-none-eabi" }, "serpente": { "tier": 2, - "build": "cargo build --examples --all-features" + "build": "cargo build --examples --all-features", + "target": "thumbv6m-none-eabi" }, "sodaq_one": { "tier": 2, - "build": "cargo build --examples --all-features" + "build": "cargo build --examples --all-features", + "target": "thumbv6m-none-eabi" }, "sodaq_sara_aff": { "tier": 2, - "build": "cargo build --examples --all-features" + "build": "cargo build --examples --all-features", + "target": "thumbv6m-none-eabi" }, "trellis_m4": { "tier": 2, - "build": "cargo build --examples --features=keypad-unproven" + "build": "cargo build --examples --features=keypad-unproven", + "target": "thumbv7em-none-eabihf" }, "trinket_m0": { "tier": 2, - "build": "cargo build --examples --all-features" + "build": "cargo build --examples --all-features", + "target": "thumbv6m-none-eabi" }, "wio_lite_mg126": { "tier": 2, - "build": "cargo build --examples --all-features" + "build": "cargo build --examples --all-features", + "target": "thumbv6m-none-eabi" }, "wio_lite_w600": { "tier": 2, - "build": "cargo build --examples --all-features" + "build": "cargo build --examples --all-features", + "target": "thumbv6m-none-eabi" }, "wio_terminal": { "tier": 1, - "build": "cargo build --examples --all-features" + "build": "cargo build --examples --all-features", + "target": "thumbv7em-none-eabihf" }, "xiao_m0": { "tier": 2, - "build": "cargo build --examples --all-features" + "build": "cargo build --examples --all-features", + "target": "thumbv6m-none-eabi" }, "qt_py_m0": { "tier": 2, - "build": "cargo build --examples --all-features" + "build": "cargo build --examples --all-features", + "target": "thumbv6m-none-eabi" } }, "hal_doc_variants": { "samd11c": { "features": [ "samd11c", - "unproven" + "unproven", + "dma" ], "target": "thumbv6m-none-eabi" }, "samd11d": { "features": [ "samd11d", - "unproven" + "unproven", + "dma" ], "target": "thumbv6m-none-eabi" }, @@ -152,7 +187,8 @@ "features": [ "samd21g", "unproven", - "usb" + "usb", + "dma" ], "target": "thumbv6m-none-eabi" }, @@ -160,7 +196,8 @@ "features": [ "samd21j", "unproven", - "usb" + "usb", + "dma" ], "target": "thumbv6m-none-eabi" }, @@ -168,7 +205,9 @@ "features": [ "samd51g", "unproven", - "usb" + "usb", + "sdmmc", + "dma" ], "target": "thumbv7em-none-eabihf" }, @@ -176,7 +215,9 @@ "features": [ "samd51j", "unproven", - "usb" + "usb", + "sdmmc", + "dma" ], "target": "thumbv7em-none-eabihf" }, @@ -184,7 +225,9 @@ "features": [ "samd51n", "unproven", - "usb" + "usb", + "sdmmc", + "dma" ], "target": "thumbv7em-none-eabihf" }, @@ -192,9 +235,85 @@ "features": [ "samd51p", "unproven", - "usb" + "usb", + "sdmmc", + "dma" ], "target": "thumbv7em-none-eabihf" } + }, + "hal_build_variants": { + "samd11c": { + "features": [ "samd11c", "unproven", "dma", "rtic" ], + "target": "thumbv6m-none-eabi" + }, + "samd11d": { + "features": [ "samd11d", "unproven", "dma", "rtic" ], + "target": "thumbv6m-none-eabi" + }, + "samd21e": { + "features": [ "samd21e", "unproven", "usb", "dma", "rtic" ], + "target": "thumbv6m-none-eabi" + }, + "samd21el": { + "features": [ "samd21el", "unproven", "usb", "dma", "rtic" ], + "target": "thumbv6m-none-eabi" + }, + "samd21g": { + "features": [ "samd21g", "unproven", "usb", "dma", "rtic" ], + "target": "thumbv6m-none-eabi" + }, + "samd21gl": { + "features": [ "samd21gl", "unproven", "usb", "dma", "rtic" ], + "target": "thumbv6m-none-eabi" + }, + "samd21j": { + "features": [ "samd21j", "unproven", "usb", "dma", "rtic" ], + "target": "thumbv6m-none-eabi" + }, + "samd51g": { + "features": [ "samd51g", "unproven", "usb", "dma", "sdmmc", "rtic" ], + "target": "thumbv7em-none-eabihf" + }, + "samd51j": { + "features": [ "samd51j", "unproven", "usb", "dma", "sdmmc", "rtic" ], + "target": "thumbv7em-none-eabihf" + }, + "samd51n": { + "features": [ "samd51n", "unproven", "usb", "dma", "sdmmc", "rtic" ], + "target": "thumbv7em-none-eabihf" + }, + "samd51p": { + "features": [ "samd51p", "unproven", "usb", "dma", "sdmmc", "rtic" ], + "target": "thumbv7em-none-eabihf" + }, + "same51g": { + "features": [ "same51g", "unproven", "usb", "dma", "sdmmc", "rtic" ], + "target": "thumbv7em-none-eabihf" + }, + "same51j": { + "features": [ "same51j", "unproven", "usb", "dma", "sdmmc", "rtic" ], + "target": "thumbv7em-none-eabihf" + }, + "same51n": { + "features": [ "same51n", "unproven", "usb", "dma", "sdmmc", "rtic" ], + "target": "thumbv7em-none-eabihf" + }, + "same53j": { + "features": [ "same53j", "unproven", "usb", "dma", "sdmmc", "rtic" ], + "target": "thumbv7em-none-eabihf" + }, + "same53n": { + "features": [ "same53n", "unproven", "usb", "dma", "sdmmc", "rtic" ], + "target": "thumbv7em-none-eabihf" + }, + "same54n": { + "features": [ "same54n", "unproven", "usb", "dma", "sdmmc", "rtic" ], + "target": "thumbv7em-none-eabihf" + }, + "same54p": { + "features": [ "same54p", "unproven", "usb", "dma", "sdmmc", "rtic" ], + "target": "thumbv7em-none-eabihf" + } } }