Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,66 @@ jobs:
- name: Test Makefile source installation
run: ./scripts/test-make-install.sh

macos_source_install:
name: macOS Source Install (PG17)
runs-on: macos-latest
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0

- name: Install Rust stable
run: |
rustup toolchain install stable --profile minimal
rustup default stable

- name: Install PostgreSQL and cargo-pgrx
run: |
brew install postgresql@17
cargo install cargo-pgrx --version 0.16.1 --locked
PG_CONFIG="$(brew --prefix postgresql@17)/bin/pg_config"
cargo pgrx init --pg17 "$PG_CONFIG"
echo "PG_CONFIG=$PG_CONFIG" >> "$GITHUB_ENV"

- name: Test source package installation
run: |
./scripts/test-make-install.sh
make package PG_CONFIG="$PG_CONFIG"

stage_dir="$RUNNER_TEMP/pg-durable-stage"
make install PG_CONFIG="$PG_CONFIG" DESTDIR="$stage_dir"
pkglibdir="$($PG_CONFIG --pkglibdir)"
extension_dir="$($PG_CONFIG --sharedir)/extension"
test -f "$stage_dir$pkglibdir/pg_durable.dylib"
test -f "$stage_dir$extension_dir/pg_durable.control"
make uninstall PG_CONFIG="$PG_CONFIG" DESTDIR="$stage_dir"
test ! -e "$stage_dir$pkglibdir/pg_durable.dylib"
test ! -e "$stage_dir$extension_dir/pg_durable.control"
test -z "$(find "$stage_dir$extension_dir" -name 'pg_durable--*.sql' -print -quit)"

make install PG_CONFIG="$PG_CONFIG"
bindir="$($PG_CONFIG --bindir)"
data_dir="$RUNNER_TEMP/pg-durable-data"
cleanup() {
"$bindir/pg_ctl" -D "$data_dir" -m immediate stop >/dev/null 2>&1 || true
make uninstall PG_CONFIG="$PG_CONFIG" >/dev/null 2>&1 || true
}
trap cleanup EXIT
"$bindir/initdb" -D "$data_dir" --no-locale --encoding=UTF8
cat >> "$data_dir/postgresql.conf" <<EOF
shared_preload_libraries = 'pg_durable'
port = 55432
unix_socket_directories = '$RUNNER_TEMP'
EOF
"$bindir/pg_ctl" -D "$data_dir" -l "$RUNNER_TEMP/postgresql.log" start
"$bindir/psql" -h "$RUNNER_TEMP" -p 55432 -d postgres -v ON_ERROR_STOP=1 \
-c 'CREATE EXTENSION pg_durable;' \
-c "SELECT extversion FROM pg_extension WHERE extname = 'pg_durable';"
"$bindir/pg_ctl" -D "$data_dir" -m fast stop
make uninstall PG_CONFIG="$PG_CONFIG"
trap - EXIT
test ! -e "$pkglibdir/pg_durable.dylib"
test ! -e "$extension_dir/pg_durable.control"
test -z "$(find "$extension_dir" -name 'pg_durable--*.sql' -print -quit)"

format:
name: Format Check
runs-on: ubuntu-latest
Expand Down
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,13 @@ endif
DEFAULT_PGRX_PACKAGE_DIR = $(CURDIR)/target/release/pg_durable-pg$(PG_MAJOR)
PGRX_PACKAGE_DIR ?= $(DEFAULT_PGRX_PACKAGE_DIR)
PGRX_PACKAGE_MARKER = $(PGRX_PACKAGE_DIR).pg_durable-owned
PG_DLSUFFIX ?= $(if $(filter Darwin,$(shell uname -s)),.dylib,.so)

ifeq ($(filter installcheck,$(REQUESTED_GOALS)),)

