name: Build Wheels

on:
  workflow_call:
    inputs:
      upload-name-suffix:
        description: "Suffix for artifact names (e.g., 'ci' or 'release')"
        required: false
        default: ""
        type: string

jobs:
  # Linux x86_64 (glibc)
  linux-x86_64:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Build wheels
        uses: PyO3/maturin-action@v1
        with:
          target: x86_64
          args: --release --out dist --features python
          sccache: "true"
          manylinux: auto
          before-script-linux: |
            yum install -y fontconfig-devel

      - name: Upload wheels
        uses: actions/upload-artifact@v4
        with:
          name: wheels-linux-x86_64${{ inputs.upload-name-suffix }}
          path: dist

  # Linux aarch64 (glibc)
  linux-aarch64:
    runs-on: ubuntu-24.04-arm
    steps:
      - uses: actions/checkout@v4

      - name: Build wheels
        uses: PyO3/maturin-action@v1
        with:
          args: --release --out dist --features python
          sccache: "true"
          manylinux: auto
          before-script-linux: |
            yum install -y fontconfig-devel

      - name: Upload wheels
        uses: actions/upload-artifact@v4
        with:
          name: wheels-linux-aarch64${{ inputs.upload-name-suffix }}
          path: dist

  # macOS (x86_64 and aarch64)
  macos:
    runs-on: macos-latest
    strategy:
      matrix:
        target: [x86_64, aarch64]
    steps:
      - uses: actions/checkout@v4

      - name: Build wheels
        uses: PyO3/maturin-action@v1
        with:
          target: ${{ matrix.target }}
          args: --release --out dist --features python
          sccache: "true"

      - name: Upload wheels
        uses: actions/upload-artifact@v4
        with:
          name: wheels-macos-${{ matrix.target }}${{ inputs.upload-name-suffix }}
          path: dist

  # Source distribution
  sdist:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Build sdist
        uses: PyO3/maturin-action@v1
        with:
          command: sdist
          args: --out dist

      - name: Upload sdist
        uses: actions/upload-artifact@v4
        with:
          name: wheels-sdist${{ inputs.upload-name-suffix }}
          path: dist
