Skip to content

Commit 0f82879

Browse files
mliezundvarrazzo
authored andcommitted
feat: add workflow to build riscv64 binaries and cache libpq
This commit introduces a new GitHub Actions workflow for building and caching the libpq package, ensuring that the libpq artifacts are available for subsequent builds. Additionally, it updates the build scripts to release riscv64 binaries for linux.
1 parent fd9ae8c commit 0f82879

File tree

5 files changed

+168
-12
lines changed

5 files changed

+168
-12
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
name: Build and cache libpq
2+
3+
# Build the libpq package and cache the artifacts.
4+
#
5+
# Every Python version on the same architecture will use the same libpq.
6+
# Therefore building and caching the libpq together with the binary packages
7+
# result in multiple concurrent builds, and the github artifacts manageer very
8+
# confused.
9+
#
10+
# This job builds the libpq and then caches the artifacts so that the
11+
# packages.yml workflow will find the library in the cache.
12+
#
13+
# You can see the caches at https://github.com/psycopg/psycopg2/actions/caches
14+
#
15+
# Or from the API:
16+
#
17+
# curl -fsSL -X GET \
18+
# -H "Accept: application/vnd.github+json" \
19+
# -H "Authorization: Bearer $GITHUB_TOKEN" \
20+
# -H "X-GitHub-Api-Version: 2022-11-28" \
21+
# "https://api.github.com/repos/psycopg/psycopg/actions/caches" \
22+
# | jq -r '.actions_caches[].key'
23+
#
24+
# You can delete a cache using:
25+
#
26+
# curl -fsSL -X DELETE \
27+
# -H "Accept: application/vnd.github+json" \
28+
# -H "Authorization: Bearer $GITHUB_TOKEN" \
29+
# -H "X-GitHub-Api-Version: 2022-11-28" \
30+
# "https://api.github.com/repos/psycopg/psycopg/actions/caches?key=libpq-manylinux-ppc64le-17.2-3.4.0"
31+
#
32+
# ref: https://docs.github.com/en/rest/actions/cache?apiVersion=2022-11-28#delete-github-actions-caches-for-a-repository-using-a-cache-key
33+
34+
on:
35+
workflow_dispatch:
36+
push:
37+
paths:
38+
- .github/workflows/build-and-cache-libpq.yml
39+
- scripts/build/build_libpq.sh
40+
41+
# TODO: move these env vars in an external env file in order to share them
42+
# across workflows.
43+
44+
env:
45+
LIBPQ_VERSION: "17.6"
46+
OPENSSL_VERSION: "3.5.4"
47+
PQ_FLAGS: ""
48+
49+
concurrency:
50+
# Cancel older requests of the same workflow in the same branch.
51+
group: ${{ github.workflow }}-${{ github.ref_name }}
52+
cancel-in-progress: true
53+
54+
jobs:
55+
56+
linux: # {{{
57+
runs-on: ubuntu-latest
58+
if: true
59+
60+
strategy:
61+
fail-fast: false
62+
matrix:
63+
arch: [x86_64, ppc64le, aarch64, riscv64]
64+
platform: [manylinux, musllinux]
65+
66+
steps:
67+
- uses: actions/checkout@v5
68+
69+
- name: Set up QEMU for multi-arch build
70+
# Check https://github.com/docker/setup-qemu-action for newer versions.
71+
uses: docker/setup-qemu-action@v3
72+
with:
73+
# https://github.com/pypa/cibuildwheel/discussions/2256
74+
image: tonistiigi/binfmt:qemu-v8.1.5
75+
76+
- name: Cache libpq build
77+
uses: actions/cache@v4
78+
with:
79+
path: /tmp/libpq.build
80+
key: libpq-${{ matrix.platform }}-${{ matrix.arch }}-${{ env.LIBPQ_VERSION }}-${{ env.OPENSSL_VERSION }}${{ env.PQ_FLAGS }}
81+
82+
- name: Build wheels
83+
uses: pypa/[email protected]
84+
env:
85+
CIBW_SKIP: "cp31?t-*"
86+
CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014
87+
CIBW_MANYLINUX_I686_IMAGE: manylinux2014
88+
CIBW_MANYLINUX_AARCH64_IMAGE: manylinux2014
89+
CIBW_MANYLINUX_PPC64LE_IMAGE: manylinux2014
90+
CIBW_MANYLINUX_RISCV64_IMAGE: quay.io/pypa/manylinux_2_39_riscv64
91+
CIBW_BUILD: cp313-${{matrix.platform}}_${{matrix.arch}}
92+
CIBW_ARCHS_LINUX: auto aarch64 ppc64le riscv64
93+
CIBW_BEFORE_ALL_LINUX: ./scripts/build/build_libpq.sh
94+
CIBW_REPAIR_WHEEL_COMMAND: >-
95+
./scripts/build/strip_wheel.sh {wheel}
96+
&& auditwheel repair -w {dest_dir} {wheel}
97+
CIBW_ENVIRONMENT_PASS_LINUX: LIBPQ_VERSION OPENSSL_VERSION
98+
CIBW_ENVIRONMENT: >-
99+
LIBPQ_BUILD_PREFIX=/host/tmp/libpq.build
100+
PATH="$LIBPQ_BUILD_PREFIX/bin:$PATH"
101+
LD_LIBRARY_PATH="$LIBPQ_BUILD_PREFIX/lib:$LIBPQ_BUILD_PREFIX/lib64"
102+
103+
104+
# }}}
105+
106+
macos: # {{{
107+
runs-on: macos-latest
108+
if: true
109+
110+
strategy:
111+
fail-fast: false
112+
matrix:
113+
arch: [x86_64, arm64]
114+
115+
steps:
116+
- name: Checkout repos
117+
uses: actions/checkout@v5
118+
119+
- name: Cache libpq build
120+
uses: actions/cache@v4
121+
with:
122+
path: /tmp/libpq.build
123+
key: libpq-macos-${{ env.LIBPQ_VERSION }}-${{ matrix.arch }}-${{ env.OPENSSL_VERSION }}${{ env.PQ_FLAGS }}
124+
125+
- name: Build wheels
126+
uses: pypa/[email protected]
127+
env:
128+
CIBW_SKIP: "cp31?t-*"
129+
CIBW_BUILD: cp313-macosx_${{matrix.arch}}
130+
CIBW_ARCHS_MACOS: ${{matrix.arch}}
131+
MACOSX_ARCHITECTURE: ${{matrix.arch}}
132+
CIBW_BEFORE_ALL_MACOS: ./scripts/build/build_libpq.sh
133+
CIBW_ENVIRONMENT: >-
134+
PSYCOPG_IMPL=binary
135+
LIBPQ_BUILD_PREFIX=/tmp/libpq.build
136+
PATH="$LIBPQ_BUILD_PREFIX/bin:$PATH"
137+
138+
# }}}

