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

Setup build wheels using cibuildwheel for all systems #559

Merged
merged 22 commits into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,43 +120,6 @@ jobs:
(cd examples; rm -f gl_*)
run_examples --no-require-main

wheels:
name: Build and upload wheels
runs-on: ubuntu-latest
strategy:
matrix:
DOCKER_IMAGE:
- quay.io/pypa/manylinux2014_x86_64
# Disable i686 builds for now: no binary wheels for cryptography,
# source build fails, e.g. https://github.com/inducer/pyopencl/pull/421/checks?check_run_id=1781071632
# - quay.io/pypa/manylinux2014_i686
steps:
- uses: actions/checkout@v2
- name: "Main Script"
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
DOCKER_IMAGE: ${{ matrix.DOCKER_IMAGE }}

run: |
pwd
ls -la

# Only perform upload for tag builds, otherwise unset TWINE_USERNAME to prevent
if ! [[ $GITHUB_REF == refs/tags* ]]; then
echo "Not a tag build, GITHUB_REF is '$GITHUB_REF'. Unsetting TWINE_USERNAME"
unset TWINE_USERNAME
fi

if [[ $DOCKER_IMAGE == *i686* ]]; then
PRE_CMD=linux32
else
PRE_CMD=""
fi

docker run --rm -v `pwd`:/io -e TWINE_USERNAME -e TWINE_PASSWORD $DOCKER_IMAGE $PRE_CMD /io/scripts/build-wheels.sh
ls wheelhouse/

downstream_tests:
strategy:
matrix:
Expand Down
65 changes: 65 additions & 0 deletions .github/workflows/github-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Build and upload to PyPI
Czaki marked this conversation as resolved.
Show resolved Hide resolved

# Build on every branch push, tag push, and pull request change:
on:
push:
branches:
- main
tags:
- v*
pull_request:
schedule:
- cron: '17 3 * * 0'

jobs:
build_wheels:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04, windows-2019, macos-10.15]

steps:
- uses: actions/checkout@v3
with:
submodules: 'true'

- name: Build wheels
uses: pypa/[email protected]

