diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index 13d4f909..5052198d 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -22,23 +22,33 @@ jobs: - run: sudo apt install libbluetooth-dev - run: mkdir build && pushd build && cmake -DGATTLIB_FORCE_DBUS=TRUE -DCMAKE_BUILD_TYPE=Release .. && make - generate-python-binary-packages: + generate-python-source-package: 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 - name: Archive Python packages uses: actions/upload-artifact@v4 with: - name: python-${{ matrix.python-version }}-binary-package + name: python-source-package + path: dist/*.tar.gz + + generate-python-binary-packages: + runs-on: quay.io/pypa/manylinux_2_28_x86_64 + steps: + - uses: actions/checkout@v4 + - name: Generate Binary package with git version + if: startsWith(github.ref, 'refs/tags/') + run: ./ci/generate-python-mainlinux-package.sh + - name: Generate Binary package with FAKE version + if: ${{ ! startsWith(github.ref, 'refs/tags/') }} + run: ./ci/generate-python-mainlinux-package.sh + env: + GATTLIB_PY_VERSION: '0.0.1' + - name: Archive Python packages + uses: actions/upload-artifact@v4 + with: + name: python-binary-packages path: dist/* # publish-python-packages: diff --git a/ci/generate-python-mainlinux-package.sh b/ci/generate-python-mainlinux-package.sh new file mode 100755 index 00000000..3dd9c4a1 --- /dev/null +++ b/ci/generate-python-mainlinux-package.sh @@ -0,0 +1,102 @@ +#!/bin/bash + +# +# To launch: docker run --volume $PWD:/code --env GATTLIB_PY_VERSION=0.4 -it quay.io/pypa/manylinux_2_28_x86_64 /code/ci/generate-python-mainlinux-package.sh +# +# Based on https://github.com/pypa/python-manylinux-demo/blob/master/travis/build-wheels.sh +# + +# Exit immediately if a command exits with a non-zero status. +set -ex + +export PLAT=manylinux_2_28_x86_64 + +# 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 --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 + +# +# Generate Python package +# + +# Retrieve path of current script +SCRIPT_PATH=`dirname "$0"` +SCRIPT_PATH=`( cd "$SCRIPT_PATH" && pwd )` +ROOT_PATH=`( cd "$SCRIPT_PATH/.." && pwd )` + +gattlib_py_package_dir=$(mktemp -d -p $PWD -t gattlib-py-package-XXXXXXXXXX) + +# Python code +cp -r ${ROOT_PATH}/gattlib-py/gattlib ${gattlib_py_package_dir}/ +cp -r ${ROOT_PATH}/gattlib-py/setup.py ${gattlib_py_package_dir}/ +cp -r ${ROOT_PATH}/gattlib-py/README.md ${gattlib_py_package_dir}/ + +# Native code +cp -r ${ROOT_PATH}/common ${gattlib_py_package_dir}/ +cp -r ${ROOT_PATH}/bluez ${gattlib_py_package_dir}/ +cp -r ${ROOT_PATH}/dbus ${gattlib_py_package_dir}/ +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}/ + +# Create MANIFEST.in +cat <> MANIFEST.in +graft common +graft bluez +graft dbus +graft include +include CMakeLists.txt +include CrossCompilation.cmake +EOT + +mkdir -p wheelhouse +mkdir -p ${ROOT_PATH}/dist + +function repair_wheel { + wheel="$1" + if ! auditwheel show "$wheel"; then + echo "Skipping non-platform wheel $wheel" + else + auditwheel repair "$wheel" --plat "$PLAT" -w ${ROOT_PATH}/dist/ + fi +} + +pushd ${gattlib_py_package_dir} + +# For now, remove Pypy implementation. Only keep CPython implementation +# There is a build issue when using Pypy - CMake does not find the Python developer package. +rm -Rf /opt/python/pp* + +# Compile wheels +for PYBIN in /opt/python/*/bin; do + #"${PYBIN}/pip" install -r /io/dev-requirements.txt + PATH=${PYBIN}:$PATH pip wheel . --no-deps -w wheelhouse/ +done + +# Bundle external shared libraries into the wheels +for whl in wheelhouse/*.whl; do + repair_wheel "$whl" +done + +# Install packages and test +for PYBIN in /opt/python/*/bin/; do + "${PYBIN}/pip" install gattlib_py --no-index -f ${ROOT_PATH}/dist + #(cd "$HOME"; "${PYBIN}/nosetests" pymanylinuxdemo) +done + +popd + +rm -Rf ${gattlib_py_package_dir} + +ls ${ROOT_PATH}/dist diff --git a/ci/generate-python-package.sh b/ci/generate-python-package.sh index 8cbac500..b56dc09b 100755 --- a/ci/generate-python-package.sh +++ b/ci/generate-python-package.sh @@ -47,7 +47,6 @@ python setup.py sdist # Move generated artifact to project root path ls dist/* -mv dist ${ROOT_PATH} popd