.github/workflows/packages.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
---
22
name: Build packages
3+
4+
# Note: these jobs also build and cache the libpq, but, because every Python
5+
# version will try to build and cache the same libpq instance, there is a race
6+
# condition and most likely the artifacts manager will refuse to cache.
7+
#
8+
# Please run the `build-and-cache-libpq.yml` workflow when the libpq/openssl
9+
# version change in order to update the cache.
10+
311
on:
412
- workflow_dispatch
513

614
env:
715
PIP_BREAK_SYSTEM_PACKAGES: "1"
816
LIBPQ_VERSION: "17.6"
917
OPENSSL_VERSION: "3.5.4"
18+
PQ_FLAGS: ""
1019

1120
jobs:
1221
sdist: # {{{
@@ -65,7 +74,7 @@ jobs:
6574
fail-fast: false
6675
matrix:
6776
platform: [manylinux, musllinux]
68-
arch: [x86_64, aarch64, ppc64le]
77+
arch: [x86_64, aarch64, ppc64le, riscv64]
6978
pyver: [cp39, cp310, cp311, cp312, cp313, cp314]
7079

7180
runs-on: ubuntu-latest
@@ -80,7 +89,7 @@ jobs:
8089
uses: actions/cache@v4
8190
with:
8291
path: /tmp/libpq.build
83-
key: libpq-${{ env.LIBPQ_VERSION }}-${{ matrix.platform }}-${{ matrix.arch }}
92+
key: libpq-${{ matrix.platform }}-${{ matrix.arch }}-${{ env.LIBPQ_VERSION }}-${{ env.OPENSSL_VERSION }}${{ env.PQ_FLAGS }}
8493

