Skip to content

Commit f6cbbe7

Browse files
authored
Merge branch 'develop' into sam/oriole16
2 parents 0e23e7d + d7902e5 commit f6cbbe7

File tree

8 files changed

+365
-26
lines changed

8 files changed

+365
-26
lines changed

ansible/vars.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ groonga_release_checksum: sha256:1c2d1a6981c1ad3f02a11aff202b15ba30cb1c6147f1fa9
141141
pgroonga_release: "3.0.7"
142142
pgroonga_release_checksum: sha256:885ff3878cc30e9030e5fc56d561bc8b66df3ede1562c9d802bc0ea04fe5c203
143143

144-
wrappers_release: "0.4.2"
144+
wrappers_release: "0.4.3"
145145

146146
hypopg_release: "1.4.1"
147147
hypopg_release_checksum: sha256:9afe6357fd389d8d33fad81703038ce520b09275ec00153c6c89282bcdedd6bc

flake.lock

Lines changed: 36 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
flake-utils.url = "github:numtide/flake-utils";
77
nix2container.url = "github:nlewo/nix2container";
88
nix-editor.url = "github:snowfallorg/nix-editor";
9+
rust-overlay.url = "github:oxalica/rust-overlay";
910
};
1011

11-
outputs = { self, nixpkgs, flake-utils, nix2container, nix-editor, ...}:
12+
outputs = { self, nixpkgs, flake-utils, nix2container, nix-editor, rust-overlay, ...}:
1213
let
1314
gitRev = "vcs=${self.shortRev or "dirty"}+${builtins.substring 0 8 (self.lastModifiedDate or self.lastModified or "19700101")}";
1415

@@ -37,12 +38,42 @@
3738
# pull them from the overlays/ directory automatically, but we don't
3839
# want to have an arbitrary order, since it might matter. being
3940
# explicit is better.
41+
(import rust-overlay)
42+
(final: prev: {
43+
cargo-pgrx = final.callPackage ./nix/cargo-pgrx/default.nix {
44+
inherit (final) lib;
45+
inherit (final) darwin;
46+
inherit (final) fetchCrate;
47+
inherit (final) openssl;
48+
inherit (final) pkg-config;
49+
inherit (final) makeRustPlatform;
50+
inherit (final) stdenv;
51+
inherit (final) rust-bin;
52+
};
53+
54+
buildPgrxExtension = final.callPackage ./nix/cargo-pgrx/buildPgrxExtension.nix {
55+
inherit (final) cargo-pgrx;
56+
inherit (final) lib;
57+
inherit (final) Security;
58+
inherit (final) pkg-config;
59+
inherit (final) makeRustPlatform;
60+
inherit (final) stdenv;
61+
inherit (final) writeShellScriptBin;
62+
};
63+
64+
buildPgrxExtension_0_11_3 = prev.buildPgrxExtension.override {
65+
cargo-pgrx = final.cargo-pgrx.cargo-pgrx_0_11_3;
66+
};
67+
68+
buildPgrxExtension_0_12_6 = prev.buildPgrxExtension.override {
69+
cargo-pgrx = final.cargo-pgrx.cargo-pgrx_0_12_6;
70+
};
71+
})
4072
(final: prev: {
4173
postgresql = final.callPackage ./nix/postgresql/default.nix {
4274
inherit (final) lib stdenv fetchurl makeWrapper callPackage buildEnv newScope;
4375
};
4476
})
45-
(import ./nix/overlays/cargo-pgrx-0-11-3.nix)
4677
];
4778
};
4879
sfcgal = pkgs.callPackage ./nix/ext/sfcgal/sfcgal.nix { };
@@ -260,6 +291,8 @@
260291
in
261292
postgresVersions //{
262293
supabase-groonga = supabase-groonga;
294+
cargo-pgrx_0_11_3 = pkgs.cargo-pgrx.cargo-pgrx_0_11_3;
295+
cargo-pgrx_0_12_6 = pkgs.cargo-pgrx.cargo-pgrx_0_12_6;
263296
# PostgreSQL versions.
264297
psql_15 = postgresVersions.psql_15;
265298
psql_16 = postgresVersions.psql_16;
@@ -567,10 +600,7 @@
567600
packages = flake-utils.lib.flattenTree basePackages // {
568601
# Any extra packages we might want to include in our package
569602
# set can go here.
570-
inherit (pkgs)
571-
# NOTE: comes from our cargo-pgrx-0-11-3.nix overlay
572-
cargo-pgrx_0_11_3;
573-
603+
inherit (pkgs);
574604
};
575605

