name: Rust

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

env:
  CARGO_TERM_COLOR: always

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - name: Setup sccache
      if: github.event_name != 'release' && github.event_name != 'workflow_dispatch'
      uses: mozilla-actions/sccache-action@v0.0.6
    - name: Configure sccache
      if: github.event_name != 'release' && github.event_name != 'workflow_dispatch'
      run: |
        echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV
        echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
    - name: Install build dependencies
      run: |
        sudo apt-get update
        sudo apt-get install -y cmake libjpeg-dev libfontconfig1-dev libopenjp2-7-dev libopenjpip7 libopenjp2-7 libglib2.0-dev libnss3-dev libunwind-dev libgoogle-perftools-dev libboost-dev
    - name: Build newer poppler
      run: |
        wget https://poppler.freedesktop.org/poppler-23.10.0.tar.xz
        tar xf poppler-23.10.0.tar.xz
        cd poppler-23.10.0
        mkdir build && cd build
        cmake .. -DCMAKE_BUILD_TYPE=Release \
             -DCMAKE_C_COMPILER_LAUNCHER=sccache \
             -DCMAKE_CXX_COMPILER_LAUNCHER=sccache \
             -DENABLE_UNSTABLE_API_ABI_HEADERS=ON \
             -DENABLE_GPGME=OFF \
             -DENABLE_QT5=OFF \
             -DENABLE_QT6=OFF \
             -DENABLE_SPLASH=OFF \
             -DENABLE_LIBCURL=OFF
        make -j$(nproc)
        sudo make install
        sudo ldconfig
    - uses: actions/checkout@v4
    - name: Clippy
      run: cargo clippy -- -D warnings
    - name: Check fmt
      run: cargo fmt -- --check
    - name: Run tests
      run: cargo test --benches -- adobe_example
    - name: Build
      run: cargo build
