From 2f1c4776fed48d2432f5ee79d34ab088eb022ee7 Mon Sep 17 00:00:00 2001 From: Yogesh Sharma Date: Fri, 21 Aug 2026 06:02:50 -0400 Subject: [PATCH] For CI/CD -devel and PG 18+ to use meson build Remove c_std, use postgres defined Fix libpq search Fix internal header path --- .../{test-master.yml => test-devel.yml} | 54 +++++++-------- .github/workflows/test.yml | 69 ++++++++++++++----- meson.build | 42 ++++++----- 3 files changed, 98 insertions(+), 67 deletions(-) rename .github/workflows/{test-master.yml => test-devel.yml} (55%) diff --git a/.github/workflows/test-master.yml b/.github/workflows/test-devel.yml similarity index 55% rename from .github/workflows/test-master.yml rename to .github/workflows/test-devel.yml index d948f917..9106bcfc 100644 --- a/.github/workflows/test-master.yml +++ b/.github/workflows/test-devel.yml @@ -1,4 +1,4 @@ -name: pgactive PG-Master CI +name: pgactive PG-Devel CI on: #schedule: # # Runs every day at 5am. @@ -35,27 +35,17 @@ jobs: - name: Checkout Postgres run: | - sudo apt-get -y -q install libipc-run-perl build-essential libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt-dev libssl-dev libxml2-utils xsltproc ccache pkg-config libicu-dev + sudo apt-get -y -q install libipc-run-perl build-essential libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt-dev libssl-dev libxml2-utils xsltproc ccache pkg-config libicu-dev meson ninja-build git clone --depth 1 --branch ${{ matrix.version }} https://github.com/postgres/postgres.git - - if: ${{ matrix.version == 'REL_11_STABLE' }} - name: Apply per-test-script runtime display patch (REL_11_STABLE only) - run: | - cd postgres - git apply $GITHUB_WORKSPACE/pgactive/src/compat/11/v1-0001-Add-per-test-script-runtime-display-to-pg_regress.patch - git status - - name: Build Postgres run: | cd $GITHUB_WORKSPACE/postgres - sh configure --prefix=$PWD/inst/ --enable-debug --enable-cassert --enable-tap-tests CFLAGS="-ggdb3 -O0" - make -j4 install - - # Install extensions required for pgactive tests - make -C contrib/btree_gist install - make -C contrib/cube install - make -C contrib/hstore install - make -C contrib/pg_trgm install + # meson build. contrib (btree_gist, cube, hstore, pg_trgm) and the + # PostgreSQL::Test perl modules are built and installed as part of the + # main tree, so no separate contrib install steps are needed. + meson setup build --prefix=$PWD/inst --buildtype=debug -Dcassert=true -Dtap_tests=enabled + ninja -C build install - name: Check pgactive code indentation run: | @@ -63,31 +53,35 @@ jobs: ls -1 src/compat/??/pg_dump/*.[ch] >$GITHUB_WORKSPACE/postgres/pgindent.ignore cd $GITHUB_WORKSPACE/postgres - make -C src/tools/pg_bsd_indent/ -j4 install - src/tools/pgindent/pgindent --indent=$GITHUB_WORKSPACE/postgres/src/tools/pg_bsd_indent/pg_bsd_indent --excludes=pgindent.ignore --diff $GITHUB_WORKSPACE/pgactive > pgindent.diffs + # pg_bsd_indent is built by meson but not installed; use it from the build tree. + ninja -C build src/tools/pg_bsd_indent/pg_bsd_indent + src/tools/pgindent/pgindent --indent=$GITHUB_WORKSPACE/postgres/build/src/tools/pg_bsd_indent/pg_bsd_indent --excludes=pgindent.ignore --diff $GITHUB_WORKSPACE/pgactive > pgindent.diffs test -s pgindent.diffs && cat pgindent.diffs && exit 1 || exit 0 - name: Build pgactive run: | - cd pgactive - PATH=$GITHUB_WORKSPACE/postgres/inst/bin:"$PATH" - sh configure - make PROFILE="-Wall -Wmissing-prototypes -Werror=maybe-uninitialized -Werror" -j1 all install + cd $GITHUB_WORKSPACE/pgactive + export PATH=$GITHUB_WORKSPACE/postgres/inst/bin:"$PATH" + meson setup build -Dpg_config=$GITHUB_WORKSPACE/postgres/inst/bin/pg_config -Dwarning_level=1 -Dwerror=true + ninja -C build install - name: Run pgactive core tests run: | - cd pgactive - make regress_check + cd $GITHUB_WORKSPACE/pgactive + export PATH=$GITHUB_WORKSPACE/postgres/inst/bin:"$PATH" + meson test -C build --suite regress --print-errorlogs - name: Show pgactive core tests diff if: ${{ failure() }} run: | - cat pgactive/test/regression.diffs + cat pgactive/build/meson-logs/testlog.txt 2>/dev/null || true + cat pgactive/test/regression.diffs 2>/dev/null || true - name: Run pgactive extended tests run: | - cd pgactive - make PROVE_FLAGS="--timer -v" prove_check + cd $GITHUB_WORKSPACE/pgactive + export PATH=$GITHUB_WORKSPACE/postgres/inst/bin:"$PATH" + meson test -C build --suite tap --print-errorlogs - name: Upload test artifacts if: ${{ failure() }} @@ -96,6 +90,6 @@ jobs: name: test-artifact-${{ matrix.os }}-${{ matrix.version }} path: | postgres/pgindent.diffs - pgactive/test/regression.diffs - pgactive/test/tmp_check/log + pgactive/build/meson-logs + pgactive/build/tmp_check/log retention-days: 1 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 58ae458e..ac0f105e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,8 +21,9 @@ jobs: - id: set-versions run: | curl -s https://www.postgresql.org/versions.json > versions.json - # Format as JSON array and map 'major' to 'REL_XX_STABLE' for postgres branch checkout - VERSIONS=$(jq -c '[.[] | select(.supported == true) | "REL_" + (.major | tostring) + "_STABLE"]' versions.json) + # Emit {branch, major} per supported release: branch for checkout, + # major (an integer) so the job can pick meson vs autoconf directly. + VERSIONS=$(jq -c '[.[] | select(.supported == true) | {branch: ("REL_" + (.major | tostring) + "_STABLE"), major: .major}]' versions.json) echo "versions=$VERSIONS" >> $GITHUB_OUTPUT test: @@ -35,10 +36,14 @@ jobs: matrix: os: [ubuntu-latest] version: ${{ fromJson(needs.setup-matrix.outputs.versions) }} - + runs-on: ${{ matrix.os }} timeout-minutes: 120 + # Build PG 18 and newer with meson; keep autoconf/make for older majors. + env: + USE_MESON: ${{ matrix.version.major >= 18 && '1' || '0' }} + steps: - name: Checkout pgactive uses: actions/checkout@v4 @@ -47,10 +52,10 @@ jobs: - name: Checkout Postgres run: | - sudo apt-get -y -q install libipc-run-perl build-essential libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt-dev libssl-dev libxml2-utils xsltproc ccache pkg-config libicu-dev - git clone --depth 1 --branch ${{ matrix.version }} https://github.com/postgres/postgres.git + sudo apt-get -y -q install libipc-run-perl build-essential libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt-dev libssl-dev libxml2-utils xsltproc ccache pkg-config libicu-dev meson ninja-build + git clone --depth 1 --branch ${{ matrix.version.branch }} https://github.com/postgres/postgres.git - - if: ${{ matrix.version == 'REL_11_STABLE' }} + - if: ${{ matrix.version.branch == 'REL_11_STABLE' }} name: Apply per-test-script runtime display patch (REL_11_STABLE only) run: | cd postgres @@ -60,42 +65,68 @@ jobs: - name: Build Postgres run: | cd postgres - sh configure --prefix=$PWD/inst/ --enable-debug --enable-cassert --enable-tap-tests CFLAGS="-ggdb3 -O0" - make -j4 install - # Install extensions required for pgactive tests - make -C contrib/btree_gist install - make -C contrib/cube install - make -C contrib/hstore install - make -C contrib/pg_trgm install + if [ "$USE_MESON" = "1" ]; then + # meson build. contrib and the PostgreSQL::Test perl modules are + # built and installed with the main tree — no separate steps needed. + meson setup build --prefix=$PWD/inst --buildtype=debug -Dcassert=true -Dtap_tests=enabled + ninja -C build install + else + sh configure --prefix=$PWD/inst/ --enable-debug --enable-cassert --enable-tap-tests CFLAGS="-ggdb3 -O0" + make -j4 install + # Install extensions required for pgactive tests + make -C contrib/btree_gist install + make -C contrib/cube install + make -C contrib/hstore install + make -C contrib/pg_trgm install + fi - name: Build pgactive run: | cd pgactive - PATH=$GITHUB_WORKSPACE/postgres/inst/bin:"$PATH" sh configure - make PROFILE="-Wall -Wmissing-prototypes -Werror=maybe-uninitialized -Werror" -j1 all install + export PATH=$GITHUB_WORKSPACE/postgres/inst/bin:"$PATH" + if [ "$USE_MESON" = "1" ]; then + meson setup build -Dpg_config=$GITHUB_WORKSPACE/postgres/inst/bin/pg_config -Dwarning_level=1 -Dwerror=true + ninja -C build install + else + sh configure + make PROFILE="-Wall -Wmissing-prototypes -Werror=maybe-uninitialized -Werror" -j1 all install + fi - name: Run pgactive core tests run: | cd pgactive - make regress_check + if [ "$USE_MESON" = "1" ]; then + export PATH=$GITHUB_WORKSPACE/postgres/inst/bin:"$PATH" + meson test -C build --suite regress --print-errorlogs + else + make regress_check + fi - name: Show pgactive core tests diff if: ${{ failure() }} run: | - cat pgactive/test/regression.diffs + cat pgactive/build/meson-logs/testlog.txt 2>/dev/null || true + cat pgactive/test/regression.diffs 2>/dev/null || true - name: Run pgactive extended tests run: | cd pgactive - make PROVE_FLAGS="--timer -v" prove_check + if [ "$USE_MESON" = "1" ]; then + export PATH=$GITHUB_WORKSPACE/postgres/inst/bin:"$PATH" + meson test -C build --suite tap --print-errorlogs + else + make PROVE_FLAGS="--timer -v" prove_check + fi - name: Upload test artifacts if: ${{ failure() }} uses: actions/upload-artifact@v4 with: - name: test-artifact-${{ matrix.os }}-${{ matrix.version }} + name: test-artifact-${{ matrix.os }}-${{ matrix.version.branch }} path: | postgres/pgindent.diffs pgactive/test/regression.diffs pgactive/test/tmp_check/log + pgactive/build/meson-logs + pgactive/build/tmp_check/log retention-days: 1 diff --git a/meson.build b/meson.build index 978605fa..cbd5ba1a 100644 --- a/meson.build +++ b/meson.build @@ -1,11 +1,14 @@ project( 'pgactive', 'c', - version: '2.1.9', + version: run_command( + 'sh', '-c', + 'sed -n \'s/^#define[[:space:]]\\+pgactive_VERSION[[:space:]]\\+"\\([^"]*\\)".*/\\1/p\' include/pgactive_version.h.in', + check: true, + ).stdout().strip(), license: 'Apache-2.0', - meson_version: '>= 0.57.0', + meson_version: '>= 0.58.0', default_options: [ - 'c_std=gnu99', 'warning_level=2', ], ) @@ -22,6 +25,7 @@ pg_config = find_program( pg_bindir = run_command(pg_config, '--bindir', check: true).stdout().strip() pg_includedir = run_command(pg_config, '--includedir', check: true).stdout().strip() pg_includedir_server = run_command(pg_config, '--includedir-server', check: true).stdout().strip() +pg_pkgincludedir = run_command(pg_config, '--pkgincludedir', check: true).stdout().strip() pg_pkglibdir = run_command(pg_config, '--pkglibdir', check: true).stdout().strip() pg_sharedir = run_command(pg_config, '--sharedir', check: true).stdout().strip() pg_libdir = run_command(pg_config, '--libdir', check: true).stdout().strip() @@ -37,26 +41,23 @@ pg_major = run_command('sh', '-c', message('Building against PostgreSQL @0@'.format(pg_major)) pg_inc = include_directories(pg_includedir, pg_includedir_server) -pg_inc_internal = include_directories(pg_includedir / 'postgresql' / 'internal') +pg_inc_internal = include_directories(pg_pkgincludedir / 'internal') # pgxs directory (for test perl modules and pg_regress) pgxs_dir = run_command('dirname', pg_pgxs, check: true).stdout().strip() pgxs_basedir = run_command('dirname', pgxs_dir, check: true).stdout().strip() -# libpq -libpq = dependency('libpq', required: false) -if not libpq.found() - libpq = declare_dependency( - include_directories: include_directories( - run_command(pg_config, '--includedir', check: true).stdout().strip(), - ), - dependencies: [ - meson.get_compiler('c').find_library('pq', - dirs: [pg_libdir], - ), - ], - ) -endif +# libpq — must be the copy that belongs to THIS pg_config, not whatever a +# system pkg-config/cmake happens to find first. A generic dependency('libpq') +# would prefer a distro libpq (e.g. /usr/lib64 via libpq.pc) over the target +# server's, an ABI mismatch when building against a custom-prefix install. +# pg_config's --libdir/--includedir are authoritative, exactly as PGXS uses them. +libpq = declare_dependency( + include_directories: include_directories(pg_includedir), + dependencies: [ + meson.get_compiler('c').find_library('pq', dirs: [pg_libdir]), + ], +) # pgfeutils (needed by pgactive_dump) cc = meson.get_compiler('c') @@ -174,6 +175,9 @@ pgactive_lib = shared_module( name_prefix: '', install: true, install_dir: pg_pkglibdir, + # Resolve the same libpq at runtime that we linked from pg_config --libdir, + # not a system copy — matters for custom-prefix servers not in ldconfig. + install_rpath: pg_libdir, ) # ---- pgactive_init_copy binary ---- @@ -187,6 +191,7 @@ pgactive_init_copy = executable( dependencies: [libpq, libpgport, libpgcommon], install: true, install_dir: pg_bindir, + install_rpath: pg_libdir, ) # ---- pgactive_dump binary ---- @@ -233,6 +238,7 @@ pgactive_dump = executable( dependencies: [libpq, libpgfeutils, libpgport, libpgcommon, libssl, libz, liblz4, libzstd], install: true, install_dir: pg_bindir, + install_rpath: pg_libdir, ) # ---- Extension data files ----