macos: relocate libpq to @rpath for Homebrew layout portability - #49
Merged
Conversation
The pg_client extension is linked in CI against the keg-only standalone 'libpq' Homebrew formula, which records an absolute install name of /opt/homebrew/opt/libpq/lib/libpq.5.dylib in the released binary. End users who install libpq via 'brew install postgresql@18' only (the common layout on Apple Silicon) have libpq at a different path, so dyld cannot resolve the dependency and the extension fails to load. Add scripts/relocate-macos-libpq.sh (mirroring the existing scripts/relocate-macos-openssl.sh pattern) to rewrite the install name to @rpath/libpq.5.dylib and add the common Homebrew locations as LC_RPATH fallbacks, plus scripts/verify-macos-libpq-rpaths.sh to assert the relocation in CI. Fixes #48.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #48
Problem
The macOS arm64
libpg_client.lbug_extension0.19.0 records the absolute install namewhich is provided only by the keg-only standalone
libpqHomebrew formula. Machines that install libpq viabrew install postgresql@18have it at/opt/homebrew/lib/postgresql@18/libpq.5.dylibinstead, so dyld cannot resolve the dependency andLOAD EXTENSIONfails.Fix
Adds two scripts mirroring the existing OpenSSL relocation pattern in the ladybug repo (
scripts/relocate-macos-openssl.sh/verify-macos-openssl-rpaths.sh):scripts/relocate-macos-libpq.sh— rewrites the libpq install name to@rpath/libpq.5.dyliband adds the common Homebrew locations asLC_RPATHfallbacks (standalonelibpqand bundledpostgresql@18, on both/opt/homebrewand/usr/local), then ad-hoc re-signs (install_name_tool invalidates the signature).scripts/verify-macos-libpq-rpaths.sh— asserts the@rpathdependency is present, no package-manager-specific absolute libpq path remains, and all rpaths exist.dyld silently skips
LC_RPATHentries pointing at non-existent directories, so the released binary loads in either Homebrew layout. Companion wiring lives in the ladybug repo (build-extensions.yml; PR will be linked) where the official macOS artifacts are built.Validation
Tested locally with a dylib linked against the standalone libpq formula:
@rpath/libpq.5.dylib+ adds all 6 rpaths; verify passes; relocation is idempotent