pxdct 0.3.6

Discrete cosine transform
Documentation
name: Build

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

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

jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        rust: [ "1.89.0", stable ]
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: ${{ matrix.rust }}
      - run: rustup target add aarch64-unknown-linux-gnu x86_64-unknown-linux-gnu i686-unknown-linux-gnu powerpc-unknown-linux-gnu wasm32-unknown-unknown
      - run: RUSTFLAGS="-C target-feature=+neon" cargo build --target aarch64-unknown-linux-gnu
      - run: RUSTFLAGS="-C target-feature=+neon" cargo build --target aarch64-unknown-linux-gnu --no-default-features
      - run: RUSTFLAGS="-C target-feature=+avx2" cargo build --target i686-unknown-linux-gnu
      - run: cargo build --target powerpc-unknown-linux-gnu
      - run: RUSTFLAGS="-C target-feature=+avx2" cargo build --target x86_64-unknown-linux-gnu
      - run: RUSTFLAGS="-C target-feature=+avx2" cargo build --target x86_64-unknown-linux-gnu --no-default-features --features avx
      - run: RUSTFLAGS="-C target-feature=+avx2" cargo +nightly build --target x86_64-unknown-linux-gnu --no-default-features --features avx
      - run: RUSTFLAGS="-C target-feature=+simd128" cargo build --target wasm32-unknown-unknown

  tests_arm:
    name: Tests
    strategy:
      matrix:
        features: [ "", neon, fcma ]
    runs-on: ubuntu-24.04-arm
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@nightly
      - run: cargo test --no-default-features --features "${{ matrix.features }}"

  tests_x86:
    name: Tests
    strategy:
      matrix:
        features: [ "", avx ]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@stable
      - run: cargo test --no-default-features --features "${{ matrix.features }}"

  clippy_x86:
    name: Clippy x86 Stable
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@stable
      - run: cargo clippy --features avx -- -D warnings
      - run: cargo clippy --no-default-features -- -D warnings

  clippy_x86_nightly:
    name: Clippy x86 Nightly
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@nightly
      - run: rustup component add clippy
      - run: cargo clippy --all-features -- -D warnings

  clippy_arm:
    name: Clippy ARM
    runs-on: ubuntu-24.04-arm
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@stable
      - run: cargo clippy -- -D warnings

  fuzz_arm:
    name: Fuzzing ARM
    runs-on: ubuntu-24.04-arm
    if: github.event_name == 'pull_request'
    strategy:
      matrix:
        feature: [ "", neon, fcma ]
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@nightly
      - run: cargo install cargo-fuzz
      - run: cargo fuzz run dct --no-default-features --features "${{ matrix.feature }}" -- -max_total_time=12
      - run: cargo fuzz run dct4 --no-default-features --features "${{ matrix.feature }}" -- -max_total_time=12
      - run: cargo fuzz run dct2_f64 --no-default-features --features "${{ matrix.feature }}" -- -max_total_time=12
      - run: cargo fuzz run dct4_f64 --no-default-features --features "${{ matrix.feature }}" -- -max_total_time=12
      - run: cargo fuzz run type1 --no-default-features --features "${{ matrix.feature }}" -- -max_total_time=12
      - run: cargo fuzz run type7 --no-default-features --features "${{ matrix.feature }}" -- -max_total_time=12
      - run: cargo fuzz run type6 --no-default-features --features "${{ matrix.feature }}" -- -max_total_time=12
      - run: cargo fuzz run type5 --no-default-features --features "${{ matrix.feature }}" -- -max_total_time=12
      - run: cargo fuzz run type8 --no-default-features --features "${{ matrix.feature }}" -- -max_total_time=12

  fuzz_x86_64:
    name: Fuzzing x86_64
    runs-on: ubuntu-latest
    if: github.event_name == 'pull_request'
    strategy:
      matrix:
        feature: [ "", avx ]
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@nightly
      - run: cargo install cargo-fuzz
      - run: cargo fuzz run dct --no-default-features --features "${{ matrix.feature }}" -- -max_total_time=12
      - run: cargo fuzz run dct4 --no-default-features --features "${{ matrix.feature }}" -- -max_total_time=12
      - run: cargo fuzz run dct2_f64 --no-default-features --features "${{ matrix.feature }}" -- -max_total_time=12
      - run: cargo fuzz run dct4_f64 --no-default-features --features "${{ matrix.feature }}" -- -max_total_time=12
      - run: cargo fuzz run type1 --no-default-features --features "${{ matrix.feature }}" -- -max_total_time=12
      - run: cargo fuzz run type7 --no-default-features --features "${{ matrix.feature }}" -- -max_total_time=12
      - run: cargo fuzz run type6 --no-default-features --features "${{ matrix.feature }}" -- -max_total_time=12
      - run: cargo fuzz run type5 --no-default-features --features "${{ matrix.feature }}" -- -max_total_time=12
      - run: cargo fuzz run type8 --no-default-features --features "${{ matrix.feature }}" -- -max_total_time=12

  tests_x86_sse_isolated:
    name: Testing x86 SSE isolated
    runs-on: ubuntu-latest
    if: github.event_name == 'pull_request'
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@nightly
      - run: |
          sudo apt-get -y update
          sudo apt-get install -y qemu-user
      - run: |
          failed=0
          tests=$(cargo +nightly test --lib -- --list 2>/dev/null | grep ': test' | sed 's/: test//')
          while read -r test; do
              rc=0
              echo "Running: $test"
              output=$(RUSTFLAGS="-C target-feature=+sse4.1,-avx,-avx2,-fma" \
              CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER="qemu-x86_64 -cpu Nehalem" SHORT_TEST=yes \
              cargo +nightly test --lib -- "$test" --exact 2>&1) || rc=$?
              echo "$output" | grep -E "FAILED|ok|signal 4"
              if [ "${rc:-0}" -ne 0 ]; then
                echo "❌ Test failed: $test"
                echo "$output"
                failed=1
              else
                echo "$output" | grep -E "ok|signal 4"
              fi
          done <<< "$tests"
          exit $failed

  tests_x86_avx2_isolated:
    name: Testing x86 AVX2 isolated (no FMA)
    runs-on: ubuntu-latest
    if: github.event_name == 'pull_request'
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@nightly
      - run: |
          sudo apt-get -y update
          sudo apt-get install -y qemu-user
      - run: |
          failed=0
          tests=$(cargo +nightly test --lib -- --list 2>/dev/null | grep ': test' | sed 's/: test//')
          while read -r test; do
              rc=0
              echo "Running: $test"
              output=$(RUSTFLAGS="-C target-feature=+avx2,-fma" \
              CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER="qemu-x86_64 -cpu Haswell-noTSX,avx2=on,fma=off" SHORT_TEST=yes \
              cargo +nightly test --lib --target x86_64-unknown-linux-gnu -- "$test" --exact 2>&1) || rc=$?
              echo "$output" | grep -E "FAILED|ok|signal 4"
              if [ "${rc:-0}" -ne 0 ]; then
                echo "❌ Test failed: $test"
                echo "$output"
                failed=1
              else
                echo "$output" | grep -E "ok|signal 4"
              fi
          done <<< "$tests"
          exit $failed

  python_bindings:
    name: Python bindings
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@stable
      - uses: actions/setup-python@v5
        with:
          python-version: '3.12'
      - name: Create venv and install dependencies
        run: |
          python -m venv pxdct-py/.venv
          pxdct-py/.venv/bin/pip install --upgrade pip
          pxdct-py/.venv/bin/pip install maturin pytest numpy
      - name: Build and install pxdct
        working-directory: pxdct-py
        run: .venv/bin/maturin develop --release
      - name: Run Python tests
        working-directory: pxdct-py
        run: .venv/bin/pytest tests/test_pxdct.py -v