-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Solves #5. This is done by avoiding building the postgres extension inside the nix derivation. Instead we build it with `make` on the current directory and install it on postgres using the upcoming postgres `extension_control_path` GUC. This is taken from the patch on https://www.postgresql.org/message-id/flat/E7C7BFFB-8857-48D4-A71F-88B359FADCFD%40justatheory.com and backpatched to postgres 12, 13, 14, 15 and 16, Thanks to this, it's now possible to do watch commands: ``` nxpg-watch nxpg-16 nxpg-build (rebuilds when changing sources) nxpg-watch nxpg-13 nxpg-tmp nxpg-test (runs tests when changing sources) ``` Future improvements: * Makes possible to enable code coverage, since the `.gcno` files will live outside the nix store. * It's wasteful to rebuild the patched pgs everytime, later on this `nxpg` could live in another repo and benefit from Nix caching. Additionally: * removes clean_generated in favor of builtin EXTRA_CLEAN * Don't hardcode sources in Makefile * Update github action
- Loading branch information
1 parent
676178d
commit 51be9a8
Showing
12 changed files
with
2,560 additions
and
79 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,32 @@ | ||
## Our variables | ||
EXTENSION = plmustache | ||
EXTVERSION = 0.1 | ||
SED ?= sed | ||
|
||
DATA = $(wildcard sql/*--*.sql) | ||
## PGXS variables | ||
PG_CONFIG = pg_config | ||
PGXS := $(shell $(PG_CONFIG) --pgxs) | ||
|
||
MODULE_big = $(EXTENSION) | ||
OBJS = src/plmustache.o src/observation.o src/build.o | ||
SRC = $(wildcard src/*.c) | ||
OBJS = $(patsubst src/%.c, src/%.o, $(SRC)) | ||
SHLIB_LINK = -lmustach | ||
PG_CFLAGS = -std=c99 -Wno-declaration-after-statement -Wall -Werror -Wshadow | ||
|
||
TESTS = $(wildcard test/sql/*.sql) | ||
REGRESS = $(patsubst test/sql/%.sql,%,$(TESTS)) | ||
REGRESS_OPTS = --inputdir=test | ||
|
||
PG_CONFIG = pg_config | ||
SHLIB_LINK = -lmustach | ||
|
||
PG_CFLAGS = -std=c99 -Wno-declaration-after-statement -Wall -Werror -Wshadow | ||
|
||
PGXS := $(shell $(PG_CONFIG) --pgxs) | ||
|
||
all: sql/$(EXTENSION)--$(EXTVERSION).sql $(EXTENSION).control | ||
DATA = $(wildcard *--*.sql) | ||
|
||
.PHONY: clean_generated | ||
clean_generated: | ||
rm -f $(EXTENSION).control | ||
rm -f sql/$(EXTENSION)--$(EXTVERSION).sql | ||
EXTRA_CLEAN = $(EXTENSION)--$(EXTVERSION).sql $(EXTENSION).control | ||
|
||
# extra dep for clean target in pgxs.mk | ||
clean: clean_generated | ||
all: $(EXTENSION)--$(EXTVERSION).sql $(EXTENSION).control | ||
|
||
sql/$(EXTENSION)--$(EXTVERSION).sql: sql/$(EXTENSION).sql | ||
$(EXTENSION)--$(EXTVERSION).sql: sql/$(EXTENSION).sql | ||
cp $< $@ | ||
|
||
$(EXTENSION).control: | ||
sed "s/@EXTVERSION@/$(EXTVERSION)/g" $(EXTENSION).control.in > $(EXTENSION).control | ||
$(SED) "s/@EXTVERSION@/$(EXTVERSION)/g" $(EXTENSION).control.in > $@ | ||
|
||
include $(PGXS) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
{ writeShellScriptBin, findutils, entr, callPackage, postgresql_16, postgresql_15, postgresql_14, postgresql_13, postgresql_12 } : | ||
let | ||
prefix = "nxpg"; | ||
supportedPgs = [ | ||
postgresql_16 | ||
postgresql_15 | ||
postgresql_14 | ||
postgresql_13 | ||
postgresql_12 | ||
]; | ||
build = | ||
writeShellScriptBin "${prefix}-build" '' | ||
set -euo pipefail | ||
make clean | ||
make | ||
''; | ||
test = | ||
writeShellScriptBin "${prefix}-test" '' | ||
set -euo pipefail | ||
make clean | ||
make | ||
make installcheck | ||
''; | ||
|
||
watch = | ||
writeShellScriptBin "${prefix}-watch" '' | ||
set -euo pipefail | ||
${findutils}/bin/find . -type f \( -name '*.c' -o -name '*.h' \) | ${entr}/bin/entr -dr "$@" | ||
''; | ||
|
||
tmpDb = | ||
writeShellScriptBin "${prefix}-tmp" '' | ||
set -euo pipefail | ||
export tmpdir="$(mktemp -d)" | ||
export PGDATA="$tmpdir" | ||
export PGHOST="$tmpdir" | ||
export PGUSER=postgres | ||
export PGDATABASE=postgres | ||
trap 'pg_ctl stop -m i && rm -rf "$tmpdir"' sigint sigterm exit | ||
PGTZ=UTC initdb --no-locale --encoding=UTF8 --nosync -U "$PGUSER" | ||
# pg versions older than 16 don't support adding "-c" to initdb to add these options | ||
# so we just modify the resulting postgresql.conf to avoid an error | ||
echo "dynamic_library_path='\$libdir:$(pwd)'" >> $PGDATA/postgresql.conf | ||
echo "extension_control_path='\$system:$(pwd)'" >> $PGDATA/postgresql.conf | ||
default_options="-F -c listen_addresses=\"\" -k $PGDATA" | ||
pg_ctl start -o "$default_options" | ||
"$@" | ||
''; | ||
allPgPaths = map (pg: | ||
let | ||
ver = builtins.head (builtins.splitVersion pg.version); | ||
patchedPg = pg.overrideAttrs(oldAttrs: { | ||
patches = oldAttrs.patches ++ [ | ||
./patches/${ver}-add-extension_control_path-for.patch | ||
]; | ||
}); | ||
script = '' | ||
set -euo pipefail | ||
export PATH=${patchedPg}/bin:"$PATH" | ||
"$@" | ||
''; | ||
in | ||
writeShellScriptBin "${prefix}-${ver}" script | ||
) supportedPgs; | ||
in | ||
[ | ||
build | ||
test | ||
watch | ||
tmpDb | ||
allPgPaths | ||
] |
Oops, something went wrong.