]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Build psycopg-binary package for Linux
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 27 Jun 2021 23:38:39 +0000 (00:38 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 30 Jun 2021 00:48:40 +0000 (01:48 +0100)
.github/workflows/packages.yml [new file with mode: 0644]
.gitignore
tools/build/copy_to_binary.sh [new file with mode: 0755]
tools/build/wheel_linux_before_all.sh [new file with mode: 0755]

diff --git a/.github/workflows/packages.yml b/.github/workflows/packages.yml
new file mode 100644 (file)
index 0000000..b26e8b3
--- /dev/null
@@ -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
index 2eec3babe3b36de411172a283d24cc8b9c336a9b..80f237f59dbcac2223fd30f88132f9df3a0d79dc 100644 (file)
@@ -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 (executable)
index 0000000..147f7ff
--- /dev/null
@@ -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 (executable)
index 0000000..6e7e8a3
--- /dev/null
@@ -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