Skip to content

Commit 4f3fc1a

Browse files
jfrochesamrose
authored andcommitted
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.
1 parent 4db4d5b commit 4f3fc1a

File tree

4 files changed

+94
-10
lines changed

4 files changed

+94
-10
lines changed

nix/cargo-pgrx/buildPgrxExtension.nix

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,13 @@
2626
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2727
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2828
# SOFTWARE.
29-
3029
{
3130
lib,
3231
cargo-pgrx,
3332
pkg-config,
3433
rustPlatform,
3534
stdenv,
36-
Security,
35+
darwin,
3736
writeShellScriptBin,
3837
}:
3938

@@ -112,7 +111,9 @@ let
112111
# so we don't accidentally `(rustPlatform.buildRustPackage argsForBuildRustPackage) // { ... }` because
113112
# we forgot parentheses
114113
finalArgs = argsForBuildRustPackage // {
115-
buildInputs = (args.buildInputs or [ ]) ++ lib.optionals stdenv.hostPlatform.isDarwin [ Security ];
114+
buildInputs =
115+
(args.buildInputs or [ ])
116+
++ lib.optionals stdenv.hostPlatform.isDarwin [ darwin.apple_sdk.frameworks.Security ];
116117

117118
nativeBuildInputs =
118119
(args.nativeBuildInputs or [ ])
@@ -156,6 +157,7 @@ let
156157
cargo-pgrx pgrx stop all
157158
158159
mv $out/${postgresql}/* $out
160+
mv $out/${postgresql.lib}/* $out
159161
rm -rf $out/nix
160162
161163
${maybeLeaveBuildAndTestSubdir}

nix/cargo-pgrx/default.nix

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
makeRustPlatform,
88
stdenv,
99
rust-bin,
10+
rustVersion ? "1.85.1",
1011
}:
1112
let
12-
rustVersion = "1.85.1";
1313
rustPlatform = makeRustPlatform {
1414
cargo = rust-bin.stable.${rustVersion}.default;
1515
rustc = rust-bin.stable.${rustVersion}.default;
1616
};
17-
generic =
17+
mkCargoPgrx =
1818
{
1919
version,
2020
hash,
@@ -57,25 +57,25 @@ let
5757
};
5858
in
5959
{
60-
cargo-pgrx_0_11_3 = generic {
60+
cargo-pgrx_0_11_3 = mkCargoPgrx {
6161
version = "0.11.3";
6262
hash = "sha256-UHIfwOdXoJvR4Svha6ud0FxahP1wPwUtviUwUnTmLXU=";
6363
cargoHash = "sha256-j4HnD8Zt9uhlV5N7ldIy9564o9qFEqs5KfXHmnQ1WEw=";
6464
};
65-
cargo-pgrx_0_12_6 = generic {
65+
cargo-pgrx_0_12_6 = mkCargoPgrx {
6666
version = "0.12.6";
6767
hash = "sha256-7aQkrApALZe6EoQGVShGBj0UIATnfOy2DytFj9IWdEA=";
6868
cargoHash = "sha256-Di4UldQwAt3xVyvgQT1gUhdvYUVp7n/a72pnX45kP0w=";
6969
};
70-
cargo-pgrx_0_12_9 = generic {
70+
cargo-pgrx_0_12_9 = mkCargoPgrx {
7171
version = "0.12.9";
7272
hash = "sha256-aR3DZAjeEEAjLQfZ0ZxkjLqTVMIEbU0UiZ62T4BkQq8=";
7373
cargoHash = "sha256-KTKcol9qSNLQZGW32e6fBb6cPkUGItknyVpLdBYqrBY=";
7474
};
75-
cargo-pgrx_0_14_3 = generic {
75+
cargo-pgrx_0_14_3 = mkCargoPgrx {
7676
version = "0.14.3";
7777
hash = "sha256-3TsNpEqNm3Uol5XPW1i0XEbP2fF2+RKB2d7lO6BDnvQ=";
7878
cargoHash = "sha256-Ny7j56pwB+2eEK62X0nWfFKQy5fBz+Q1oyvecivxLkk=";
7979
};
80-
inherit rustPlatform;
80+
inherit mkCargoPgrx;
8181
}

nix/cargo-pgrx/mkPgrxExtension.nix

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
callPackage,
3+
rustVersion,
4+
pgrxVersion,
5+
makeRustPlatform,
6+
rust-bin,
7+
}:
8+
let
9+
inherit
10+
(
11+
(callPackage ./default.nix {
12+
inherit rustVersion;
13+
})
14+
)
15+
mkCargoPgrx
16+
;
17+
18+
rustPlatform = makeRustPlatform {
19+
cargo = rust-bin.stable.${rustVersion}.default;
20+
rustc = rust-bin.stable.${rustVersion}.default;
21+
};
22+
23+
versions = builtins.fromJSON (builtins.readFile ./versions.json);
24+
25+
cargo-pgrx =
26+
let
27+
pgrx =
28+
versions.${pgrxVersion}
29+
or (throw "Unsupported pgrx version ${pgrxVersion}. Available versions: ${builtins.attrNames versions}. Change 'nix/cargo-pgrx/versions.json' to add support for new versions.");
30+
mapping = {
31+
inherit (pgrx) hash;
32+
cargoHash =
33+
pgrx.rust."${rustVersion}".cargoHash
34+
or (throw "Unsupported rust version ${rustVersion} for pgrx version ${pgrxVersion}. Available Rust versions: ${builtins.attrNames pgrx.rust}. Change 'nix/cargo-pgrx/versions.json' to add support for new versions.");
35+
};
36+
in
37+
mkCargoPgrx {
38+
inherit (mapping) hash cargoHash;
39+
version = pgrxVersion;
40+
};
41+
in
42+
callPackage ./buildPgrxExtension.nix {
43+
inherit rustPlatform;
44+
inherit cargo-pgrx;
45+
}

nix/cargo-pgrx/versions.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"0.11.2": {
3+
"hash": "sha256-8NlpMDFaltTIA8G4JioYm8LaPJ2RGKH5o6sd6lBHmmM=",
4+
"rust": {
5+
"1.70.0": {
6+
"cargoHash": "sha256-qTb3JV3u42EilaK2jP9oa5D09mkuHyRbGGRs9Rg4TzI="
7+
},
8+
"1.85.1": {
9+
"cargoHash": "sha256-CbU5B0pvB9ApTZOdYP/ZwuIG8bqGzk/ING2PCM0q2bQ="
10+
}
11+
}
12+
},
13+
"0.11.3": {
14+
"hash": "sha256-UHIfwOdXoJvR4Svha6ud0FxahP1wPwUtviUwUnTmLXU=",
15+
"rust": {
16+
"1.85.1": {
17+
"cargoHash": "sha256-KBlT3FARjGcbtHIGDoC6ir3aNXXfDRmIoy990SOqoFg="
18+
}
19+
}
20+
},
21+
"0.12.6": {
22+
"hash": "sha256-7aQkrApALZe6EoQGVShGBj0UIATnfOy2DytFj9IWdEA=",
23+
"rust": {
24+
"1.81.0": {
25+
"cargoHash": "sha256-Di4UldQwAt3xVyvgQT1gUhdvYUVp7n/a72pnX45kP0w="
26+
}
27+
}
28+
},
29+
"0.12.9": {
30+
"hash": "sha256-aR3DZAjeEEAjLQfZ0ZxkjLqTVMIEbU0UiZ62T4BkQq8=",
31+
"rust": {
32+
"1.81.0": {
33+
"cargoHash": "sha256-53HKhvsKLTa2JCByLEcK3UzWXoM+LTatd98zvS1C9no="
34+
}
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)