From d68bee54e30c724b06fffacad34d63f0bba8b053 Mon Sep 17 00:00:00 2001 From: Arun Sharma Date: Mon, 10 Aug 2026 08:38:05 -0700 Subject: [PATCH 1/2] build: make test harness build and run on macOS Three fixes so ./scripts/test.sh works on macOS against a pgembed-bundled PostgreSQL whose pg_config has a stale -isysroot baked in after an Xcode upgrade, and where an older liblbug may already be installed system-wide: - Makefile: add PG_LDFLAGS = -L/lib. PGXS prepends PG_LDFLAGS to LDFLAGS, so the vendored liblbug (0.19.1) is searched before any system liblbug (e.g. an older 0.18.0 under /opt/homebrew/lib) that pg_config's LDFLAGS would otherwise link first, causing 'undefined symbol: _lbug_connection_get_pushed_sql'. - scripts/test_with_pgembed.py: forward CC and PG_SYSROOT from the environment onto the make command line (command-line make vars override PGXS' plain '=' assignments; plain env vars do not). This lets a builder pick homebrew clang and a valid SDK to repair the stale -isysroot. Also resolve the shared library suffix dynamically (.so on Linux, .dylib on macOS) instead of hardcoding pg_ladybug.so, and prepend the embedded PG's bin/ to PATH so psql is found. - .gitignore: add *.dylib (macOS build product). --- .gitignore | 1 + Makefile | 4 ++++ scripts/test_with_pgembed.py | 25 ++++++++++++++++++++++--- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 2b2c05c..e4c42e6 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ lib/ *.o *.so *.bc +*.dylib diff --git a/Makefile b/Makefile index 2d84dea..dba5283 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,10 @@ EXTENSION = pg_ladybug DATA = pg_ladybug--1.0.sql OBJS = $(WIN32RES) pg_ladybug.o ladybug_bridge.o PG_CPPFLAGS = -I. +# Search the vendored lib/ *before* any system liblbug (PG_LDFLAGS is +# prepended to LDFLAGS by PGXS, so it wins over -L paths baked into pg_config, +# e.g. an older liblbug installed under /opt/homebrew/lib). +PG_LDFLAGS = -L$(CURDIR)/lib SHLIB_LINK = -L$(CURDIR)/lib -llbug -Wl,-rpath,$(CURDIR)/lib PG_CONFIG ?= pg_config diff --git a/scripts/test_with_pgembed.py b/scripts/test_with_pgembed.py index 00bbfff..6b66eb1 100644 --- a/scripts/test_with_pgembed.py +++ b/scripts/test_with_pgembed.py @@ -30,8 +30,17 @@ def main() -> int: print("=== Building pg_ladybug with", _pg_config, "===") env_build = os.environ.copy() env_build["PG_CONFIG"] = _pg_config - subprocess.run(["make", "clean"], cwd=repo_root, capture_output=True, text=True, env=env_build) - result = subprocess.run(["make"], cwd=repo_root, capture_output=True, text=True, env=env_build) + # Forward CC / PG_SYSROOT from the environment onto the make command line + # (command-line make vars override PGXS' `=` assignments; plain env vars + # do not). This lets a builder select a specific compiler and/or repair a + # stale -isysroot baked into a bundled pg_config after an Xcode upgrade. + make_overrides = [] + for var in ("CC", "PG_SYSROOT"): + val = env_build.get(var) + if val: + make_overrides.append(f"{var}={val}") + subprocess.run(["make", "clean", *make_overrides], cwd=repo_root, capture_output=True, text=True, env=env_build) + result = subprocess.run(["make", *make_overrides], cwd=repo_root, capture_output=True, text=True, env=env_build) if result.returncode != 0: print("Build FAILED:", result.stderr) return 1 @@ -49,7 +58,15 @@ def main() -> int: # ---- Install pg_ladybug into the embedded PG ---- pg_lib_dir = _pgembed_dir / "lib" / "postgresql" pg_share_dir = _pgembed_dir / "share" / "postgresql" / "extension" - shutil.copy(repo_root / "pg_ladybug.so", pg_lib_dir / "pg_ladybug.so") + # The shared library suffix is platform-dependent (.so on Linux, + # .dylib on macOS); pick up whichever the build actually produced. + shlib_path = next((repo_root / f"pg_ladybug.{ext}" + for ext in ("so", "dylib") + if (repo_root / f"pg_ladybug.{ext}").exists()), None) + if shlib_path is None: + print("Build FAILED: pg_ladybug shared library not found") + return 1 + shutil.copy(shlib_path, pg_lib_dir / shlib_path.name) shutil.copy(repo_root / "pg_ladybug--1.0.sql", pg_share_dir / "pg_ladybug--1.0.sql") shutil.copy(repo_root / "pg_ladybug.control", pg_share_dir / "pg_ladybug.control") print("Extension files installed") @@ -132,6 +149,8 @@ def run_test(name: str, sql: str, env, check: callable = None) -> bool: socket_dir = query.get("host", ["/tmp"])[0] env = os.environ.copy() + # Ensure the embedded PG's client binaries (psql) are on PATH. + env["PATH"] = f"{_pgembed_dir / 'bin'}{os.pathsep}{env.get('PATH', '')}" env["PGHOST"] = socket_dir env["PGPORT"] = "5432" env["PGUSER"] = "ci" From cd645bae285534606efdc1ed8a1a65ba26a0cd0b Mon Sep 17 00:00:00 2001 From: Arun Sharma Date: Mon, 10 Aug 2026 08:49:44 -0700 Subject: [PATCH 2/2] ci: avoid multiple runs on prs --- .github/workflows/ci.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8cb060f..0b9950e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,5 +1,12 @@ name: CI -on: [push, pull_request] +on: + pull_request: + branches: + - main + push: + branches: + - main + workflow_dispatch: jobs: test: strategy: