svd2rust 0.37.1

Generate Rust register maps (`struct`s) from SVD files
Documentation
on:
  push:
    branches: [master]
  pull_request:
  merge_group:

name: Continuous integration

jobs:
  ci:
    name: CI
    runs-on: ubuntu-latest
    needs: [check, ci-linux, ci-docs-clippy, ci-serde]
    if: always()
    steps:
      - name: Done
        run: jq --exit-status 'all(.result == "success")' <<< '${{ toJson(needs) }}'

  check:
    name: Cargo check / clippy
    runs-on: ubuntu-latest
    strategy:
      matrix:
        TARGET:
          [
            x86_64-unknown-linux-gnu,
            x86_64-apple-darwin,
            x86_64-pc-windows-msvc,
          ]

    steps:
      - uses: actions/checkout@v4

      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: stable
          targets: ${{ matrix.TARGET }}
          components: clippy

      - name: Cache Dependencies
        uses: Swatinem/rust-cache@v2
        with:
          key: ${{ matrix.TARGET }}

      - run: cargo check --target ${{ matrix.TARGET }} --no-default-features
        env:
          RUSTFLAGS: -D warnings
      - run: cargo check --target ${{ matrix.TARGET }}
        env:
          RUSTFLAGS: -D warnings
      - run: cargo clippy --target ${{ matrix.TARGET }}

  ci-linux:
    runs-on: ubuntu-latest
    needs: [check]
    strategy:
      fail-fast: false
      matrix:
        include:
          - { vendor: Atmel }
          - { vendor: Atmel, options: "-- --strict --atomics" }
          - { vendor: Freescale }
          - { vendor: Freescale, options: "-- --strict --atomics" }
          - { vendor: Fujitsu }
          - { vendor: Fujitsu, options: "-- --atomics" }
          - { vendor: Holtek }
          - { vendor: Holtek, options: "-- --strict --atomics" }
          - { vendor: Atmel }
          - { vendor: Atmel, options: "-- --strict --atomics" }
          - { vendor: Microchip }
          - { vendor: Microchip, options: "-- --atomics" }
          - { vendor: Nordic }
          - { vendor: Nordic, options: "-- --strict --atomics" }
          - { vendor: Nuvoton }
          - { vendor: Nuvoton, options: "-- --atomics" }
          - { vendor: NXP }
          - { vendor: NXP, options: "-- --strict --atomics" }
          - { vendor: SiFive }
          - { vendor: SiFive, options: "-- --atomics" }
          - { vendor: SiliconLabs, options: "" }
          - { vendor: SiliconLabs, options: "-- --strict --atomics" }
          - { vendor: Spansion }
          - { vendor: Spansion, options: "-- --atomics" }
          - { vendor: STMicro }
          - { vendor: STMicro, options: "-- --atomics" }
          - {
              vendor: STMicro,
              options: "-- --strict -f enum_value::p: --max-cluster-size --atomics --atomics-feature atomics --impl-debug --impl-defmt defmt",
            }
          - { vendor: Toshiba }
          - { vendor: Toshiba, options: "-- --strict --atomics" }
          - { vendor: TexasInstruments }
          - { vendor: TexasInstruments, options: "-- --atomics" }
          - { vendor: Espressif }
          - { vendor: Espressif, options: "-- --atomics --edition=2024" }
          - { vendor: Vorago }
          - { vendor: Vorago, options: "-- --strict --atomics" }
          - { vendor: Renesas }
          - { vendor: RaspberryPi }
          - { vendor: RaspberryPi, options: "-- --atomics" }

    steps:
      - uses: actions/checkout@v4

      - uses: dtolnay/rust-toolchain@stable

      - name: Cache
        uses: Swatinem/rust-cache@v2

      - name: Self install
        run: |
          cargo install svd2rust --path .

      - name: Run regression tool
        run: cargo regress tests -m ${{ matrix.vendor }} ${{ matrix.options }}

  ci-msrv-check:
    runs-on: ubuntu-latest
    needs: [check]
    steps:
      - uses: actions/checkout@v4

      - name: Self install
        run: |
          cargo install svd2rust --path .

      # Install the MSRV toolchain
      - uses: dtolnay/rust-toolchain@1.76.0
      - name: Run reression tool with MSRV
        # The MSRV only applies to the generated crate. The regress tool should still be run with
        # stable.
        run: cargo +stable regress tests --toolchain 1.76.0 -m Nordic -- --strict --atomics

  ci-docs-clippy:
    runs-on: ubuntu-latest
    needs: [check]
    strategy:
      fail-fast: false
      matrix:
        include:
          # STMicro
          - { chip: STM32F030 }
          - { chip: STM32F410 }
          - { chip: STM32L1xx }
          # Espressif
          - { chip: esp32c3 }
          # Freescale
          - { chip: MKW22D5 }
          - { chip: MK02F12810 }
          # Silicon Labs
          - { chip: SIM3L1x8_SVD }
          # Nordic chips
          - { chip: nrf51, options: "-- -f register_mod::s:_mod" }
          - { chip: nrf52, options: "-- -f register_mod::s:_mod" }
    steps:
      - uses: actions/checkout@v4

      - uses: dtolnay/rust-toolchain@nightly
      - uses: dtolnay/rust-toolchain@stable

      - name: Cache
        uses: Swatinem/rust-cache@v2

      - name: Self install
        run: |
          cargo install svd2rust --path .

      - name: Check docs and clippy on generated PACs
        run: cargo regress test -c ${{ matrix.chip }} --docs-stable --docs-nightly --clippy ${{ matrix.options }}

  ci-serde:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: stable

      - name: Cache
        uses: Swatinem/rust-cache@v2
        with:
          key: svdtools-0.4.6

      - name: Install svdtools
        run: |
          cargo install svdtools --version 0.4.6 --target-dir target

      - name: Run CI script
        run: |
          wget https://stm32-rs.github.io/stm32-rs/stm32f411.svd.patched
          svdtools convert --input-format xml stm32f411.svd.patched stm32f411.yaml
          cargo run --release -- -i stm32f411.yaml

  fmt:
    name: Rustfmt
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: stable
          components: rustfmt

      - name: Cache Dependencies
        uses: Swatinem/rust-cache@v2

      - run: cargo fmt --all -- --check

  artifact:
    name: Build svd2rust artifact
    if: github.event_name == 'pull_request'
    needs: [check]
    runs-on: ${{ matrix.runs-on }}
    strategy:
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            runs-on: ubuntu-latest
          - target: aarch64-apple-darwin
            runs-on: macos-latest
          - target: x86_64-pc-windows-msvc
            runs-on: windows-latest
            suffix: .exe
    steps:
      - uses: actions/checkout@v4

      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: stable
          targets: ${{ matrix.target }}

      - name: Cache Dependencies
        uses: Swatinem/rust-cache@v2

      - name: Build svd2rust artifact
        run: cargo build --release --target ${{ matrix.target }}

      - run: mv target/${{ matrix.target }}/release/svd2rust${{ matrix.suffix || '' }} svd2rust-${{ matrix.target }}-$(git rev-parse --short HEAD)${{ matrix.suffix || '' }}

      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: artifact-svd2rust-${{ matrix.target }}
          path: svd2rust-${{ matrix.target }}*