name: Build Cross (Linux ARM64)

on:
  workflow_call:
  workflow_dispatch:

env:
  CARGO_TERM_COLOR: always

jobs:
  build:
    runs-on: ubuntu-latest
    timeout-minutes: 60

    steps:
      - uses: actions/checkout@v4
        with:
          submodules: recursive

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: aarch64-unknown-linux-gnu

      - name: Cache Rust dependencies
        uses: Swatinem/rust-cache@v2
        with:
          key: aarch64-unknown-linux-gnu

      - name: Install cross
        run: cargo install cross --git https://github.com/cross-rs/cross

      - name: Build
        run: cross build --release --target aarch64-unknown-linux-gnu

      - name: Build desktop
        run: cross build --release --features desktop --bin cagire-desktop --target aarch64-unknown-linux-gnu

      - name: Upload CLI artifact
        uses: actions/upload-artifact@v4
        with:
          name: cagire-linux-aarch64
          path: target/aarch64-unknown-linux-gnu/release/cagire

      - name: Upload desktop artifact
        uses: actions/upload-artifact@v4
        with:
          name: cagire-linux-aarch64-desktop
          path: target/aarch64-unknown-linux-gnu/release/cagire-desktop
