name: PyPI Build

on: [workflow_dispatch]

jobs:

  build_windows_all:
    name: Build windows wheels
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python 3.x
        uses: actions/setup-python@v5
        with:
          python-version: '3.x'
      - name: Install cibuildwheel
        run: python -m pip install cibuildwheel==2.21.3
      - name: Build wheels
        run: python -m cibuildwheel --output-dir wheelhouse
        env:
          CIBW_BUILD_VERBOSITY: 1
          CIBW_BUILD: "cp37-* cp38-* cp39-* cp310-* cp311-* cp312-* cp313-*"
          CIBW_SKIP: "*-win32 pp*"
          CIBW_ARCHS_WINDOWS: "AMD64 ARM64"
      - name: Archive wheels
        uses: actions/upload-artifact@v4
        with:
          name: windows-all-wheels
          path: ./wheelhouse/*.whl
  
  build_macos_intel:
    name: Build macos-intel wheels
    runs-on: macos-13
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python 3.x
        uses: actions/setup-python@v5
        with:
          python-version: '3.x'
      - name: Install cibuildwheel
        run: python -m pip install cibuildwheel==2.21.3
      - name: Build wheels
        run: python -m cibuildwheel --output-dir wheelhouse
        env:
          CIBW_BUILD_VERBOSITY: 1
          CIBW_BUILD: "cp37-* cp38-* cp39-* cp310-* cp311-* cp312-* cp313-*"
          CIBW_SKIP: "pp*"
          CIBW_ARCHS_MACOS: "x86_64"
      - name: Archive wheels
        uses: actions/upload-artifact@v4
        with:
          name: macos-intel-wheels
          path: ./wheelhouse/*.whl

  build_macos_arm:
    name: Build macos-arm wheels
    runs-on: macos-14
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python 3.x
        uses: actions/setup-python@v5
        with:
          python-version: '3.x'
      - name: Install cibuildwheel
        run: python -m pip install cibuildwheel==2.21.3
      - name: Build wheels
        run: python -m cibuildwheel --output-dir wheelhouse
        env:
          CIBW_BUILD_VERBOSITY: 1
          CIBW_BUILD: "cp37-* cp38-* cp39-* cp310-* cp311-* cp312-* cp313-*"
          CIBW_SKIP: "pp*"
          CIBW_ARCHS_MACOS: "arm64"
      - name: Archive wheels
        uses: actions/upload-artifact@v4
        with:
          name: macos-arm-wheels
          path: ./wheelhouse/*.whl

  build_linux_intel:
    name: Build linux-intel wheels
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python 3.x
        uses: actions/setup-python@v5
        with:
          python-version: '3.x'
      - name: Install cibuildwheel
        run: python -m pip install cibuildwheel==2.21.3
      - name: Build wheels
        run: python -m cibuildwheel --output-dir wheelhouse
        env:
          CIBW_BUILD_VERBOSITY: 1
          CIBW_BUILD: "cp37-* cp38-* cp39-* cp310-* cp311-* cp312-* cp313-*"
          CIBW_SKIP: "*-manylinux_i686 pp*"
          CIBW_ARCHS_LINUX: "x86_64"
      - name: Archive wheels
        uses: actions/upload-artifact@v4
        with:
          name: linux-intel-wheels
          path: ./wheelhouse/*.whl

  build_linux_arm:
    name: Build linux-arm wheels
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3
        with:
          platforms: arm64
      - name: Build wheels
        uses: pypa/cibuildwheel@v2.21.3
        env:
          CIBW_BUILD_VERBOSITY: 1
          CIBW_BUILD: "cp37-* cp38-* cp39-* cp310-* cp311-* cp312-* cp313-*"
          CIBW_ARCHS_LINUX: "aarch64"
      - name: Archive wheels
        uses: actions/upload-artifact@v4
        with:
          name: linux-arm-wheels
          path: ./wheelhouse/*.whl

  build_source:
    name: Build source distribution
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python 3.x
        uses: actions/setup-python@v5
        with:
          python-version: '3.x'
      - name: Install requirements
        run: |
          pip install "setuptools>=67.2.0"
          pip install wheel build
      - name: Build .tar.gz
        run: python -m build --sdist
      - name: Archive .tar.gz
        uses: actions/upload-artifact@v4
        with:
          name: source-dist
          path: dist/*.tar.gz
