cverif 0.1.1

Verifies that compiled machine code faithfully matches its C source
Documentation
name: CI

on:
  push:
    branches: [master]
  pull_request:
  workflow_dispatch:

# A newer push to the same branch (or PR) supersedes this run: cancel the
# older one instead of queueing every intermediate commit.
concurrency:
  group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}
  cancel-in-progress: true

permissions:
  contents: read

env:
  CARGO_TERM_COLOR: always

jobs:
  lint:
    name: Format & clippy (${{ matrix.os }})
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
    steps:
      - uses: actions/checkout@v7

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy

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

      - name: Format
        if: runner.os == 'Linux' # formatting is platform-independent
        run: cargo fmt --all --check

      - name: Clippy (warnings denied)
        run: cargo clippy --all-targets -- -D warnings

  # The whole test suite, split into shares that run side by side: every test
  # runs in exactly one of them (scripts/ci_shard.py balances them by
  # scripts/test-times.tsv). The end-to-end tests compile C with
  # arm-none-eabi-gcc and clang at several optimisation levels and verify the
  # result; tests/qemu_diff.rs runs the executor against QEMU's Cortex-M
  # models. They skip themselves where a compiler (or QEMU) is absent, so the
  # Linux shares are the ones that run them all.
  test:
    name: Test (${{ matrix.os }}, share ${{ matrix.shard }} of ${{ matrix.of }})
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - { os: ubuntu-latest, shard: 0, of: 6 }
          - { os: ubuntu-latest, shard: 1, of: 6 }
          - { os: ubuntu-latest, shard: 2, of: 6 }
          - { os: ubuntu-latest, shard: 3, of: 6 }
          - { os: ubuntu-latest, shard: 4, of: 6 }
          - { os: ubuntu-latest, shard: 5, of: 6 }
          # Without an ARM cross compiler only clang's tests do real work there.
          - { os: windows-latest, shard: 0, of: 2 }
          - { os: windows-latest, shard: 1, of: 2 }
          - { os: macos-latest, shard: 0, of: 2 }
          - { os: macos-latest, shard: 1, of: 2 }
    steps:
      - uses: actions/checkout@v7

      - name: Install ARM cross compiler and QEMU
        if: runner.os == 'Linux'
        run: |
          sudo apt-get update
          sudo apt-get install -y gcc-arm-none-eabi binutils-arm-none-eabi clang qemu-system-arm
          arm-none-eabi-gcc --version

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable

      # (For scripts/ci_shard.py: `python` on every runner.)
      - name: Install Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.x"

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

      - name: Test
        shell: bash
        run: |
          python scripts/ci_shard.py --shard ${{ matrix.shard }} --of ${{ matrix.of }} \
            --record "test-times-${{ matrix.shard }}.tsv"

      # The times of this run's tests: those of the Linux shares, concatenated,
      # are an up-to-date scripts/test-times.tsv.
      - name: Keep the test times
        if: always() && runner.os == 'Linux'
        uses: actions/upload-artifact@v7
        with:
          name: test-times-${{ matrix.shard }}
          path: test-times-${{ matrix.shard }}.tsv
          if-no-files-found: ignore

  msrv:
    name: MSRV (Rust 1.95)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7

      # Keep this pin in sync with `rust-version` in Cargo.toml. Compile-only:
      # behaviour is covered by the stable `test` jobs.
      - name: Install Rust 1.95 (declared MSRV)
        uses: dtolnay/rust-toolchain@1.95

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

      - name: cargo check --all-targets
        run: cargo check --all-targets

  binary:
    name: Build binary (${{ matrix.target }})
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
          - target: x86_64-pc-windows-msvc
            os: windows-latest
          - target: aarch64-apple-darwin
            os: macos-latest
    steps:
      - uses: actions/checkout@v7

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

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

      - name: Build the cverif binary
        run: cargo build --release --bin cverif --target ${{ matrix.target }}

      - name: Smoke test
        shell: bash
        run: target/${{ matrix.target }}/release/cverif --version

      - name: Upload artifact
        uses: actions/upload-artifact@v7
        with:
          name: cverif-${{ matrix.target }}
          path: |
            target/${{ matrix.target }}/release/cverif
            target/${{ matrix.target }}/release/cverif.exe
          if-no-files-found: error