name: CI Checks

on: [push, pull_request]

jobs:
  test-units:
    strategy:
      matrix:
        #os: [ubuntu-latest, macos-latest]
        os: [ubuntu-latest]
    runs-on: ${{ matrix.os }}

    steps:
      - uses: actions/checkout@v2
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: nightly
          override: true
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: nightly
          target: wasm32-unknown-unknown
          override: true

      - uses: Swatinem/rust-cache@v1

      - name: Install dependencies (Linux)
        run: |
          sudo apt update
          sudo apt -y install jq build-essential clang libclang-dev llvm-dev libudev-dev pkg-config libasound2-dev
        if: matrix.os == 'ubuntu-latest'

      - name: Install dependencies (macOS)
        run: |
          brew install llvm
        if: matrix.os == 'macos-latest'

      - name: Run test units
        run: |
          make test

      - name: Compile all bins
        run: |
          ./contrib/compile_all_bins.sh

  feature-powerset:
    name: Test crate feature powerset on ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest]

    steps:
      - uses: actions/checkout@v2
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: nightly
          override: true
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: nightly
          target: wasm32-unknown-unknown
          override: true
      - uses: taiki-e/install-action@cargo-hack
      - uses: Swatinem/rust-cache@v1

      - name: Install dependencies (Linux)
        run: |
          sudo apt update
          sudo apt -y install jq build-essential clang libclang-dev llvm-dev libudev-dev pkg-config libasound2-dev
        if: matrix.os == 'ubuntu-latest'

      - name: Install dependencies (macOS)
        run: |
          brew install llvm
        if: matrix.os == 'macos-latest'

      - name: Run feature powerset builds
        run: |
          make check

  fmt:
    name: rustfmt
    timeout-minutes: 30
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: nightly
          components: rustfmt
          override: true
      - run: |
          cargo fmt -- --check
