Files
LEANN/.github/workflows/build-cibuildwheel.yml
Andy Lee 3c8d32f156 fix: prevent pyzmq compilation during tests
- Cap pyzmq version to <27 for manylinux2014 compatibility
- Pre-install pyzmq binary wheel before tests using CIBW_BEFORE_TEST
- Force pip to use only binary wheels with --only-binary :all:
2025-07-25 11:35:31 -07:00

173 lines
6.1 KiB
YAML

name: Build with cibuildwheel
on:
workflow_call:
inputs:
ref:
description: 'Git ref to build'
required: false
type: string
default: ''
jobs:
build_wheels:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
submodules: recursive
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
# Build pure Python packages separately
- name: Build pure Python packages (leann-core, leann)
if: matrix.os == 'ubuntu-latest' # Only build once
run: |
python -m pip install --upgrade pip build
python -m build packages/leann-core --outdir wheelhouse/
python -m build packages/leann --outdir wheelhouse/
- name: Build leann-backend-hnsw wheels
uses: pypa/cibuildwheel@v2.20.0
with:
package-dir: packages/leann-backend-hnsw
output-dir: wheelhouse
env:
CIBW_BUILD: cp39-* cp310-* cp311-* cp312-* cp313-*
CIBW_SKIP: "*-win32 *-manylinux_i686 pp* *musllinux*"
# 使用manylinux2014生成兼容性更好的wheels
CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014
CIBW_MANYLINUX_AARCH64_IMAGE: manylinux2014
# Linux dependencies - 使用yum因为manylinux2014基于CentOS 7
CIBW_BEFORE_ALL_LINUX: |
yum install -y epel-release
yum install -y gcc-c++ boost-devel zeromq-devel openblas-devel cmake3
ln -sf /usr/bin/cmake3 /usr/bin/cmake
# Install numpy before building
CIBW_BEFORE_BUILD: |
pip install numpy
pip install --upgrade pip setuptools wheel
CIBW_BEFORE_BUILD_LINUX: |
pip install numpy
pip install --upgrade pip setuptools wheel swig
CIBW_BEFORE_ALL_MACOS: |
brew install boost zeromq openblas cmake libomp
# Pre-install test dependencies to avoid compilation
CIBW_BEFORE_TEST: |
pip install --only-binary :all: "pyzmq>=23.0.0,<27"
# Test command to verify the wheel works
CIBW_TEST_COMMAND: |
python -c "import leann_backend_hnsw; print('HNSW backend imported successfully')"
# Skip problematic configurations
CIBW_TEST_SKIP: "*-macosx_arm64" # Skip ARM64 tests on GitHub Actions
# Test dependencies
CIBW_TEST_REQUIRES: "pytest numpy"
# Environment variables for build
CIBW_ENVIRONMENT: |
CMAKE_BUILD_PARALLEL_LEVEL=8
Python_FIND_VIRTUALENV=ONLY
Python3_FIND_VIRTUALENV=ONLY
# Linux-specific environment variables
CIBW_ENVIRONMENT_LINUX: |
CMAKE_BUILD_PARALLEL_LEVEL=8
# macOS-specific environment variables
CIBW_ENVIRONMENT_MACOS: |
CMAKE_BUILD_PARALLEL_LEVEL=8
MACOSX_DEPLOYMENT_TARGET=11.0
CMAKE_OSX_DEPLOYMENT_TARGET=11.0
Python_FIND_VIRTUALENV=ONLY
Python3_FIND_VIRTUALENV=ONLY
- name: Build leann-backend-diskann wheels
uses: pypa/cibuildwheel@v2.20.0
with:
package-dir: packages/leann-backend-diskann
output-dir: wheelhouse
env:
CIBW_BUILD: cp39-* cp310-* cp311-* cp312-* cp313-*
CIBW_SKIP: "*-win32 *-manylinux_i686 pp* *musllinux*"
CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014
CIBW_MANYLINUX_AARCH64_IMAGE: manylinux2014
CIBW_BEFORE_ALL_LINUX: |
yum install -y epel-release
yum install -y gcc-c++ boost-devel zeromq-devel openblas-devel cmake3
ln -sf /usr/bin/cmake3 /usr/bin/cmake
# Install numpy before building
CIBW_BEFORE_BUILD: |
pip install numpy
pip install --upgrade pip setuptools wheel
CIBW_BEFORE_BUILD_LINUX: |
pip install numpy
pip install --upgrade pip setuptools wheel swig
CIBW_BEFORE_ALL_MACOS: |
brew install boost zeromq openblas cmake libomp
# Pre-install test dependencies to avoid compilation
CIBW_BEFORE_TEST: |
pip install --only-binary :all: "pyzmq>=23.0.0,<27"
# Test command to verify the wheel works
CIBW_TEST_COMMAND: |
python -c "import leann_backend_diskann; print('DiskANN backend imported successfully')"
# Skip problematic configurations
CIBW_TEST_SKIP: "*-macosx_arm64" # Skip ARM64 tests on GitHub Actions
# Test dependencies - avoid pyzmq due to manylinux2014 compatibility issues
CIBW_TEST_REQUIRES: "pytest numpy"
CIBW_ENVIRONMENT: |
CMAKE_BUILD_PARALLEL_LEVEL=8
Python_FIND_VIRTUALENV=ONLY
Python3_FIND_VIRTUALENV=ONLY
# Linux-specific environment variables
CIBW_ENVIRONMENT_LINUX: |
CMAKE_BUILD_PARALLEL_LEVEL=8
CMAKE_PREFIX_PATH=$VIRTUAL_ENV
Python_FIND_VIRTUALENV=ONLY
Python3_FIND_VIRTUALENV=ONLY
Python_FIND_STRATEGY=LOCATION
Python3_FIND_STRATEGY=LOCATION
Python_EXECUTABLE=$VIRTUAL_ENV/bin/python
Python3_EXECUTABLE=$VIRTUAL_ENV/bin/python
# macOS-specific environment variables
CIBW_ENVIRONMENT_MACOS: |
CMAKE_BUILD_PARALLEL_LEVEL=8
MACOSX_DEPLOYMENT_TARGET=11.0
CMAKE_OSX_DEPLOYMENT_TARGET=11.0
Python_FIND_VIRTUALENV=ONLY
Python3_FIND_VIRTUALENV=ONLY
- uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.os }}
path: ./wheelhouse/*.whl