name: CI

on:
  push:
    branches:
      - '**'
  pull_request:
    branches:
      - '**'

env:
  CARGO_INCREMENTAL: 0
  CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse

jobs:
  test:
    name: Test
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        include:
          - build: linux-amd64
            os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
          - build: android-arm64
            os: ubuntu-latest
            target: aarch64-linux-android
            no_run: --no-run
          - build: android-amd64
            os: ubuntu-latest
            target: x86_64-linux-android
            no_run: --no-run
          - build: macos-amd64
            os: macos-latest
            target: x86_64-apple-darwin
          - build: macos-arm64
            os: macos-14
            target: aarch64-apple-darwin
          - build: ios-arm64
            os: macos-latest
            target: aarch64-apple-ios
            no_run: --no-run
          - build: windows-amd64
            os: windows-latest
            target: x86_64-pc-windows-msvc
          - build: windows-arm64
            os: windows-latest
            target: aarch64-pc-windows-msvc
            no_run: --no-run
    steps:
      - uses: actions/checkout@v4
      - name: Install Rust (rustup)
        run: |
          set -euxo pipefail
          rustup toolchain install stable --no-self-update --profile minimal --target ${{ matrix.target }}
          rustup default stable
        shell: bash
      - uses: Swatinem/rust-cache@v2
      - name: Setup android environment
        if: contains(matrix.build, 'android')
        uses: ./.github/actions/ndk-dev-rs
        with:
          rust-target: ${{ matrix.target }}
      - run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }}
      - run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --release

  msrv_n_clippy:
    name: MSRV & Clippy & Rustfmt
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - run: cargo fmt -- --check
      - run: cargo clippy --all-features -- -D warnings
      - run: cargo check --lib -p netstack-smoltcp
      - run: cargo check --lib -p netstack-smoltcp --all-features
