Skip to content

Commit d584651

Browse files
jfrochesamrose
andauthored
feat: support multiple versions of the pg-graphql extension (#1761)
* feat(pg_graphql): build multiple versions of the pg_graphql extension Build multiple versions of the pg_graphql extension on different PostgreSQL versions. Add test for the extensions and their upgrade on PostgreSQL 15 and 17. * feat(cargo-pgrx): build extensions with specified Rust version This change allows developers to target specific Rust versions for building extensions. It implements support for building cargo extensions and `cargo-pgrx` using the specified Rust version. * Build pg_graphql 1.4.2 using pgrx 0.10.2 * Build pg_graphql 1.4.1 using pgrx 0.10.2 * Build pg_graphql 1.2.3 using pgrx 0.9.7 * Build pg_graphql 1.2.2 using pgrx 0.9.5 * Build pg_graphql 1.2.0 using pgx 0.7.1 * Build pg_graphql 1.1.0 using pgx 0.6.1 * Refactoring and build pg_graphql 1.0.2 using pgx 0.6.1 * chore: add release suffix for testing * fix: conditional for using this linking only with macos * fix: bindgen * fix: apply bindgen fix for aarch64 to versions up to 1.5.1 The issue we face when building pg_graphql on aarch64 is: `Invalid or unknown abi 16 for function "_ZGVnN4vv_atan2f"` It has been fixed in bindgen 0.11.3. * chore: use default nixos test to test pg_graphql extension * fix(pg_graphql): migration script from 1.5.1-mergeless to 1.5.4 Add special case handling for 1.5.1-mergeless to 1.5.4 upgrade path. Also replace CREATE FUNCTION with CREATE OR REPLACE FUNCTION to prevent conflicts in migration scripts and the same for event triggers. * fix: do not apply bindgen fix for version 1.5.4 pg_graphql 1.5.4 uses pgrx 0.11.3 which fixed the ABI issues on aarch64-linux. * feat: run pg_regress tests during build We don't recompile the extension using pgx with dev/debug symbols, but we do run the pg_regress tests to ensure everything is working correctly. * chore: bump to release --------- Co-authored-by: Sam Rose <[email protected]>
1 parent 4d7f384 commit d584651

16 files changed

+12417
-68
lines changed

ansible/vars.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ postgres_major:
1010

1111
# Full version strings for each major version
1212
postgres_release:
13-
postgresorioledb-17: 17.5.1.034-orioledb
14-
postgres17: 17.6.1.013
15-
postgres15: 15.14.1.013
13+
postgresorioledb-17: "17.5.1.035-orioledb"
14+
postgres17: "17.6.1.014"
15+
postgres15: "15.14.1.014"
1616

1717
# Non Postgres Extensions
1818
pgbouncer_release: 1.19.0

nix/cargo-pgrx/buildPgrxExtension.nix

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
buildFeatures ? [ ],
5454
cargoBuildFlags ? [ ],
5555
postgresql,
56+
# enable override to generate bindings using bindgenHook.
57+
# Some older versions of cargo-pgrx use a bindgenHook that is not compatible with the
58+
# current clang version present in stdenv
59+
bindgenHook ? rustPlatform.bindgenHook,
5660
# cargo-pgrx calls rustfmt on generated bindings, this is not strictly necessary, so we avoid the
5761
# dependency here. Set to false and provide rustfmt in nativeBuildInputs, if you need it, e.g.
5862
# if you include the generated code in the output via postInstall.
@@ -87,12 +91,14 @@ let
8791
pushd "${buildAndTestSubdir}"
8892
'';
8993
maybeLeaveBuildAndTestSubdir = lib.optionalString (buildAndTestSubdir != null) "popd";
94+
pgrxBinaryName = if builtins.compareVersions "0.7.4" cargo-pgrx.version >= 0 then "pgx" else "pgrx";
9095

9196
pgrxPostgresMajor = lib.versions.major postgresql.version;
9297
preBuildAndTest = ''
9398
export PGRX_HOME=$(mktemp -d)
99+
export PGX_HOME=$PGRX_HOME
94100
export PGDATA="$PGRX_HOME/data-${pgrxPostgresMajor}/"
95-
cargo-pgrx pgrx init "--pg${pgrxPostgresMajor}" ${lib.getDev postgresql}/bin/pg_config
101+
cargo-${pgrxBinaryName} ${pgrxBinaryName} init "--pg${pgrxPostgresMajor}" ${lib.getDev postgresql}/bin/pg_config
96102
97103
# unix sockets work in sandbox, too.
98104
export PGHOST="$(mktemp -d)"
@@ -127,7 +133,7 @@ let
127133
cargo-pgrx
128134
postgresql
129135
pkg-config
130-
rustPlatform.bindgenHook
136+
bindgenHook
131137
]
132138
++ lib.optionals useFakeRustfmt [ fakeRustfmt ];
133139

@@ -138,9 +144,10 @@ let
138144
${preBuildAndTest}
139145
${maybeEnterBuildAndTestSubdir}
140146
141-
PGRX_BUILD_FLAGS="--frozen -j $NIX_BUILD_CORES ${builtins.concatStringsSep " " cargoBuildFlags}" \
147+
export PGRX_BUILD_FLAGS="--frozen -j $NIX_BUILD_CORES ${builtins.concatStringsSep " " cargoBuildFlags}"
148+
export PGX_BUILD_FLAGS="$PGRX_BUILD_FLAGS"
142149
${lib.optionalString stdenv.hostPlatform.isDarwin ''RUSTFLAGS="''${RUSTFLAGS:+''${RUSTFLAGS} }-Clink-args=-Wl,-undefined,dynamic_lookup"''} \
143-
cargo pgrx package \
150+
cargo ${pgrxBinaryName} package \
144151
--pg-config ${lib.getDev postgresql}/bin/pg_config \
145152
${maybeDebugFlag} \
146153
--features "${builtins.concatStringsSep " " buildFeatures}" \
@@ -160,7 +167,7 @@ let
160167
161168
${maybeEnterBuildAndTestSubdir}
162169
163-
cargo-pgrx pgrx stop all
170+
cargo-${pgrxBinaryName} ${pgrxBinaryName} stop all
164171
165172
mv $out/${postgresql}/* $out
166173
mv $out/${postgresql.lib}/* $out

nix/cargo-pgrx/default.nix

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@ let
2020
hash,
2121
cargoHash,
2222
}:
23+
let
24+
pname = if builtins.compareVersions "0.7.4" version >= 0 then "cargo-pgx" else "cargo-pgrx";
25+
in
2326
rustPlatform.buildRustPackage rec {
2427
# rust-overlay uses 'cargo-auditable' wrapper for 'cargo' command, but it
2528
# is using older version 0.18.1 of 'cargo_metadata' which doesn't support
2629
# rust edition 2024, so we disable the 'cargo-auditable' just for now.
2730
# ref: https://github.com/oxalica/rust-overlay/issues/153
2831
auditable = false;
29-
pname = "cargo-pgrx";
32+
inherit pname;
3033
inherit version;
3134
src = fetchCrate { inherit version pname hash; };
3235
inherit cargoHash;

nix/cargo-pgrx/versions.json

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,44 @@
11
{
2+
"0.6.1": {
3+
"hash": "sha256-O4eHVbJBudybsPab+zr2eXnfheREMqLAHAKm2GDbfrs=",
4+
"rust": {
5+
"1.82.0": {
6+
"cargoHash": "sha256-MucGrA3qXgJOcT2LMNmoNOhQi8QA3LuqgZEHKycLCCo="
7+
}
8+
}
9+
},
10+
"0.7.1": {
11+
"hash": "sha256-t/gdlrBeP6KFkBFJiZUa8KKVJVYMf6753vQGKJdytss=",
12+
"rust": {
13+
"1.82.0": {
14+
"cargoHash": "sha256-muce9wT4LAJmfNLWWEShARnpZgglXe/KrfxlitmGgXk="
15+
}
16+
}
17+
},
18+
"0.9.5": {
19+
"hash": "sha256-GpXQUOBuojAqPXyRR+k8AVW2XzBbn6V0+2dhP4w4Vs8=",
20+
"rust": {
21+
"1.70.0": {
22+
"cargoHash": "sha256-YbwGh3tbt8W9/VOu11fTWO9fRMUlrwJnG4wxUHuyX10="
23+
}
24+
}
25+
},
26+
"0.9.7": {
27+
"hash": "sha256-uDBq7tUZ9f8h5nlRFR1mv4+Ty1OFtAk5P7OTNQPI1gI=",
28+
"rust": {
29+
"1.70.0": {
30+
"cargoHash": "sha256-YTkjqMNF+cz5XtELh7+l8KwvRoVKQP7t98nkJwkW218="
31+
}
32+
}
33+
},
34+
"0.10.2": {
35+
"hash": "sha256-FqjfbJmSy5UCpPPPk4bkEyvQCnaH9zYtkI7txgIn+ls=",
36+
"rust": {
37+
"1.70.0": {
38+
"cargoHash": "sha256-syZ3cQq8qDHBLvqmNDGoxeK6zXHJ47Jwkw3uhaXNCzI="
39+
}
40+
}
41+
},
242
"0.11.2": {
343
"hash": "sha256-8NlpMDFaltTIA8G4JioYm8LaPJ2RGKH5o6sd6lBHmmM=",
444
"rust": {
@@ -57,5 +97,4 @@
5797
}
5898
}
5999
}
60-
61100
}

nix/ext/pg_graphql.nix

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)