]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
build: cache libpq build
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Mon, 13 Jun 2022 07:12:01 +0000 (09:12 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 14 Jun 2022 22:56:07 +0000 (00:56 +0200)
.github/workflows/packages.yml
tools/build/build_libpq.sh

index e140208626254f4b7375319acca5ff3aec83f645..f1c9f4b3b1ad15d47f2ee7e1483c8e076bd32de4 100644 (file)
@@ -93,6 +93,12 @@ jobs:
       - name: Set up QEMU for multi-arch build
         uses: docker/setup-qemu-action@v1
 
+      - name: Cache libpq build
+        uses: actions/cache@v3
+        with:
+          path: /tmp/libpq.build
+          key: libpq-14.3-${{ matrix.platform }}-${{ matrix.arch }}-1
+
       - name: Create the binary package source tree
         run: python3 ./tools/build/copy_to_binary.py
 
@@ -118,6 +124,9 @@ jobs:
             PSYCOPG_IMPL=binary
             PSYCOPG_TEST_DSN='host=172.17.0.1 user=postgres'
             PGPASSWORD=password
+            LIBPQ_BUILD_PREFIX=/host/tmp/libpq.build
+            PATH="$LIBPQ_BUILD_PREFIX/bin:$PATH"
+            LD_LIBRARY_PATH="$LIBPQ_BUILD_PREFIX/lib"
 
       - uses: actions/upload-artifact@v2
         with:
index 5f3188150b4256ce1bccd990910e048a8996fb60..e098ba7c0c2b63cf13fd033f07d9c7e83c7cc168 100755 (executable)
@@ -5,10 +5,18 @@
 set -euo pipefail
 set -x
 
+# IMPORTANT! Change the cache key in packages.yml when upgrading libraries
+postgres_version="14.3"
 openssl_version="1.1.1o"
 ldap_version="2.6.2"
 sasl_version="2.1.28"
-postgres_version="14.3"
+
+export LIBPQ_BUILD_PREFIX=${LIBPQ_BUILD_PREFIX:-/tmp/libpq.build}
+
+if [[ -f "${LIBPQ_BUILD_PREFIX}/lib/libpq.so" ]]; then
+    echo "libpq already available: build skipped" >&2
+    exit 0
+fi
 
 source /etc/os-release
 
@@ -38,7 +46,7 @@ if [ "$ID" == "centos" ]; then
 
         cd "${openssl_dir}"
 
-        ./config --prefix=/usr/local/ --openssldir=/usr/local/ \
+        ./config --prefix=${LIBPQ_BUILD_PREFIX} --openssldir=${LIBPQ_BUILD_PREFIX} \
             zlib -fPIC shared
         make depend
         make
@@ -69,7 +77,7 @@ if [ "$ID" == "centos" ]; then
         cd "${sasl_dir}"
 
         autoreconf -i
-        ./configure
+        ./configure --prefix=${LIBPQ_BUILD_PREFIX}
         make
     else
         cd "${sasl_dir}"
@@ -96,7 +104,7 @@ if [ "$ID" == "centos" ]; then
 
         cd "${ldap_dir}"
 
-        ./configure --enable-backends=no --enable-null
+        ./configure --prefix=${LIBPQ_BUILD_PREFIX} --enable-backends=no --enable-null
         make depend
         make -C libraries/liblutil/
         make -C libraries/liblber/
@@ -109,7 +117,7 @@ if [ "$ID" == "centos" ]; then
     make -C libraries/liblber/ install
     make -C libraries/libldap/ install
     make -C include/ install
-    chmod +x /usr/local/lib/{libldap,liblber}*.so*
+    chmod +x ${LIBPQ_BUILD_PREFIX}/lib/{libldap,liblber}*.so*
     cd ..
 
 fi
@@ -131,13 +139,12 @@ if [ ! -d "${postgres_dir}" ]; then
 '|#define DEFAULT_PGSOCKET_DIR "/var/run/postgresql"|' \
         src/include/pg_config_manual.h
 
-    # Without this, libpq ./configure fails on i686
-    if [[ "$(uname -m)" != "x86_64" ]]; then
-        export LD_LIBRARY_PATH=/usr/local/lib
-    fi
+    # Often needed, but currently set by the workflow
+    # export LD_LIBRARY_PATH="${LIBPQ_BUILD_PREFIX}/lib"
 
-    ./configure --prefix=/usr/local --sysconfdir=/etc/postgresql-common \
-        --without-readline --with-gssapi --with-openssl --with-pam --with-ldap
+    ./configure --prefix=${LIBPQ_BUILD_PREFIX} --sysconfdir=/etc/postgresql-common \
+        --without-readline --with-gssapi --with-openssl --with-pam --with-ldap \
+        CPPFLAGS=-I${LIBPQ_BUILD_PREFIX}/include/ LDFLAGS=-L${LIBPQ_BUILD_PREFIX}/lib
     make -C src/interfaces/libpq
     make -C src/bin/pg_config
     make -C src/include
@@ -151,4 +158,4 @@ make -C src/bin/pg_config install
 make -C src/include install
 cd ..
 
-find /usr/local/ -name \*.so.\* -type f -exec strip --strip-unneeded {} \;
+find ${LIBPQ_BUILD_PREFIX} -name \*.so.\* -type f -exec strip --strip-unneeded {} \;