PG_PKGLIBDIR = $(shell "$(PG_CONFIG)" --pkglibdir)
PG_EXTENSION_DIR = $(shell "$(PG_CONFIG)" --sharedir)/extension
PACKAGE_LIBRARY = $(PGRX_PACKAGE_DIR)$(PG_PKGLIBDIR)/pg_durable.so
PACKAGE_LIBRARY = $(PGRX_PACKAGE_DIR)$(PG_PKGLIBDIR)/pg_durable$(PG_DLSUFFIX)
PACKAGE_EXTENSION_DIR = $(PGRX_PACKAGE_DIR)$(PG_EXTENSION_DIR)
# Same directories relative to the package root, for auditing the packaged tree.
PG_PKGLIBDIR_REL = $(patsubst /%,%,$(PG_PKGLIBDIR))
Expand All @@ -191,7 +192,7 @@ install:
set -- "$$package_extension_dir"/pg_durable--*.sql; \
test -f "$$1" || { echo "missing packaged SQL files; run 'make package' first" >&2; exit 1; }; \
unexpected="$$(cd "$(PGRX_PACKAGE_DIR)" && find . -type f \
! -path "./$(PG_PKGLIBDIR_REL)/pg_durable.so" \
! -path "./$(PG_PKGLIBDIR_REL)/pg_durable$(PG_DLSUFFIX)" \
! -path "./$(PG_EXTENSION_DIR_REL)/pg_durable.control" \
! -path "./$(PG_EXTENSION_DIR_REL)/pg_durable--*.sql")"; \
test -z "$$unexpected" || { \
Expand All @@ -200,7 +201,7 @@ install:
echo "the Debian package ships the whole tree, so a source install would silently differ from it; extend the install and uninstall recipes or exclude these files" >&2; \
exit 1; }; \
install -d -m 0755 "$(DESTDIR)$(PG_PKGLIBDIR)" "$(DESTDIR)$(PG_EXTENSION_DIR)"; \
install -m 0755 "$$package_library" "$(DESTDIR)$(PG_PKGLIBDIR)/pg_durable.so"; \
install -m 0755 "$$package_library" "$(DESTDIR)$(PG_PKGLIBDIR)/pg_durable$(PG_DLSUFFIX)"; \
install -m 0644 "$$package_extension_dir/pg_durable.control" "$$@" "$(DESTDIR)$(PG_EXTENSION_DIR)/"

