name: "Build"

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

on:
  push:
    branches:
      - '*'
      - '!ci_test_*'
    tags-ignore:
      - '*'
  pull_request:
    branches:
      - '*'
      - '!ci_test_*'

jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    strategy:
      matrix:
        toolchain: [ stable, "1.89.0" ]
    steps:
      - uses: actions/checkout@v6
      - uses: actions-rust-lang/setup-rust-toolchain@v1
        with:
          toolchain: ${{ matrix.toolchain }}
      - run: rustup target add aarch64-unknown-linux-gnu x86_64-unknown-linux-gnu i686-unknown-linux-gnu powerpc-unknown-linux-gnu
      - run: RUSTFLAGS="-C target-feature=+neon" cargo build --all-features --target aarch64-unknown-linux-gnu
      - run: RUSTFLAGS="-C target-feature=+sse4.1" cargo build --all-features --target i686-unknown-linux-gnu
      - run: RUSTFLAGS="-C target-feature=+avx2" cargo build --no-default-features --target i686-unknown-linux-gnu
      - run: cargo build --target powerpc-unknown-linux-gnu --no-default-features
      - run: RUSTFLAGS="-C target-feature=+sse4.1" cargo build --all-features --target x86_64-unknown-linux-gnu
      - run: RUSTFLAGS="-C target-feature=+avx2" cargo build --all-features --target x86_64-unknown-linux-gnu
      - name: Test release pipeline
        run: cargo publish --dry-run
        if: matrix.toolchain == 'stable'

  test_x86_64:
    name: Test x86_64
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: actions-rust-lang/setup-rust-toolchain@v1
      - name: Run tests SSE4.1
        run: RUSTFLAGS="-C target-feature=+sse4.1" cargo test --all-features
      - name: Run tests AVX2
        run: RUSTFLAGS="-C target-feature=+avx2" cargo test --all-features
      - name: Run tests no features
        run: cargo test --no-default-features

  test_i686:
    name: Test i686
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: actions-rust-lang/setup-rust-toolchain@v1
      - run: rustup target add i686-unknown-linux-gnu
      - run: sudo apt-get install -y gcc-multilib
      - name: Run tests SSE4.1
        run: RUSTFLAGS="-C target-feature=+sse4.1" cargo test --all-features --target i686-unknown-linux-gnu
      - name: Run tests AVX2
        run: RUSTFLAGS="-C target-feature=+avx2" cargo test --no-default-features --target i686-unknown-linux-gnu

  test_aarch64:
    name: Test AArch64 NEON
    runs-on: ubuntu-24.04-arm
    steps:
      - uses: actions/checkout@v6
      - uses: actions-rust-lang/setup-rust-toolchain@v1
      - name: Run tests
        run: cargo test --all-features