derive-mmio 0.8.0

A mechanism for making it easier to access MMIO peripherals
Documentation
on:
  push:
    branches: [ main ]
  pull_request:

name: Build

jobs:

  # Define Rust versions dynamically
  setup:
    runs-on: ubuntu-latest
    outputs:
      matrix: ${{ steps.set-matrix.outputs.rust_versions }}
    steps:
      - id: set-matrix
        run: |
          echo 'rust_versions={"rust": ["stable", "1.85"]}' >> "$GITHUB_OUTPUT"

  # Build the library
  build:
    runs-on: ubuntu-latest
    needs: setup
    strategy:
      matrix: ${{ fromJSON(needs.setup.outputs.matrix) }}
    steps:
      - name: Checkout
        uses: actions/checkout@v7
      - name: Install rust
        run: |
          rustup install ${{ matrix.rust }}
          rustup default ${{ matrix.rust }}
      - name: Build
        run: |
          cargo build --examples

  # Cross-Build the library with no_std
  cross-build:
    runs-on: ubuntu-latest
    needs: setup
    strategy:
      matrix:
        rust: ${{ fromJSON(needs.setup.outputs.matrix).rust }}
        target:
          - thumbv7em-none-eabihf
    steps:
      - name: Checkout
        uses: actions/checkout@v7
      - name: Install rust
        run: |
          rustup install ${{ matrix.rust }}
          rustup default ${{ matrix.rust }}
          rustup target add ${{ matrix.target }}
      - name: Build
        run: |
          cargo build --manifest-path ./examples/no_std/Cargo.toml --target ${{ matrix.target }}

  # Build the macro
  build-macro:
    runs-on: ubuntu-latest
    needs: setup
    strategy:
      matrix: ${{ fromJSON(needs.setup.outputs.matrix) }}
    steps:
      - name: Checkout
        uses: actions/checkout@v7
      - name: Install rust
        run: |
          rustup install ${{ matrix.rust }}
          rustup default ${{ matrix.rust }}
      - name: Build
        run: |
          cd macro
          cargo build

  # Gather all the above build jobs together for the purposes of getting an overall pass-fail
  build-all:
    runs-on: ubuntu-latest
    needs: [build, build-macro, cross-build]
    steps:
      - run: /bin/true

  # Test the library
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v7
      - name: Install rust
        run: |
          rustup install 1.85
          rustup default 1.85
      - run: cargo test --all-targets

  # Build the docs for the library
  docs:
    runs-on: ubuntu-latest
    needs: setup
    strategy:
      matrix: ${{ fromJSON(needs.setup.outputs.matrix) }}
    steps:
      - name: Checkout
        uses: actions/checkout@v7
      - name: Install rust
        run: |
          rustup install ${{ matrix.rust }}
          rustup default ${{ matrix.rust }}
      - name: Build docs
        run: |
          cargo doc --examples

  # Format the library
  fmt:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v7
      - name: Install rust
        run: |
          rustup install stable
          rustup default stable
      - name: Format Check
        run: |
          cargo fmt --check
      - name: Format Check for macro
        run: |
          cd macro
          cargo fmt --check

  # Run clippy on the library
  clippy:
    runs-on: ubuntu-latest
    needs: setup
    strategy:
      matrix: ${{ fromJSON(needs.setup.outputs.matrix) }}
    steps:
      - name: Checkout
        uses: actions/checkout@v7
      - name: Install rust
        run: |
          rustup install ${{ matrix.rust }}
          rustup default ${{ matrix.rust }}
          rustup component add clippy
      - name: Clippy
        run: |
          cargo clippy --examples
      - name: Clippy for the Macro
        run: |
          cd macro
          cargo clippy

  # Gather all the above xxx-all jobs together for the purposes of getting an overall pass-fail
  all:
    runs-on: ubuntu-latest
    needs: [docs, build-all, test, fmt] # not gating on clippy-all
    steps:
      - run: /bin/true