From 8b45c1d2156efa99f3ce5b1a235958ffdbe0255c Mon Sep 17 00:00:00 2001 From: Olivier Martin Date: Thu, 22 Feb 2024 09:35:15 +0100 Subject: [PATCH] ci: Generate Python package with cibuildwheel --- .github/workflows/github-actions.yml | 16 ++++++++++------ ci/generate-python-package.sh | 8 ++++++-- ci/install-bluez.sh | 21 +++++++++++++++++++++ dbus/CMakeLists.txt | 22 +++++++++++++++------- 4 files changed, 52 insertions(+), 15 deletions(-) create mode 100755 ci/install-bluez.sh diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index 13d4f909..280ae489 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -24,21 +24,25 @@ jobs: generate-python-binary-packages: runs-on: ubuntu-latest - strategy: - matrix: - python-version: ["3.9", "3.10", "3.11"] steps: - uses: actions/checkout@v4 - run: sudo apt install -y libbluetooth-dev - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - run: ./ci/generate-python-package.sh + if: startsWith(github.ref, 'refs/tags/') + env: + CIBW_BEFORE_BUILD_LINUX: "sh ci/install-bluez.sh" + - run: ./ci/generate-python-package.sh + if: ${{ ! startsWith(github.ref, 'refs/tags/') }} + env: + CIBW_BEFORE_BUILD_LINUX: "sh ci/install-bluez.sh" + GATTLIB_PY_VERSION: '0.0.1' + CIBW_ENVIRONMENT_PASS_LINUX: "GATTLIB_PY_VERSION" - name: Archive Python packages uses: actions/upload-artifact@v4 with: - name: python-${{ matrix.python-version }}-binary-package + name: python-binary-packages path: dist/* # publish-python-packages: diff --git a/ci/generate-python-package.sh b/ci/generate-python-package.sh index 8cbac500..3119531d 100755 --- a/ci/generate-python-package.sh +++ b/ci/generate-python-package.sh @@ -23,6 +23,10 @@ cp -r ${ROOT_PATH}/include ${gattlib_py_package_dir}/ cp -r ${ROOT_PATH}/CMakeLists.txt ${gattlib_py_package_dir}/ cp -r ${ROOT_PATH}/CrossCompilation.cmake ${gattlib_py_package_dir}/ +# Build script +mkdir ${gattlib_py_package_dir}/ci/ +cp -r ${ROOT_PATH}/ci/install-bluez.sh ${gattlib_py_package_dir}/ci/ + # Create MANIFEST.in cat <> MANIFEST.in graft common @@ -34,13 +38,13 @@ include CrossCompilation.cmake EOT # Install requirements -python3 -m pip install wheel +python3 -m pip --disable-pip-version-check install cibuildwheel==2.16.5 # Generate packages pushd ${gattlib_py_package_dir} # Binary package -python3 setup.py bdist_wheel +python3 -m cibuildwheel --output-dir dist # Source package python setup.py sdist diff --git a/ci/install-bluez.sh b/ci/install-bluez.sh new file mode 100755 index 00000000..af50f26a --- /dev/null +++ b/ci/install-bluez.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# Exit immediately if a command exits with a non-zero status. +set -ex + +# Install dependencies +yum -y install wget dbus-devel + +# +# +# +wget http://www.kernel.org/pub/linux/bluetooth/bluez-5.66.tar.xz +tar -xf bluez-5.66.tar.xz +pushd bluez-5.66 +./configure --prefix=/usr/local --disable-obex --disable-udev --disable-cups --disable-client --disable-manpages --disable-tools \ + --disable-obex --disable-monitor --disable-hog --disable-hid --disable-network --disable-a2dp --disable-avrcp --disable-bap \ + --disable-mcp --disable-vcp --enable-library +make +make install +popd +rm -Rf bluez-5.66 diff --git a/dbus/CMakeLists.txt b/dbus/CMakeLists.txt index 4592bd71..5b1e7017 100644 --- a/dbus/CMakeLists.txt +++ b/dbus/CMakeLists.txt @@ -102,18 +102,26 @@ if(GATTLIB_PYTHON_INTERFACE) else() set(Python_USE_STATIC_LIBS TRUE) endif() - find_package(Python COMPONENTS Interpreter Development) - if (NOT Python_Development_FOUND) - find_package(Python COMPONENTS Development.Module) - if (NOT Python_Development.Module_FOUND) + message("---- Python A") + find_package(Python3 COMPONENTS Interpreter Development) + message("---- Python B Python3_EXECUTABLE:${Python3_EXECUTABLE} Python3_Development_FOUND:${Python3_Development_FOUND} Python3_Interpreter_FOUND:${Python3_Interpreter_FOUND}") + if (NOT Python3_Development_FOUND) + message("---- Python C") + find_package(Python3 COMPONENTS Development.Module) + message("---- Python D Python3_Development.Module_FOUND:${Python3_Development.Module_FOUND}") + if (NOT Python3_Development.Module_FOUND) message(FATAL_ERROR "Could not find Python developer package") endif() + else() + message("---- Python E") endif() - include_directories(${Python_INCLUDE_DIRS}) - list(APPEND gattlib_LIBS ${Python_LIBRARIES}) + message("--- Python F: Python3_INCLUDE_DIRS:${Python3_INCLUDE_DIRS} Python3_LIBRARIES:${Python3_LIBRARIES} Python_LIBRARIES:${Python_LIBRARIES}") + + include_directories(${Python3_INCLUDE_DIRS}) + #list(APPEND gattlib_LIBS ${Python3_LIBRARIES}) - add_definitions(-DWITH_PYTHON -DPYTHON_VERSION_MAJOR=${Python_VERSION_MAJOR} -DPYTHON_VERSION_MINOR=${Python_VERSION_MINOR}) + add_definitions(-DWITH_PYTHON -DPYTHON_VERSION_MAJOR=${Python3_VERSION_MAJOR} -DPYTHON_VERSION_MINOR=${Python3_VERSION_MINOR}) endif() # Gattlib