# `pgxn uninstall` runs this target directly, without building first, so it must
Expand All @@ -209,7 +210,7 @@ install:
uninstall:
@set -eu; \
extension_dir="$(DESTDIR)$(PG_EXTENSION_DIR)"; \
library="$(DESTDIR)$(PG_PKGLIBDIR)/pg_durable.so"; \
library="$(DESTDIR)$(PG_PKGLIBDIR)/pg_durable$(PG_DLSUFFIX)"; \
removed=0; \
if test -e "$$library"; then rm -f "$$library"; removed=1; fi; \
if test -e "$$extension_dir/pg_durable.control"; then rm -f "$$extension_dir/pg_durable.control"; removed=1; fi; \
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,10 @@ make PG_CONFIG="$PG_CONFIG"
sudo make install PG_CONFIG="$PG_CONFIG"
```

PostgreSQL 17 and 18 are supported. Set `EXTRA_FEATURES` on the build command
to enable an HTTP policy feature. `DESTDIR` may be set on `make install` when
staging files for a package.
Source installation is supported on Linux and macOS for PostgreSQL 17 and 18.
Windows source installation is not currently supported. Set `EXTRA_FEATURES`
on the build command to enable an HTTP policy feature. `DESTDIR` may be set on
`make install` when staging files for a package.

`sudo make uninstall PG_CONFIG="$PG_CONFIG"` removes the installed files again.
It needs no build, so it also works from an unbuilt source tree.
Expand Down
3 changes: 2 additions & 1 deletion scripts/pg-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ cd "$PROJECT_DIR"
if [ "$BUILD_MODE" = "auto" ]; then
PKGLIBDIR=$("$PG_CONFIG" --pkglibdir)
SHAREDIR=$("$PG_CONFIG" --sharedir)
if [ -f "$PKGLIBDIR/pg_durable.so" ] && [ -f "$SHAREDIR/extension/pg_durable.control" ]; then
DLSUFFIX=$([[ "$(uname -s)" == "Darwin" ]] && printf '.dylib' || printf '.so')
if [ -f "$PKGLIBDIR/pg_durable$DLSUFFIX" ] && [ -f "$SHAREDIR/extension/pg_durable.control" ]; then
BUILD_MODE="skip"
echo -e "\033[0;33mExisting pg_durable install detected for PG${PG_MAJOR}; skipping build/install. Use --build to force.\033[0m"
else
Expand Down
7 changes: 4 additions & 3 deletions scripts/test-coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,11 @@ export RUSTFLAGS="-C instrument-coverage"

cargo pgrx install --pg-config="$PG_CONFIG" 2>&1 | grep -v "^warning:" || true

# Find the installed .so
SO_FILE=$(ls "$HOME"/.pgrx/"$PG_VERSION".*/pgrx-install/lib/postgresql/pg_durable.so 2>/dev/null | head -1)
# Find the installed extension library.
DLSUFFIX=$([[ "$(uname -s)" == "Darwin" ]] && printf '.dylib' || printf '.so')
SO_FILE=$(ls "$HOME"/.pgrx/"$PG_VERSION".*/pgrx-install/lib/postgresql/pg_durable"$DLSUFFIX" 2>/dev/null | head -1)
if [ -z "$SO_FILE" ]; then
echo -e "${RED}Error: pg_durable.so not found after install${NC}"
echo -e "${RED}Error: pg_durable$DLSUFFIX not found after install${NC}"
exit 1
fi
echo " Instrumented binary: $SO_FILE"
Expand Down
42 changes: 27 additions & 15 deletions scripts/test-make-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
TEST_DIR="$(mktemp -d)"
trap 'rm -rf "$TEST_DIR"' EXIT

file_mode() {
stat -c %a "$1" 2>/dev/null || stat -f %Lp "$1"
}

create_pg_config() {
local major="$1"
local path="$TEST_DIR/pg_config-$major"
Expand Down Expand Up @@ -73,7 +77,7 @@ done
pkglibdir="$($pg_config --pkglibdir)"
extension_dir="$($pg_config --sharedir)/extension"
mkdir -p "$out_dir$pkglibdir" "$out_dir$extension_dir"
printf 'shared library\n' > "$out_dir$pkglibdir/pg_durable.so"
printf 'shared library\n' > "$out_dir$pkglibdir/pg_durable${PG_DLSUFFIX:-.so}"
printf "default_version = '0.2.6'\n" > "$out_dir$extension_dir/pg_durable.control"
printf 'install sql\n' > "$out_dir$extension_dir/pg_durable--0.2.6.sql"
printf 'upgrade sql\n' > "$out_dir$extension_dir/pg_durable--0.2.5--0.2.6.sql"
Expand All @@ -95,26 +99,31 @@ fi
grep -F "refusing to replace unowned package directory" "$TEST_DIR/unowned.out" > /dev/null
test -f "$unowned_dir/unrelated-file"

for major in 17 18; do
for test_case in 17:.so 18:.so 17:.dylib 18:.dylib; do
major="${test_case%%:*}"
dlsuffix="${test_case#*:}"
pg_config_variable="PG_CONFIG_$major"
pg_config="${!pg_config_variable}"
package_dir="$TEST_DIR/package $major"
stage_dir="$TEST_DIR/stage-$major"
suffix_label="${dlsuffix#.}"
package_dir="$TEST_DIR/package $major-$suffix_label"
stage_dir="$TEST_DIR/stage-$major-$suffix_label"

: > "$CARGO_LOG"
if [[ "$major" == "17" ]]; then
if [[ "$test_case" == "17:.so" ]]; then
make --no-print-directory package \
PG_CONFIG="$pg_config" \
CARGO="$FAKE_CARGO" \
PGRX_PACKAGE_DIR="$package_dir" \
PG_DLSUFFIX="$dlsuffix" \
EXTRA_FEATURES=http-allow-azure-domains
grep -F -- "--features pg17\\ http-allow-azure-domains" "$CARGO_LOG" > /dev/null
else
make --no-print-directory \
PG_VERSION=pg18 \
PG_VERSION="pg$major" \
CARGO="$FAKE_CARGO" \
PGRX_PACKAGE_DIR="$package_dir"
grep -F -- "--features pg18" "$CARGO_LOG" > /dev/null
PGRX_PACKAGE_DIR="$package_dir" \
PG_DLSUFFIX="$dlsuffix"
grep -F -- "--features pg$major" "$CARGO_LOG" > /dev/null
fi
cargo_calls="$(wc -l < "$CARGO_LOG")"

Expand All @@ -123,16 +132,17 @@ for major in 17 18; do
CARGO=/missing/cargo \
PGXS=/caller/supplied/pgxs.mk \
PGRX_PACKAGE_DIR="$package_dir" \
PG_DLSUFFIX="$dlsuffix" \
DESTDIR="$stage_dir" > /dev/null

test "$(wc -l < "$CARGO_LOG")" -eq "$cargo_calls"
test -f "$stage_dir/usr/lib/postgresql/$major/lib/pg_durable.so"
test -f "$stage_dir/usr/lib/postgresql/$major/lib/pg_durable$dlsuffix"
test -f "$stage_dir/usr/share/postgresql/$major/extension/pg_durable.control"
test -f "$stage_dir/usr/share/postgresql/$major/extension/pg_durable--0.2.6.sql"
test -f "$stage_dir/usr/share/postgresql/$major/extension/pg_durable--0.2.5--0.2.6.sql"
test "$(stat -c %a "$stage_dir/usr/lib/postgresql/$major/lib/pg_durable.so")" = "755"
test "$(stat -c %a "$stage_dir/usr/share/postgresql/$major/extension/pg_durable.control")" = "644"
test "$(stat -c %a "$stage_dir/usr/share/postgresql/$major/extension/pg_durable--0.2.6.sql")" = "644"
test "$(file_mode "$stage_dir/usr/lib/postgresql/$major/lib/pg_durable$dlsuffix")" = "755"
test "$(file_mode "$stage_dir/usr/share/postgresql/$major/extension/pg_durable.control")" = "644"
test "$(file_mode "$stage_dir/usr/share/postgresql/$major/extension/pg_durable--0.2.6.sql")" = "644"

printf 'unrelated library\n' > "$stage_dir/usr/lib/postgresql/$major/lib/other_extension.so"
printf 'unrelated control\n' > "$stage_dir/usr/share/postgresql/$major/extension/other_extension.control"
Expand All @@ -149,10 +159,11 @@ for major in 17 18; do
CARGO=/missing/cargo \
PGXS=/caller/supplied/pgxs.mk \
PGRX_PACKAGE_DIR="$TEST_DIR/missing-package" \
PG_DLSUFFIX="$dlsuffix" \
DESTDIR="$stage_dir" > /dev/null

test "$(wc -l < "$CARGO_LOG")" -eq "$cargo_calls"
test ! -e "$stage_dir/usr/lib/postgresql/$major/lib/pg_durable.so"
test ! -e "$stage_dir/usr/lib/postgresql/$major/lib/pg_durable$dlsuffix"
test ! -e "$stage_dir/usr/share/postgresql/$major/extension/pg_durable.control"
test -z "$(find "$stage_dir/usr/share/postgresql/$major/extension" -name 'pg_durable--*.sql')"
test -f "$stage_dir/usr/lib/postgresql/$major/lib/other_extension.so"
Expand All @@ -162,6 +173,7 @@ for major in 17 18; do
# Removing twice is not an error; a partial install must always be cleanable.
make --no-print-directory uninstall \
PG_CONFIG="$pg_config" \
PG_DLSUFFIX="$dlsuffix" \
DESTDIR="$stage_dir" > "$TEST_DIR/uninstall-again-$major.out"
grep -F "nothing to remove" "$TEST_DIR/uninstall-again-$major.out" > /dev/null
done
Expand All @@ -183,7 +195,7 @@ grep -F "run 'make package' first" "$TEST_DIR/missing.out" > /dev/null

for artifact in control sql; do
partial_dir="$TEST_DIR/partial-$artifact"
cp -a "$TEST_DIR/package 17" "$partial_dir"
cp -a "$TEST_DIR/package 17-so" "$partial_dir"
if [[ "$artifact" == "control" ]]; then
rm "$partial_dir/usr/share/postgresql/17/extension/pg_durable.control"
expected_error="missing packaged control file"
Expand Down Expand Up @@ -212,7 +224,7 @@ grep -F "run 'make install' or 'make uninstall' and 'make installcheck' as separ
# set of files, so an unexpected artifact must fail loudly rather than be dropped
# silently from source installs.
stray_dir="$TEST_DIR/stray-package"
cp -a "$TEST_DIR/package 17" "$stray_dir"
cp -a "$TEST_DIR/package 17-so" "$stray_dir"
printf 'bitcode\n' > "$stray_dir/usr/lib/postgresql/17/lib/pg_durable.bc"
if make --no-print-directory install \
PG_CONFIG="$PG_CONFIG_17" \
Expand Down
Loading