name: Cloud Hypervisor Code Formatting
on: [pull_request, merge_group]
concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-${{ github.event_name }}
  cancel-in-progress: true

jobs:
  build:
    name: Code Formatting
    runs-on: ubuntu-latest
    strategy:
      matrix:
        rust:
          - nightly
        target:
          - x86_64-unknown-linux-gnu
          - aarch64-unknown-linux-musl
    env:
      RUSTFLAGS: -D warnings
    steps:
      - name: Code checkout
        uses: actions/checkout@v6
      - name: Install Rust toolchain (${{ matrix.rust }})
        uses: dtolnay/rust-toolchain@stable
        with:
            toolchain: ${{ matrix.rust }}
            target: ${{ matrix.target }}
            components: rustfmt
      - name: Formatting (rustfmt)
        run: cargo fmt --all -- --check
      - name: Formatting (fuzz) (rustfmt)
        run: cargo fmt --all --manifest-path fuzz/Cargo.toml -- --check
