From: Daniele Varrazzo Date: Sun, 27 Jun 2021 23:38:39 +0000 (+0100) Subject: Build psycopg-binary package for Linux X-Git-Tag: 3.0.dev0~2^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e9533a4a040dd4b466ebb419953fc86e89e288d4;p=thirdparty%2Fpsycopg.git Build psycopg-binary package for Linux --- diff --git a/.github/workflows/packages.yml b/.github/workflows/packages.yml new file mode 100644 index 000000000..b26e8b364 --- /dev/null +++ b/.github/workflows/packages.yml @@ -0,0 +1,60 @@ +name: Build packages + +on: + workflow_dispatch: + +jobs: + build_linux: + name: Build Linux packages + runs-on: ubuntu-20.04 + + strategy: + matrix: + pyver: [cp36, cp37, cp38, cp39] + arch: [x86_64, i686, ppc64le, aarch64] + + steps: + - uses: actions/checkout@v2 + + - name: Set up QEMU for multi-arch build + uses: docker/setup-qemu-action@v1 + + - name: Create the binary package source tree + run: ./tools/build/copy_to_binary.sh + + - name: Build wheels + uses: pypa/cibuildwheel@v1.12.0 + with: + package-dir: psycopg_binary + env: + CIBW_MANYLINUX_X86_64_IMAGE: manylinux_2_24 + CIBW_MANYLINUX_I686_IMAGE: manylinux_2_24 + CIBW_MANYLINUX_AARCH64_IMAGE: manylinux_2_24 + CIBW_MANYLINUX_PPC64LE_IMAGE: manylinux_2_24 + CIBW_BUILD: ${{matrix.pyver}}-manylinux_${{matrix.arch}} + CIBW_ARCHS_LINUX: auto aarch64 ppc64le + CIBW_BEFORE_ALL_LINUX: ./tools/build/wheel_linux_before_all.sh + CIBW_BEFORE_TEST: pip install ./psycopg[test] + CIBW_TEST_COMMAND: pytest {project}/tests -m 'not slow' --color yes + CIBW_ENVIRONMENT: >- + PSYCOPG_IMPL=binary + PSYCOPG_TEST_DSN='host=172.17.0.1 user=postgres' + PGPASSWORD=password + + - uses: actions/upload-artifact@v2 + with: + path: ./wheelhouse/*.whl + + services: + postgresql: + image: postgres:13 + env: + POSTGRES_PASSWORD: password + ports: + - 5432:5432 + # Set health checks to wait until postgres has started + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 diff --git a/.gitignore b/.gitignore index 2eec3babe..80f237f59 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ __pycache__/ /docs/_build/ /docs/.venv/ *.html +/psycopg_binary/ diff --git a/tools/build/copy_to_binary.sh b/tools/build/copy_to_binary.sh new file mode 100755 index 000000000..147f7ff07 --- /dev/null +++ b/tools/build/copy_to_binary.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# Create the psycopg-binary package by renaming and patching psycopg-c +# This script is designed to run + +set -euo pipefail +set -x + +dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +pdir="$( cd "${dir}/../.." && pwd )" +target="${pdir}/psycopg_binary" + +cp -r "${pdir}/psycopg_c" "${target}" +mv "${target}"/{psycopg_c,psycopg_binary}/ +sed -i 's/psycopg-c/psycopg-binary/' "${target}"/setup.cfg +sed -i "s/__impl__[[:space:]]*=.*/__impl__ = 'binary'/" \ + "${target}"/psycopg_binary/pq.pyx +find "${target}" -name \*.pyx -or -name \*.pxd -or -name \*.py \ + | xargs sed -i 's/\bpsycopg_c\b/psycopg_binary/' diff --git a/tools/build/wheel_linux_before_all.sh b/tools/build/wheel_linux_before_all.sh new file mode 100755 index 000000000..6e7e8a3e6 --- /dev/null +++ b/tools/build/wheel_linux_before_all.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Configure the libraries needed to build wheel packages on linux. +# This script is designed to be used by cibuildwheel as CIBW_BEFORE_ALL_LINUX + +set -euo pipefail +set -x + +dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +# Install libpq +# Note that the pgdg doesn't have an aarch64 repository so wheels are build +# with the libpq packaged with Debian 9, which is 9.6. +if [[ ! "$AUDITWHEEL_ARCH" = "aarch64" ]]; then + source /etc/os-release + echo "deb http://apt.postgresql.org/pub/repos/apt ${VERSION_CODENAME}-pgdg main" \ + > /etc/apt/sources.list.d/pgdg.list + curl --silent https://www.postgresql.org/media/keys/ACCC4CF8.asc \ + | apt-key add - +fi +apt-get update +apt-get -y install libpq-dev