diff --git a/.github/workflows/pip.yml b/.github/workflows/pip.yml new file mode 100644 index 000000000000..fcb0624c5505 --- /dev/null +++ b/.github/workflows/pip.yml @@ -0,0 +1,58 @@ +# Relevant GHA docs links: +# https://docs.github.com/en/actions/using-jobs/running-jobs-in-a-container +# https://docs.github.com/en/packages/managing-github-packages-using-github-actions-workflows/publishing-and-installing-a-package-with-github-actions#upgrading-a-workflow-that-accesses-ghcrio + +name: Build PyPI package + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +concurrency: + group: '${{ github.workflow }}-${{ github.event.pull_request.head.label || github.head_ref || github.ref }}' + cancel-in-progress: true + +jobs: + build-halide: + name: Build Halide + + runs-on: ubuntu-latest + + strategy: + matrix: + arch: [ x86_64, i686, aarch64 ] + + steps: + - uses: actions/checkout@v3 + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v2.0.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + with: + platforms: all + + - name: Build wheels + uses: pypa/cibuildwheel@v2.10.2 + env: + CIBW_ARCHS_LINUX: "${{ matrix.arch }}" + CIBW_BUILD: "cp38-manylinux* cp39-manylinux* cp310-manylinux*" + CIBW_MANYLINUX_X86_64_IMAGE: ghcr.io/halide/manylinux2014_x86_64-llvm:15.0.1 + CIBW_MANYLINUX_I686_IMAGE: ghcr.io/halide/manylinux2014_i686-llvm:15.0.1 + CIBW_MANYLINUX_AARCH64_IMAGE: ghcr.io/halide/manylinux2014_aarch64-llvm:15.0.1 + CIBW_BEFORE_ALL_LINUX: > + cmake -G Ninja -S . -B build + -DCMAKE_BUILD_TYPE=Release -DWITH_DOCS=NO -DWITH_PYTHON_BINDINGS=NO -DWITH_TESTS=NO + -DWITH_TUTORIALS=NO -DWITH_UTILS=NO && + cmake --build build --target install + + - uses: actions/upload-artifact@v3 + with: + path: ./wheelhouse/*.whl diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 000000000000..24fda740b1b6 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,3 @@ +graft python_bindings +prune python_bindings/test +prune python_bindings/tutorial diff --git a/build-wheels.sh b/build-wheels.sh new file mode 100755 index 000000000000..ada6f0863773 --- /dev/null +++ b/build-wheels.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +export CIBW_PLATFORM=linux + +export CIBW_ARCHS="x86_64 i686 aarch64" +export CIBW_BUILD="cp38-manylinux* cp39-manylinux* cp310-manylinux*" + +export CIBW_MANYLINUX_X86_64_IMAGE=ghcr.io/halide/manylinux2014_x86_64-llvm:15.0.1 +export CIBW_MANYLINUX_I686_IMAGE=ghcr.io/halide/manylinux2014_i686-llvm:15.0.1 +export CIBW_MANYLINUX_AARCH64_IMAGE=ghcr.io/halide/manylinux2014_aarch64-llvm:15.0.1 + +export CIBW_BEFORE_ALL="\ + cmake -G Ninja -S . -B build -DCMAKE_BUILD_TYPE=Release -DWITH_DOCS=NO -DWITH_PYTHON_BINDINGS=NO -DWITH_TESTS=NO \ + -DWITH_TUTORIALS=NO -DWITH_UTILS=NO && \ + cmake --build build --target install" + +cibuildwheel --print-build-identifiers diff --git a/python_bindings/pyproject.toml b/pyproject.toml similarity index 89% rename from python_bindings/pyproject.toml rename to pyproject.toml index e3a89e6d5ef2..8d3ba8ac1e9f 100644 --- a/python_bindings/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [build-system] requires = [ - "setuptools>=42", + "setuptools>=43", "wheel", "scikit-build", "pybind11==2.6.2", diff --git a/python_bindings/requirements.txt b/python_bindings/requirements.txt deleted file mode 100644 index 662a45cfe3be..000000000000 --- a/python_bindings/requirements.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This file lists the python dependencies, -# it is meant to be used with pip (and/or possibly virtualenv, pbundler, etc) -# See http://pip.readthedocs.org/en/latest/user_guide.html#requirements-files -# You will probably want to run -# something similar to `pip3 install --user -r requirements.txt` - -# science packages -imageio -numpy -pillow -scipy - -# Choose a specific version for pybind11 -pybind11==2.6.2 diff --git a/python_bindings/setup.py b/python_bindings/setup.py deleted file mode 100644 index 9445aaab8bc5..000000000000 --- a/python_bindings/setup.py +++ /dev/null @@ -1,55 +0,0 @@ -from skbuild import setup, cmaker, utils -from setuptools import find_packages -from pathlib import Path -import pybind11 -from tempfile import TemporaryDirectory as mkdtemp_ctx -import textwrap - - -def get_version(): - """ - Builds a dummy project that prints the found Halide version. The "version" - of these Halide bindings is whatever version of Halide they're building - against. - """ - - cmakelists_txt = textwrap.dedent( - """ - cmake_minimum_required(VERSION 3.22) - project(dummy) - find_package(Halide REQUIRED Halide) - file(WRITE halide_version.txt "${Halide_VERSION}") - """ - ) - - with mkdtemp_ctx() as srcdir, mkdtemp_ctx() as dstdir: - src, dst = Path(srcdir), Path(dstdir) - (src / "CMakeLists.txt").write_text(cmakelists_txt) - with utils.push_dir(dst): - cmkr = cmaker.CMaker() - cmkr.configure(cmake_source_dir=src, clargs=("--no-warn-unused-cli",)) - version = (src / "halide_version.txt").read_text().strip() - return version - - -setup( - name="halide", - version=get_version(), - author="The Halide team", - author_email="", - description="", - long_description="", - python_requires=">=3.6", - packages=find_packages(where="src"), - package_dir={"": "src"}, - cmake_args=[ - f"-Dpybind11_ROOT={pybind11.get_cmake_dir()}", - "-DCMAKE_REQUIRE_FIND_PACKAGE_pybind11=YES", - "-DHalide_INSTALL_PYTHONDIR=src", - "-DCMAKE_INSTALL_RPATH=$,@loader_path,$ORIGIN>", - "-DHalide_Python_INSTALL_IMPORTED_DEPS=ON", - "-DWITH_TESTS=NO", - "-DWITH_TUTORIALS=NO", - "--no-warn-unused-cli", - ], -) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 000000000000..4fa417a64d5d --- /dev/null +++ b/requirements.txt @@ -0,0 +1,11 @@ +cmake>=3.22 +imageio +ninja; platform_system!='Windows' +numpy +pillow +pybind11==2.6.2 +scikit-build +scipy +setuptools>=43 +wheel +build diff --git a/setup.py b/setup.py new file mode 100644 index 000000000000..382f82ffd3fd --- /dev/null +++ b/setup.py @@ -0,0 +1,26 @@ +import pybind11 +from setuptools import find_packages +from skbuild import setup + +setup( + name="halide", + version='15.0.0', + author="The Halide team", + author_email="", + description="", + long_description="", + python_requires=">=3.6", + packages=find_packages(where="python_bindings/src"), + package_dir={"": "python_bindings/src"}, + cmake_source_dir="python_bindings", + cmake_args=[ + f"-Dpybind11_ROOT={pybind11.get_cmake_dir()}", + "-DCMAKE_REQUIRE_FIND_PACKAGE_pybind11=YES", + "-DHalide_INSTALL_PYTHONDIR=python_bindings/src", + "-DCMAKE_INSTALL_RPATH=$,@loader_path,$ORIGIN>", + "-DHalide_Python_INSTALL_IMPORTED_DEPS=ON", + "-DWITH_TESTS=NO", + "-DWITH_TUTORIALS=NO", + "--no-warn-unused-cli", + ], +)