name: JPEG 2000 feature

on:
  push:
    paths:
      - ".gitea/workflows/jpeg2000.yml"
      - "Cargo.toml"
      - "Cargo.lock"
      - "crates/libremetaverse/Cargo.toml"
      - "crates/libremetaverse-types/**"
      - "crates/libremetaverse-imaging/**"
      - "crates/libremetaverse-openjpeg/**"
      - "tools/install_openjpeg_2_5_4.sh"
  pull_request:
    paths:
      - ".gitea/workflows/jpeg2000.yml"
      - "Cargo.toml"
      - "Cargo.lock"
      - "crates/libremetaverse/Cargo.toml"
      - "crates/libremetaverse-types/**"
      - "crates/libremetaverse-imaging/**"
      - "crates/libremetaverse-openjpeg/**"
      - "tools/install_openjpeg_2_5_4.sh"
  workflow_dispatch:

jobs:
  linux:
    runs-on: ubuntu-latest
    env:
      # Ubuntu also ships an older libopenjp2.so.7. Ensure both pkg-config and
      # the runtime loader select this run's isolated, audited 2.5.4 install.
      OPENJPEG_PREFIX: /tmp/metacrate-openjpeg-${{ github.run_id }}
      PKG_CONFIG_PATH: /tmp/metacrate-openjpeg-${{ github.run_id }}/lib/pkgconfig
      LD_LIBRARY_PATH: /tmp/metacrate-openjpeg-${{ github.run_id }}/lib
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - name: Install OpenJPEG 2.5.4
        run: |
          sudo apt-get update
          sudo apt-get install --yes build-essential cmake pkg-config
          tools/install_openjpeg_2_5_4.sh "$OPENJPEG_PREFIX"
      - name: Build and test optional feature
        run: |
          cargo test -p libremetaverse-imaging --features jpeg2000
          cargo check -p libremetaverse --features jpeg2000
