diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml new file mode 100644 index 0000000000..aa375d7e50 --- /dev/null +++ b/.github/workflows/wheels.yml @@ -0,0 +1,111 @@ +name: Build Wheels + +on: + workflow_dispatch: + push: + tags: + - "*" + +jobs: + build_macos_wheels: + name: Build wheels on ${{matrix.os}}-${{matrix.arch}} + runs-on: ${{matrix.os}} + strategy: + fail-fast: false + matrix: + include: + - {os: macos-13, arch: x86_64, build: "*"} + - {os: macos-14, arch: arm64, build: "*"} + + steps: + - uses: actions/checkout@v4 + with: + submodules: "recursive" + + - name: Build wheels + uses: pypa/cibuildwheel@v2.17.0 + if: matrix.arch == 'arm64' + env: + CIBW_ARCHS: ${{ matrix.arch }} + CIBW_BUILD: ${{ matrix.build }} + CIBW_BUILD_FRONTEND: build + CIBW_ENVIRONMENT_MACOS: CMAKE_ARGS='-DLLAMA_METAL=on' DYLD_LIBRARY_PATH="$(pwd)/llama_cpp" + with: + config-file: ./pyproject.toml + + - name: Build wheels + uses: pypa/cibuildwheel@v2.17.0 + if: matrix.arch == 'x86_64' + env: + CIBW_ARCHS: ${{ matrix.arch }} + CIBW_BUILD: ${{ matrix.build }} + CIBW_BUILD_FRONTEND: build + CIBW_ENVIRONMENT_MACOS: CMAKE_ARGS='-DLLAMA_METAL=off' DYLD_LIBRARY_PATH="$(pwd)/llama_cpp" + with: + config-file: ./pyproject.toml + + + - uses: actions/upload-artifact@v4 + with: + name: cibw-wheels-${{matrix.os}}-${{matrix.arch}}-${{strategy.job-index}} + path: ./wheelhouse/*.whl + + + build_linux_wheels: + name: Build wheels on ${{matrix.os}}-${{matrix.arch}} + runs-on: ${{matrix.os}} + strategy: + fail-fast: true + matrix: + include: + - {os: ubuntu-latest, arch: x86_64, build: "*"} + - {os: ubuntu-latest, arch: aarch64, build: "*[61]-manylinux_aarch64"} + - {os: ubuntu-latest, arch: aarch64, build: "*[72]-manylinux_aarch64"} + - {os: ubuntu-latest, arch: aarch64, build: "*[83]-manylinux_aarch64"} + - {os: ubuntu-latest, arch: aarch64, build: "*[94]-manylinux_aarch64"} + - {os: ubuntu-latest, arch: aarch64, build: "*[05]-manylinux_aarch64"} + + steps: + - uses: actions/checkout@v4 + with: + submodules: "recursive" + + - name: Set up QEMU + if: matrix.arch == 'aarch64' + uses: docker/setup-qemu-action@v3 + with: + platforms: arm64 + + - name: Build wheels + uses: pypa/cibuildwheel@v2.17.0 + env: + CIBW_ARCHS: ${{ matrix.arch }} + CIBW_BUILD: ${{ matrix.build }} + CIBW_BUILD_FRONTEND: build + CIBW_SKIP: '*-musllinux*' + with: + config-file: ./pyproject.toml + + + - uses: actions/upload-artifact@v4 + with: + name: cibw-wheels-${{matrix.os}}-${{matrix.arch}}-${{strategy.job-index}} + path: ./wheelhouse/*.whl + + + build_sdist: + name: Build source distribution + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + submodules: "recursive" + + - name: Build sdist + run: pipx run build --sdist + + - uses: actions/upload-artifact@v4 + with: + name: cibw-sdist + path: dist/*.tar.gz diff --git a/.gitignore b/.gitignore index 9d68dbcd9d..c2321418c6 100644 --- a/.gitignore +++ b/.gitignore @@ -42,6 +42,7 @@ share/python-wheels/ .installed.cfg *.egg MANIFEST +wheelhouse/ # PyInstaller # Usually these files are written by a python script from a template @@ -178,3 +179,4 @@ cython_debug/ # downloaded model .bin files docker/open_llama/*.bin +install/ diff --git a/pyproject.toml b/pyproject.toml index 2f3d3ced0f..c712057081 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ requires = ["scikit-build-core[pyproject]>=0.5.1"] build-backend = "scikit_build_core.build" [project] -name = "llama_cpp_python" +name = "llama_cpp_python-cross" dynamic = ["version"] description = "Python bindings for the llama.cpp library" readme = "README.md" @@ -73,3 +73,23 @@ Changelog = "https://llama-cpp-python.readthedocs.io/en/latest/changelog/" [tool.pytest.ini_options] testpaths = "tests" + +[tool.cibuildwheel] +before-all = "uname -a" + +[tool.cibuildwheel.linux] +manylinux-aarch64-image = "quay.io/pypa/manylinux_2_28_aarch64:latest" +manylinux-x86_64-image = "quay.io/pypa/manylinux_2_28_x86_64:latest" +before-all = [ + "uname -a", + "yum install -y wget openblas-devel", + "wget https://dl.fedoraproject.org/pub/epel/8/Everything/$(uname -m)/Packages/c/ccache-3.7.7-1.el8.$(uname -m).rpm", + "rpm -Uvh *.rpm", + "dnf install -y ccache", +] + +[tool.cibuildwheel.linux.environment] +LIBRARY_PATH = "/project/llama_cpp" +LD_LIBRARY_PATH = "/project/llama_cpp" +RUNPATH = "/project/llama_cpp" +CMAKE_ARGS = "-DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=OpenBLAS"