- uses: actions/upload-artifact@v2
with:
path: ./wheelhouse/*.whl

build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Build sdist
run: pipx run build --sdist

- uses: actions/upload-artifact@v2
with:
path: dist/*.tar.gz

upload_pypi:
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
# upload to PyPI on every tag starting with 'v'
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
# alternatively, to publish when a GitHub Release is created, use the following rule:
# if: github.event_name == 'release' && github.event.action == 'published'
steps:
- uses: actions/download-artifact@v2
with:
name: artifact
path: dist

- uses: pypa/[email protected]
with:
user: __token__
password: ${{ secrets.TWINE_PASSWORD }}
# To test: repository_url: https://test.pypi.org/legacy/
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,5 @@ cffi_build.py
.cache
.pytest_cache
.idea

wheelhouse
31 changes: 31 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[build-system]
# Minimum requirements for the build system to execute.
requires = ["setuptools>=42.0.0", "wheel>=0.34.2", "Cython", "oldest-supported-numpy", "pybind11>=2.5.0", "Mako"] # PEP 508 specifications.
Czaki marked this conversation as resolved.
Show resolved Hide resolved
build-backend = "setuptools.build_meta"


[tool.cibuildwheel]
test-command = "pytest {project}/test"
test-extras = ["test"]

[tool.cibuildwheel.linux]
test-command = ""
skip = "*-musllinux*" # lack of opencl bindings. currently avaliable only on edge channel
before-all = [
"yum install -y git openssl-devel ruby",
"bash {package}/scripts/build-ocl.sh",
Czaki marked this conversation as resolved.
Show resolved Hide resolved
]

[[tool.cibuildwheel.overrides]]
select = "*-musllinux*"
before-all = "apk add ruby git openssl opencl-dev"

[tool.cibuildwheel.macos]
skip = "pp*"
before-all = "bash {package}/scripts/build-ocl-macos.sh"
test-command = "pytest {project}/test/test_array.py" # same limitation as conda-forge
Czaki marked this conversation as resolved.
Show resolved Hide resolved

[tool.cibuildwheel.windows]
skip = ["*-win32", "pp*"]
test-command = ""
before-all = "bash {package}/scripts/build-ocl-windows.sh"
19 changes: 19 additions & 0 deletions scripts/build-ocl-macos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

set -o xtrace

git clone https://github.com/KhronosGroup/OpenCL-ICD-Loader
cd OpenCL-ICD-Loader
git checkout aec3952654832211636fc4af613710f80e203b0a
cd ..
git clone https://github.com/KhronosGroup/OpenCL-Headers
cd OpenCL-Headers
git checkout dcd5bede6859d26833cd85f0d6bbcee7382dc9b3
cd ..


cmake -D CMAKE_INSTALL_PREFIX=./OpenCL-Headers/install -S ./OpenCL-Headers -B ./OpenCL-Headers/build
cmake --build ./OpenCL-Headers/build --target install

cmake -D CMAKE_PREFIX_PATH=${PWD}/OpenCL-Headers/install -D CMAKE_INSTALL_PREFIX=./OpenCL-ICD-Loader/install -S ./OpenCL-ICD-Loader -B ./OpenCL-ICD-Loader/build
cmake --build ./OpenCL-ICD-Loader/build --target install --config Release
Czaki marked this conversation as resolved.
Show resolved Hide resolved
18 changes: 18 additions & 0 deletions scripts/build-ocl-windows.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

set -o xtrace

git clone --branch v2022.01.04 https://github.com/KhronosGroup/OpenCL-ICD-Loader

git clone --branch v2022.01.04 https://github.com/KhronosGroup/OpenCL-Headers


cmake -D CMAKE_INSTALL_PREFIX=./OpenCL-Headers/install -S ./OpenCL-Headers -B ./OpenCL-Headers/build
cmake --build ./OpenCL-Headers/build --target install

# if someone would like to try to create win32 wheels bellow lines may be usefull
Czaki marked this conversation as resolved.
Show resolved Hide resolved
# cmake -D CMAKE_PREFIX_PATH=${PWD}/OpenCL-Headers/install -DOPENCL_ICD_LOADER_HEADERS_DIR=${PWD}/OpenCL-Headers/install/include -S ./OpenCL-ICD-Loader -B ./OpenCL-ICD-Loader/build
# cmake --build ./OpenCL-ICD-Loader/build --target install --config Release

cmake -D CMAKE_PREFIX_PATH=${PWD}/OpenCL-Headers/install -DOPENCL_ICD_LOADER_HEADERS_DIR=${PWD}/OpenCL-Headers/install/include -S ./OpenCL-ICD-Loader -B ./OpenCL-ICD-Loader/build2 -A x64
cmake --build ./OpenCL-ICD-Loader/build2 --target install --config Release
Czaki marked this conversation as resolved.
Show resolved Hide resolved
25 changes: 25 additions & 0 deletions scripts/build-ocl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

set -e -x

mkdir -p ~/deps
cd ~/deps

curl https://tiker.net/tmp/.tmux.conf

Czaki marked this conversation as resolved.
Show resolved Hide resolved
git clone --branch v2.3.0 https://github.com/OCL-dev/ocl-icd
Czaki marked this conversation as resolved.
Show resolved Hide resolved
cd ocl-icd
curl -L -O https://raw.githubusercontent.com/conda-forge/ocl-icd-feedstock/e2c03e3ddb1ff86630ccf80dc7b87a81640025ea/recipe/install-headers.patch
git apply install-headers.patch
curl -L -O https://github.com/isuruf/ocl-icd/commit/3862386b51930f95d9ad1089f7157a98165d5a6b.patch
git apply 3862386b51930f95d9ad1089f7157a98165d5a6b.patch
autoreconf -i
chmod +x configure
./configure --prefix=/usr
make -j4
make install

# Bundle license files
echo "PyOpenCL wheel includes ocl-icd which is licensed as below" >> ${SCRIPT_DIR}/../LICENSE
cat ~/deps/ocl-icd/COPYING >> ${SCRIPT_DIR}/../LICENSE
90 changes: 0 additions & 90 deletions scripts/build-wheels.sh

This file was deleted.

14 changes: 14 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import sys
from os.path import exists

sys.path.append(os.path.dirname(__file__))
inducer marked this conversation as resolved.
Show resolved Hide resolved


def get_config_schema():
from aksetup_helper import (ConfigSchema, Option,
Expand Down Expand Up @@ -76,6 +78,17 @@ def get_config_schema():
else:
default_ldflags = []

if os.environ.get("CIBUILDWHEEL", False) and sys.platform == "win32":
import struct

default_cxxflags.append("-ID:/a/pyopencl/pyopencl/OpenCL-Headers/install/include")
if struct.calcsize("P") == 8:
default_ldflags.append("/LIBPATH:C:/Program Files/OpenCL-ICD-Loader/lib")
default_ldflags.append("/LIBPATH:C:/Program Files/OpenCL-ICD-Loader/bin")
else:
default_ldflags.append("/LIBPATH:C:/Program Files (x86)/OpenCL-ICD-Loader/lib")
default_ldflags.append("/LIBPATH:C:/Program Files (x86)/OpenCL-ICD-Loader/bin")
inducer marked this conversation as resolved.
Show resolved Hide resolved
Czaki marked this conversation as resolved.
Show resolved Hide resolved

return ConfigSchema([
Switch("CL_TRACE", False, "Enable OpenCL API tracing"),
Switch("CL_ENABLE_GL", False, "Enable OpenCL<->OpenGL interoperability"),
Expand Down Expand Up @@ -263,6 +276,7 @@ def main():
extras_require={
"pocl": ["pocl_binary_distribution>=1.2"],
"oclgrind": ["oclgrind_binary_distribution>=18.3"],
"test": ["pytest>=7.0.0", "Mako"],
},
include_package_data=True,
package_data={
Expand Down
10 changes: 4 additions & 6 deletions test/test_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,8 +637,8 @@ def test_vector_args(ctx_factory):
def test_header_dep_handling(ctx_factory):
context = ctx_factory()

from os.path import exists
assert exists("empty-header.h") # if this fails, change dir to pyopencl/test
inducer marked this conversation as resolved.
Show resolved Hide resolved
from os.path import exists, dirname, join
assert exists(join(dirname(__file__), "empty-header.h"))

kernel_src = """
#include <empty-header.h>
Expand All @@ -648,10 +648,8 @@ def test_header_dep_handling(ctx_factory):
}
"""

import os

cl.Program(context, kernel_src).build(["-I", os.getcwd()])
cl.Program(context, kernel_src).build(["-I", os.getcwd()])
cl.Program(context, kernel_src).build(["-I", dirname(__file__)])
cl.Program(context, kernel_src).build(["-I", dirname(__file__)])


def test_context_dep_memoize(ctx_factory):
Expand Down