576606
# The list of exported 'checks' that are run with every run of 'nix
@@ -604,7 +634,21 @@
604634
# ambient $PATH environment when you run 'nix develop'. This is useful
605635
# for development and puts many convenient devtools instantly within
606636
# reach.
607-
devShells.default = pkgs.mkShell {
637+
638+
devShells = let
639+
mkCargoPgrxDevShell = { pgrxVersion, rustVersion }: pkgs.mkShell {
640+
packages = with pkgs; [
641+
basePackages."cargo-pgrx_${pgrxVersion}"
642+
(rust-bin.stable.${rustVersion}.default.override {
643+
extensions = [ "rust-src" ];
644+
})
645+
];
646+
shellHook = ''
647+
export HISTFILE=.history
648+
'';
649+
};
650+
in {
651+
default = pkgs.mkShell {
608652
packages = with pkgs; [
609653
coreutils
610654
just
@@ -627,6 +671,15 @@
627671
export HISTFILE=.history
628672
'';
629673
};
630-
}
631-
);
674+
cargo-pgrx_0_11_3 = mkCargoPgrxDevShell {
675+
pgrxVersion = "0_11_3";
676+
rustVersion = "1.80.0";
677+
};
678+
cargo-pgrx_0_12_6 = mkCargoPgrxDevShell {
679+
pgrxVersion = "0_12_6";
680+
rustVersion = "1.80.0";
681+
};
682+
};
683+
}
684+
);
632685
}

