Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pip packaging workflow to GHA #6938

Merged
merged 19 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
198 changes: 198 additions & 0 deletions .github/workflows/pip.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
# 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 ]
release:
types: [ created ]

concurrency:
group: '${{ github.workflow }}-${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
cancel-in-progress: true

env:
LLVM_VER: 15.0.1

jobs:
pip-linux:
name: Package Halide Python bindings

runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
arch: [ x86_64, 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:${{ env.LLVM_VER }}
# CIBW_MANYLINUX_I686_IMAGE: ghcr.io/halide/manylinux2014_i686-llvm:${{ env.LLVM_VER }}
CIBW_MANYLINUX_AARCH64_IMAGE: ghcr.io/halide/manylinux2014_aarch64-llvm:${{ env.LLVM_VER }}
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:
name: wheels
path: ./wheelhouse/*.whl

pip-other:
name: Package Halide Python bindings

runs-on: ${{ matrix.runner }}

env:
CMAKE_PREFIX_PATH: ${{ github.workspace }}/local

strategy:
fail-fast: false
matrix:
include:
- runner: windows-latest
pytag: win_amd64
arch: x64

- runner: macos-latest
pytag: macosx_universal2
arch: x86_64;arm64

steps:
- uses: actions/checkout@v3

- name: Cache LLVM build folder
id: cache-llvm
uses: actions/cache@v3
with:
path: local
key: llvmorg-${{ env.LLVM_VER }}-${{ runner.os }}

- uses: ilammy/msvc-dev-cmd@v1
- uses: lukka/get-cmake@latest

- uses: actions/checkout@v3
if: steps.cache-llvm.outputs.cache-hit != 'true'
with:
repository: llvm/llvm-project
ref: llvmorg-${{ env.LLVM_VER }}

- name: Configure LLVM
if: steps.cache-llvm.outputs.cache-hit != 'true'
run: >
cmake -G Ninja -S llvm -B build
-DCMAKE_BUILD_TYPE=Release
"-DCMAKE_OSX_ARCHITECTURES=arm64;x86_64"
"-DLLVM_TARGETS_TO_BUILD=X86;ARM;NVPTX;AArch64;Mips;Hexagon;WebAssembly"
"-DLLVM_ENABLE_PROJECTS=clang;lld"
-DLLVM_ENABLE_ASSERTIONS=ON
-DLLVM_ENABLE_RTTI=ON
-DLLVM_ENABLE_EH=ON
-DLLVM_ENABLE_LIBXML2=OFF
-DLLVM_ENABLE_TERMINFO=OFF
-DLLVM_ENABLE_ZSTD=OFF
-DLLVM_ENABLE_ZLIB=OFF

- name: Build LLVM
if: steps.cache-llvm.outputs.cache-hit != 'true'
run: cmake --build build

- name: Install LLVM
if: steps.cache-llvm.outputs.cache-hit != 'true'
run: cmake --install build --prefix local

- name: Configure Halide
if: runner.os == 'Windows'
run: >
cmake -G "Visual Studio 17 2022" -T ClangCL -A "${{ matrix.arch }}" -S . -B build
-DWITH_DOCS=NO
-DWITH_PYTHON_BINDINGS=NO
-DWITH_TESTS=NO
-DWITH_TUTORIALS=NO
-DWITH_UTILS=NO

- name: Configure Halide
if: runner.os != 'Windows'
run: >
cmake -G Ninja -S . -B build
-DCMAKE_BUILD_TYPE=Release
"-DCMAKE_OSX_ARCHITECTURES=${{ matrix.arch }}"
-DWITH_DOCS=NO
-DWITH_PYTHON_BINDINGS=NO
-DWITH_TESTS=NO
-DWITH_TUTORIALS=NO
-DWITH_UTILS=NO

- name: Build Halide
run: cmake --build build --config Release

- name: Install Halide
run: cmake --install build --config Release --prefix local

- name: Build wheels
uses: pypa/cibuildwheel@v2.10.2
env:
CIBW_BUILD: "cp38-${{ matrix.pytag }} cp39-${{ matrix.pytag }} cp310-${{ matrix.pytag }}"
CIBW_ARCHS_MACOS: "universal2"

- uses: actions/upload-artifact@v3
with:
name: wheels
path: ./wheelhouse/*.whl

pip-sdist:
name: Make SDist
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: pipx run build --sdist
- uses: actions/upload-artifact@v3
with:
name: wheels
path: dist/*.tar.gz

publish:
name: Publish on PyPI
needs: [ pip-linux, pip-other, pip-sdist ]
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v3
with:
name: wheels
path: dist

- uses: pypa/gh-action-pypi-publish@v1.5.1
with:
user: __token__
password: ${{ secrets.TEST_PYPI_TOKEN }}
repository_url: https://test.pypi.org/legacy/

- uses: pypa/gh-action-pypi-publish@v1.5.1
if: github.event_name == 'release' && github.event.action == 'published'
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
graft python_bindings
prune python_bindings/test
prune python_bindings/tutorial
19 changes: 11 additions & 8 deletions packaging/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,18 @@ else ()
set(rbase $ORIGIN)
endif ()

if (TARGET Halide_Adams2019)
set(autoscheduler_utils adams2019_retrain_cost_model adams2019_featurization_to_sample adams2019_get_host_target adams2019_weightsdir_to_weightsfile)
if (NOT CMAKE_INSTALL_RPATH)
set_target_properties(${autoscheduler_utils} PROPERTIES INSTALL_RPATH "${rbase};${rbase}/${lib_dir}")
endif ()
install(TARGETS ${autoscheduler_utils}
foreach (util IN ITEMS adams2019_retrain_cost_model adams2019_featurization_to_sample adams2019_get_host_target adams2019_weightsdir_to_weightsfile)
if (TARGET ${util})
if (NOT CMAKE_INSTALL_RPATH)
set_target_properties(${util} PROPERTIES INSTALL_RPATH "${rbase};${rbase}/${lib_dir}")
endif ()
install(
TARGETS ${util}
EXPORT Halide_Interfaces
COMPONENT Halide_Development)
endif ()
COMPONENT Halide_Development
)
endif ()
endforeach ()

##
# READMEs and other top-level documentation
Expand Down
2 changes: 1 addition & 1 deletion python_bindings/pyproject.toml → pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[build-system]
requires = [
"setuptools>=42",
"setuptools>=43",
"wheel",
"scikit-build",
"pybind11==2.6.2",
Expand Down
14 changes: 0 additions & 14 deletions python_bindings/requirements.txt

This file was deleted.

55 changes: 0 additions & 55 deletions python_bindings/setup.py

This file was deleted.

11 changes: 11 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import pybind11
from setuptools import find_packages
from skbuild import setup
from pathlib import Path

this_directory = Path(__file__).parent
long_description = (this_directory / "README.md").read_text()

setup(
name="halide",
version='15.0.0',
author="The Halide team",
author_email="halide-dev@lists.csail.mit.edu",
description="Halide is a programming language designed to make it easier "
"to write high-performance image and array processing code.",
long_description=long_description,
long_description_content_type='text/markdown',
python_requires=">=3.8",
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=$<IF:$<PLATFORM_ID:Darwin>,@loader_path,$ORIGIN>",
"-DHalide_Python_INSTALL_IMPORTED_DEPS=ON",
"-DWITH_TESTS=NO",
"-DWITH_TUTORIALS=NO",
"--no-warn-unused-cli",
],
)