Skip to content

Commit

Permalink
Merge pull request #132 from CerebusOSS/cboulay/fixup_build
Browse files Browse the repository at this point in the history
Build more wheels for more Pythons
  • Loading branch information
cboulay authored May 26, 2023
2 parents c294962 + 94a4799 commit 860cef6
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 54 deletions.
33 changes: 22 additions & 11 deletions .github/workflows/build_cbsdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ jobs:
fail-fast: false
matrix:
config:
- { name: "windows-x64", os: "windows-latest", qt_arch: "win64_msvc2019_64", qt_ver: "6.4.3", cmake_extra: "-DCMAKE_PREFIX_PATH='D:\\a\\CereLink\\Qt\\6.4.3\\msvc2019_64' -T v142,host=x86" }
- { name: "macOS-latest", os: "macOS-latest"}
- {name: "windows-x64", os: "windows-latest",
qt_arch: "win64_msvc2019_64", qt_ver: "6.4.3",
cmake_extra: "-DCMAKE_PREFIX_PATH='D:\\a\\CereLink\\Qt\\6.4.3\\msvc2019_64' -T v142,host=x86"}
- { name: "macOS-latest", os: "macOS-latest", cibw_build: "cp3*-macosx_x86_64"}
- { name: "jammy", os: "ubuntu-22.04"}
- { name: "focal", os: "ubuntu-20.04"}

Expand Down Expand Up @@ -76,17 +78,27 @@ jobs:
cmake --build build --target install --config Release -j
cmake --build build --target package --config Release -j
- name: Set up Python
uses: actions/setup-python@v4
- uses: conda-incubator/setup-miniconda@v2
with:
python-version: "3.9"

- name: Build Wheel
miniconda-version: "latest"
- name: Build Wheels
shell: bash -el {0}
run: |
python -m pip install --upgrade numpy Cython pip wheel setuptools
conda create -n py39 python=3.9 numpy Cython pip wheel setuptools
conda activate py39
pip wheel . -w dist/
conda create -n py310 python=3.10 numpy Cython pip wheel setuptools
conda activate py310
pip wheel . -w dist/
# python -m tox -e clean,build
# python -m tox -e publish -- --verbose --repository pypi
conda create -n py311 python=3.11 numpy Cython pip wheel setuptools
conda activate py311
pip wheel . -w dist/
rm -f dist/numpy*.whl dist/Cython*.whl
# While it would be great if we could use cibuildhweels, this is not realistic because of the Qt6 dependency.
# We could delocate-wheel (Mac) or auditwheel (linux) but these produce huge binaries and it's fairly easy to
# install Qt6 (the only truly missing dependency) on these platforms.
# On Windows, we might want to unzip the wheel, drop in Qt6Core.dll, and then re-zip it.
# I'd rather spend development time removing Qt6 altogether.