nix/cargo-pgrx/buildPgrxExtension.nix

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
# preBuildAndTest and some small other bits
2+
# taken from https://github.com/tcdi/pgrx/blob/v0.9.4/nix/extension.nix
3+
# (but now heavily modified)
4+
# which uses MIT License with the following license file
5+
#
6+
# MIT License
7+
#
8+
# Portions Copyright 2019-2021 ZomboDB, LLC.
9+
# Portions Copyright 2021-2022 Technology Concepts & Design, Inc. <[email protected]>.
10+
# All rights reserved.
11+
#
12+
# Permission is hereby granted, free of charge, to any person obtaining a copy
13+
# of this software and associated documentation files (the "Software"), to deal
14+
# in the Software without restriction, including without limitation the rights
15+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16+
# copies of the Software, and to permit persons to whom the Software is
17+
# furnished to do so, subject to the following conditions:
18+
#
19+
# The above copyright notice and this permission notice shall be included in all
20+
# copies or substantial portions of the Software.
21+
#
22+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28+
# SOFTWARE.
29+
30+
{ lib
31+
, cargo-pgrx
32+
, pkg-config
33+
, rustPlatform
34+
, stdenv
35+
, Security
36+
, writeShellScriptBin
37+
}:
38+
39+
# The idea behind: Use it mostly like rustPlatform.buildRustPackage and so
40+
# we hand most of the arguments down.
41+
#
42+
# Additional arguments are:
43+
# - `postgresql` postgresql package of the version of postgresql this extension should be build for.
44+
# Needs to be the build platform variant.
45+
# - `useFakeRustfmt` Whether to use a noop fake command as rustfmt. cargo-pgrx tries to call rustfmt.
46+
# If the generated rust bindings aren't needed to use the extension, its a
47+
# unnecessary and heavy dependency. If you set this to true, you also
48+
# have to add `rustfmt` to `nativeBuildInputs`.
49+
50+
{ buildAndTestSubdir ? null
51+
, buildType ? "release"
52+
, buildFeatures ? [ ]
53+
, cargoBuildFlags ? [ ]
54+
, postgresql
55+
# cargo-pgrx calls rustfmt on generated bindings, this is not strictly necessary, so we avoid the
56+
# dependency here. Set to false and provide rustfmt in nativeBuildInputs, if you need it, e.g.
57+
# if you include the generated code in the output via postInstall.
58+
, useFakeRustfmt ? true
59+
, usePgTestCheckFeature ? true
60+
, ...
61+
} @ args:
62+
let
63+
rustfmtInNativeBuildInputs = lib.lists.any (dep: lib.getName dep == "rustfmt") (args.nativeBuildInputs or []);
64+
in
65+
66+
assert lib.asserts.assertMsg ((args.installPhase or "") == "")
67+
"buildPgrxExtensions overwrites the installPhase, so providing one does nothing";
68+
assert lib.asserts.assertMsg ((args.buildPhase or "") == "")
69+
"buildPgrxExtensions overwrites the buildPhase, so providing one does nothing";
70+
assert lib.asserts.assertMsg (useFakeRustfmt -> !rustfmtInNativeBuildInputs)
71+
"The parameter useFakeRustfmt is set to true, but rustfmt is included in nativeBuildInputs. Either set useFakeRustfmt to false or remove rustfmt from nativeBuildInputs.";
72+
assert lib.asserts.assertMsg (!useFakeRustfmt -> rustfmtInNativeBuildInputs)
73+
"The parameter useFakeRustfmt is set to false, but rustfmt is not included in nativeBuildInputs. Either set useFakeRustfmt to true or add rustfmt from nativeBuildInputs.";
74+
75+
let
76+
fakeRustfmt = writeShellScriptBin "rustfmt" ''
77+
exit 0
78+
'';
79+
maybeDebugFlag = lib.optionalString (buildType != "release") "--debug";
80+
maybeEnterBuildAndTestSubdir = lib.optionalString (buildAndTestSubdir != null) ''
81+
export CARGO_TARGET_DIR="$(pwd)/target"
82+
pushd "${buildAndTestSubdir}"
83+
'';
84+
maybeLeaveBuildAndTestSubdir = lib.optionalString (buildAndTestSubdir != null) "popd";
85+
86+
pgrxPostgresMajor = lib.versions.major postgresql.version;
87+
preBuildAndTest = ''
88+
export PGRX_HOME=$(mktemp -d)
89+
export PGDATA="$PGRX_HOME/data-${pgrxPostgresMajor}/"
90+
cargo-pgrx pgrx init "--pg${pgrxPostgresMajor}" ${lib.getDev postgresql}/bin/pg_config
91+
echo "unix_socket_directories = '$(mktemp -d)'" > "$PGDATA/postgresql.conf"
92+
93+
# This is primarily for Mac or other Nix systems that don't use the nixbld user.
94+
export USER="$(whoami)"
95+
pg_ctl start
96+
createuser -h localhost --superuser --createdb "$USER" || true
97+
pg_ctl stop
98+
'';
99+
100+
argsForBuildRustPackage = builtins.removeAttrs args [ "postgresql" "useFakeRustfmt" "usePgTestCheckFeature" ];
101+
102+
# so we don't accidentally `(rustPlatform.buildRustPackage argsForBuildRustPackage) // { ... }` because
103+
# we forgot parentheses
104+
finalArgs = argsForBuildRustPackage // {
105+
buildInputs = (args.buildInputs or [ ]) ++ lib.optionals stdenv.hostPlatform.isDarwin [ Security ];
106+
107+
nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [
108+
cargo-pgrx
109+
postgresql
110+
pkg-config
111+
rustPlatform.bindgenHook
112+
] ++ lib.optionals useFakeRustfmt [ fakeRustfmt ];
113+
114+
buildPhase = ''
115+
runHook preBuild
116+
117+
echo "Executing cargo-pgrx buildPhase"
118+
${preBuildAndTest}
119+
${maybeEnterBuildAndTestSubdir}
120+
121+
PGRX_BUILD_FLAGS="--frozen -j $NIX_BUILD_CORES ${builtins.concatStringsSep " " cargoBuildFlags}" \
122+
${lib.optionalString stdenv.hostPlatform.isDarwin ''RUSTFLAGS="''${RUSTFLAGS:+''${RUSTFLAGS} }-Clink-args=-Wl,-undefined,dynamic_lookup"''} \
123+
cargo pgrx package \
124+
--pg-config ${lib.getDev postgresql}/bin/pg_config \
125+
${maybeDebugFlag} \
126+
--features "${builtins.concatStringsSep " " buildFeatures}" \
127+
--out-dir "$out"
128+
129+
${maybeLeaveBuildAndTestSubdir}
130+
131+
runHook postBuild
132+
'';
133+
134+
preCheck = preBuildAndTest + args.preCheck or "";
135+
136+
installPhase = ''
137+
runHook preInstall
138+
139+
echo "Executing buildPgrxExtension install"
140+
141+
${maybeEnterBuildAndTestSubdir}
142+
143+
cargo-pgrx pgrx stop all
144+
145+
mv $out/${postgresql}/* $out
146+
rm -rf $out/nix
147+
148+
${maybeLeaveBuildAndTestSubdir}
149+
150+
runHook postInstall
151+
'';
152+
153+
PGRX_PG_SYS_SKIP_BINDING_REWRITE = "1";
154+
CARGO_BUILD_INCREMENTAL = "false";
155+
RUST_BACKTRACE = "full";
156+
157+
checkNoDefaultFeatures = true;
158+
checkFeatures = (args.checkFeatures or [ ]) ++ (lib.optionals usePgTestCheckFeature [ "pg_test" ]) ++ [ "pg${pgrxPostgresMajor}" ];
159+
};
160+
in
161+
rustPlatform.buildRustPackage finalArgs

0 commit comments

Comments
 (0)