8594
- name: Build wheels
8695
uses: pypa/[email protected]
@@ -90,8 +99,9 @@ jobs:
9099
CIBW_MANYLINUX_I686_IMAGE: manylinux2014
91100
CIBW_MANYLINUX_AARCH64_IMAGE: manylinux2014
92101
CIBW_MANYLINUX_PPC64LE_IMAGE: manylinux2014
102+
CIBW_MANYLINUX_RISCV64_IMAGE: quay.io/pypa/manylinux_2_39_riscv64
93103
CIBW_BUILD: ${{matrix.pyver}}-${{matrix.platform}}_${{matrix.arch}}
94-
CIBW_ARCHS_LINUX: auto aarch64 ppc64le
104+
CIBW_ARCHS_LINUX: auto aarch64 ppc64le riscv64
95105
CIBW_BEFORE_ALL_LINUX: ./scripts/build/wheel_linux_before_all.sh
96106
CIBW_REPAIR_WHEEL_COMMAND: >-
97107
./scripts/build/strip_wheel.sh {wheel}
@@ -151,7 +161,7 @@ jobs:
151161
uses: actions/cache@v4
152162
with:
153163
path: /tmp/libpq.build
154-
key: libpq-${{ env.LIBPQ_VERSION }}-macos-${{ matrix.arch }}
164+
key: libpq-macos-${{ env.LIBPQ_VERSION }}-${{ matrix.arch }}-${{ env.OPENSSL_VERSION }}${{ env.PQ_FLAGS }}
155165

156166
- name: Build wheels
157167
uses: pypa/[email protected]

scripts/build/build_libpq.sh

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
# Build a modern version of libpq and depending libs from source on Centos 5, Alpine or macOS
3+
# Build a modern version of libpq and depending libs from source on Centos 5, Rocky, Alpine or macOS
44

55
set -euo pipefail
66

@@ -54,9 +54,9 @@ fi
5454

5555
# Install packages required to build the libpq.
5656
case "$ID" in
57-
centos)
57+
centos|rocky)
5858
yum update -y
59-
yum install -y flex krb5-devel pam-devel perl-IPC-Cmd perl-Time-Piece zlib-devel
59+
yum install -y flex krb5-devel pam-devel perl perl-IPC-Cmd perl-Time-Piece zlib-devel
6060
;;
6161

6262
alpine)
@@ -104,7 +104,7 @@ else
104104
)
105105
fi
106106

107-
if [ "$ID" == "centos" ] || [ "$ID" == "macos" ]; then
107+
if [ "$ID" == "centos" ] || [ "$ID" == "rocky" ] || [ "$ID" == "macos" ]; then
108108
if [[ ! -f "${LIBPQ_BUILD_PREFIX}/openssl.cnf" ]]; then
109109

110110
# Build openssl if needed
@@ -160,7 +160,7 @@ if [ "$ID" == "macos" ]; then
160160
fi
161161

162162

163-
if [ "$ID" == "centos" ] || [ "$ID" == "macos" ]; then
163+
if [ "$ID" == "centos" ] || [ "$ID" == "rocky" ] || [ "$ID" == "macos" ]; then
164164
if [[ ! -f "${LIBPQ_BUILD_PREFIX}/lib/libsasl2.${library_suffix}" ]]; then
165165

166166
# Build libsasl2 if needed
@@ -176,6 +176,14 @@ if [ "$ID" == "centos" ] || [ "$ID" == "macos" ]; then
176176

177177
pushd "${sasl_dir}"
178178

179+
if [ "$ID" == "rocky" ]; then
180+
# Fix missing time.h include in multiple files for newer GCC versions
181+
sed -i.bak '/#include "saslint.h"/a\
182+
#include <time.h>' lib/saslutil.c
183+
sed -i.bak '/#include "plugin_common.h"/a\
184+
#include <time.h>' plugins/cram.c
185+
fi
186+
179187
autoreconf -i
180188
./configure "${make_configure_standard_flags[@]}" --disable-macos-framework
181189
make -s
@@ -193,7 +201,7 @@ if [ "$ID" == "centos" ] || [ "$ID" == "macos" ]; then
193201
fi
194202

195203

196-
if [ "$ID" == "centos" ] || [ "$ID" == "macos" ]; then
204+
if [ "$ID" == "centos" ] || [ "$ID" == "rocky" ] || [ "$ID" == "macos" ]; then
197205
if [[ ! -f "${LIBPQ_BUILD_PREFIX}/lib/libldap.${library_suffix}" ]]; then
198206

199207
# Build openldap if needed

scripts/build/print_so_versions.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ case "$ID" in
2626
done) | sort | uniq
2727
;;
2828

29-
centos)
29+
centos|rocky)
3030
echo "TODO!"
3131
;;
3232

scripts/build/wheel_linux_before_all.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ case "$ID" in
3535
apt-get -y install libpq-dev
3636
;;
3737

38-
centos)
38+
centos|rocky)
3939
"${dir}/build_libpq.sh" > /dev/null
4040
;;
4141

0 commit comments

Comments
 (0)