- name: Ubuntu - Prefix package with release name
if: startswith(matrix.config.os, 'ubuntu-')
Expand All @@ -105,4 +117,3 @@ jobs:
with:
files: |
dist/*
5 changes: 2 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,10 @@ IF(${BUILD_TEST})
${LIB_INCL_DIRS}
${PROJECT_SOURCE_DIR}/cbsdk
)
TARGET_LINK_LIBRARIES(testcbsdk
${QT_LIBRARIES}
)
TARGET_LINK_LIBRARIES(testcbsdk PRIVATE ${QT_LIBRARIES})
IF(WIN32)
TARGET_LINK_LIBRARIES(testcbsdk
PRIVATE
wsock32 ws2_32 winmm
)
ELSEIF(NOT APPLE)
Expand Down
1 change: 1 addition & 0 deletions cerebus/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = 0.2
20 changes: 20 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[build-system]
requires = ["setuptools", "wheel", "cython", "numpy"]
build-backend = "setuptools.build_meta"

[project]
name = "cerebus" # as it would appear on PyPI
dynamic = ["version", "readme"]
authors = [
{name = "Chadwick Boulay", email = "[email protected]"},
{name = "Ehsan Azar"}
]
requires-python = ">=3.9"
urls = {homepage = "https://github.com/CerebusOSS/CereLink"}

[tool.setuptools.packages.find]
include = ["cerebus*"] # package names should match these glob patterns (["*"] by default)

[tool.setuptools.dynamic]
version = {attr = "cerebus.__version__"}
readme = {file = ["README.md"]}
57 changes: 17 additions & 40 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from __future__ import print_function
import os
from pathlib import Path
import sys
import platform

import numpy
from setuptools import find_packages
from setuptools import setup, Extension
from Cython.Build import build_ext

Expand All @@ -15,10 +13,15 @@ def get_extras():
arch = '64' if '64bit' in platform.architecture() else ''
# Find all the extra include files, libraries, and link arguments we need to install.
dist_path = os.path.join(cur, 'install')
print(dist_path, os.path.exists(dist_path))
if "win32" in sys.platform:
vs_out = os.path.join(cur, 'out', 'install', 'x64-Release')
if os.path.exists(vs_out):
dist_path = vs_out
elif not os.path.exists(dist_path):
clion_out = os.path.join(cur, "cmake-build-release", "install")
if os.path.exists(clion_out):
dist_path = clion_out

x_includes = [os.path.join(dist_path, 'include')] # Must include cbsdk headers
x_libs = []
Expand Down Expand Up @@ -76,52 +79,26 @@ def _get_qt_path():
x_libs += ["Qt6" + _ for _ in ["Core", "Xml", "Concurrent"]]
else: # Linux
x_link_args += ['-L{path}'.format(path=os.path.join(dist_path, 'lib{arch}'.format(arch=arch)))]
# For Qt linking at run time, check `qtchooser -print-env`
# If it is not pointing to correct QtDir, then edit /usr/lib/x86_64-linux-gnu/qt-default/qtchooser/default.conf
# /opt/Qt/5.9/gcc_64/bin
# /opt/Qt/5.9/gcc_64/lib
# This should also take care of finding the link dir at compile time, (i.e. -L/path/to/qt not necessary)
# but we need to specify lib names, and these are version dependent.
import subprocess
import re
p = subprocess.Popen('qmake -v', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
res = p.stdout.read().decode()
if not res.startswith("Qt version"):
p = subprocess.Popen('qmake6 -v', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
res = p.stdout.read().decode()
qt_ver = re.findall('Qt version .', res)[0][-1]
x_libs += ["Qt" + qt_ver + _ for _ in ["Core", "Xml", "Concurrent"]]
x_libs += ["Qt6" + _ for _ in ["Core", "Xml", "Concurrent"]]

return x_includes, x_libs, x_link_args


extra_includes, extra_libs, extra_link_args = get_extras()

extension_kwargs = {
'sources': ['cerebus/cbpy.pyx', 'cerebus/cbsdk_helper.cpp'],
'libraries': ["cbsdk_static"] + extra_libs,
'extra_link_args': extra_link_args,
'include_dirs': [numpy.get_include()] + extra_includes,
'language': 'c++'
}

cbpy_module = Extension('cerebus.cbpy', **extension_kwargs)

setup(
name='cerebus',
version='0.2',
description='Cerebus Link',
long_description='Cerebus Link Python Package',
author='Chadwick Boulay',
author_email='[email protected]',
setup_requires=['Cython', 'numpy', 'wheel'],
install_requires=['Cython', 'numpy'],
url='https://github.com/CerebusOSS/CereLink',
packages=find_packages(),
cmdclass={
'build_ext': build_ext,
},
ext_modules=[
cbpy_module,
Extension("cerebus.cbpy",
sources=["cerebus/cbpy.pyx", "cerebus/cbsdk_helper.cpp"],
libraries=["cbsdk_static"] + extra_libs,
extra_link_args=extra_link_args,
include_dirs=[numpy.get_include()] + extra_includes,
language="c++"
)
],
cmdclass={
"build_ext": build_ext
}
# See pyproject.toml for rest of configuration.
)

0 comments on commit 860cef6

Please sign in to comment.