name: Native Rust workspace compile

on:
  push:
    paths:
      - ".gitea/workflows/rust-workspace.yml"
      - "tools/install_openjpeg_2_5_4.sh"
      - "tools/check_milestone_09.py"
      - "tools/test_milestone_09.py"
      - "tools/check_milestone_10_issue_76.py"
      - "tools/check_milestone_10_issue_77.py"
      - "tools/check_milestone_10_issue_78.py"
      - "tools/check_milestone_10_issue_79.py"
      - "tools/check_milestone_10_issue_80.py"
      - "tools/check_milestone_10_issue_81.py"
      - "tools/check_milestone_10_issue_82.py"
      - "tools/check_milestone_10_issue_83.py"
      - "tools/check_milestone_10.py"
      - "tools/test_milestone_10.py"
      - "tools/generate_lsl_tables.py"
      - "codegen/inputs/lsl_tools_grammar.json"
      - "docs/extension-milestone-gate.md"
      - "docs/live-grid-smoke.md"
      - "programs/README.md"
      - "api/SHIM-COVERAGE.md"
      - "**/*.rs"
      - "**/Cargo.toml"
      - "Cargo.lock"
  pull_request:
    paths:
      - ".gitea/workflows/rust-workspace.yml"
      - "tools/install_openjpeg_2_5_4.sh"
      - "tools/check_milestone_09.py"
      - "tools/test_milestone_09.py"
      - "tools/check_milestone_10_issue_76.py"
      - "tools/check_milestone_10_issue_77.py"
      - "tools/check_milestone_10_issue_78.py"
      - "tools/check_milestone_10_issue_79.py"
      - "tools/check_milestone_10_issue_80.py"
      - "tools/check_milestone_10_issue_81.py"
      - "tools/check_milestone_10_issue_82.py"
      - "tools/check_milestone_10_issue_83.py"
      - "tools/check_milestone_10.py"
      - "tools/test_milestone_10.py"
      - "tools/generate_lsl_tables.py"
      - "codegen/inputs/lsl_tools_grammar.json"
      - "docs/extension-milestone-gate.md"
      - "docs/live-grid-smoke.md"
      - "programs/README.md"
      - "api/SHIM-COVERAGE.md"
      - "**/*.rs"
      - "**/Cargo.toml"
      - "Cargo.lock"
  workflow_dispatch:

jobs:
  compile:
    runs-on: ubuntu-latest
    env:
      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
      CARGO_BUILD_JOBS: 1
      CARGO_INCREMENTAL: 0
      CARGO_PROFILE_DEV_DEBUG: 0
      CARGO_PROFILE_TEST_DEBUG: 0
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy
      - name: Install audited OpenJPEG 2.5.4
        run: |
          sudo apt-get update
          sudo apt-get install --yes build-essential cmake pkg-config libopus-dev libasound2-dev
          tools/install_openjpeg_2_5_4.sh "$OPENJPEG_PREFIX"
      - name: Check formatting
        run: cargo fmt --all -- --check
      - name: Audit native implementation boundaries
        run: |
          python3 tools/check_milestone_09_issue_59.py
          python3 tools/check_milestone_09_issue_60.py
          python3 tools/check_milestone_09_issue_61.py
          python3 tools/check_milestone_09_issue_62.py
          python3 tools/check_milestone_09_issue_63.py
          python3 tools/check_milestone_09_issue_64.py
          python3 tools/check_milestone_09_issue_65.py
          python3 tools/check_milestone_09_issue_66.py
          python3 tools/check_milestone_09.py
          python3 tools/check_milestone_10_issue_76.py
          python3 tools/check_milestone_10_issue_77.py
          python3 tools/check_milestone_10_issue_78.py
          python3 tools/check_milestone_10_issue_79.py
          python3 tools/check_milestone_10_issue_80.py
          python3 tools/check_milestone_10_issue_81.py
          python3 tools/check_milestone_10_issue_82.py
          python3 tools/check_milestone_10_issue_83.py
          python3 tools/generate_lsl_tables.py --check
          python3 tools/check_milestone_10.py
      - name: Test the complete native world milestone
        run: python3 tools/test_milestone_09.py
      - name: Test the complete native extension milestone
        run: python3 tools/test_milestone_10.py
      - name: Compile every workspace target with bounded memory
        run: cargo check --workspace --all-targets --locked -j 1
      - name: Audit and fake-smoke every native program target
        run: |
          cargo run -p libremetaverse-programs --bin live-grid-smoke --locked -- --audit-only
          cargo test -p libremetaverse-programs --test live_grid_smoke_cli --locked -j 1
      - name: Check optional cross-platform real audio backend
        run: |
          cargo check -p libremetaverse-voice-webrtc --all-targets --features real-audio --locked -j 1
          cargo check -p libremetaverse-programs --bin webrtc-test --features real-audio --locked -j 1
      - name: Lint every native extension target with bounded memory
        run: cargo clippy -p libremetaverse-rendering-simple -p libremetaverse-rendering-mesh-foundry -p libremetaverse-rlv -p libremetaverse-lsl-tools --all-targets --locked -j 1 -- -D warnings
      - name: Document every native extension crate
        env:
          RUSTDOCFLAGS: -D warnings
        run: cargo doc -p libremetaverse-rendering-simple -p libremetaverse-rendering-mesh-foundry -p libremetaverse-rlv -p libremetaverse-lsl-tools --no-deps --locked -j 1
