2727# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2828# SOFTWARE.
2929
30- { lib
31- , cargo-pgrx
32- , pkg-config
33- , rustPlatform
34- , stdenv
35- , Security
36- , writeShellScriptBin
30+ {
31+ lib ,
32+ cargo-pgrx ,
33+ pkg-config ,
34+ rustPlatform ,
35+ stdenv ,
36+ darwin ,
37+ writeShellScriptBin ,
3738} :
3839
3940# The idea behind: Use it mostly like rustPlatform.buildRustPackage and so
4748# unnecessary and heavy dependency. If you set this to true, you also
4849# have to add `rustfmt` to `nativeBuildInputs`.
4950
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 :
51+ {
52+ buildAndTestSubdir ? null ,
53+ buildType ? "release" ,
54+ buildFeatures ? [ ] ,
55+ cargoBuildFlags ? [ ] ,
56+ postgresql ,
57+ # cargo-pgrx calls rustfmt on generated bindings, this is not strictly necessary, so we avoid the
58+ # dependency here. Set to false and provide rustfmt in nativeBuildInputs, if you need it, e.g.
59+ # if you include the generated code in the output via postInstall.
60+ useFakeRustfmt ? true ,
61+ usePgTestCheckFeature ? true ,
62+ ...
63+ } @args :
6264let
63- rustfmtInNativeBuildInputs = lib . lists . any ( dep : lib . getName dep == "rustfmt" ) ( args . nativeBuildInputs or [ ] ) ;
65+ rustfmtInNativeBuildInputs = lib . lists . any ( dep : lib . getName dep == "rustfmt" ) (
66+ args . nativeBuildInputs or [ ]
67+ ) ;
6468in
6569
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 (
71+ ( args . installPhase or "" ) == ""
72+ ) "buildPgrxExtensions overwrites the installPhase, so providing one does nothing" ;
73+ assert lib . asserts . assertMsg (
74+ ( args . buildPhase or "" ) == ""
75+ ) "buildPgrxExtensions overwrites the buildPhase, so providing one does nothing" ;
7076assert lib . asserts . assertMsg ( useFakeRustfmt -> ! rustfmtInNativeBuildInputs )
7177 "The parameter useFakeRustfmt is set to true, but rustfmt is included in nativeBuildInputs. Either set useFakeRustfmt to false or remove rustfmt from nativeBuildInputs." ;
7278assert lib . asserts . assertMsg ( ! useFakeRustfmt -> rustfmtInNativeBuildInputs )
@@ -75,7 +81,7 @@ assert lib.asserts.assertMsg (!useFakeRustfmt -> rustfmtInNativeBuildInputs)
7581let
7682 fakeRustfmt = writeShellScriptBin "rustfmt" ''
7783 exit 0
78- '' ;
84+ '' ;
7985 maybeDebugFlag = lib . optionalString ( buildType != "release" ) "--debug" ;
8086 maybeEnterBuildAndTestSubdir = lib . optionalString ( buildAndTestSubdir != null ) ''
8187 export CARGO_TARGET_DIR="$(pwd)/target"
97103 pg_ctl stop
98104 '' ;
99105
100- argsForBuildRustPackage = builtins . removeAttrs args [ "postgresql" "useFakeRustfmt" "usePgTestCheckFeature" ] ;
106+ argsForBuildRustPackage = builtins . removeAttrs args [
107+ "postgresql"
108+ "useFakeRustfmt"
109+ "usePgTestCheckFeature"
110+ ] ;
101111
102112 # so we don't accidentally `(rustPlatform.buildRustPackage argsForBuildRustPackage) // { ... }` because
103113 # we forgot parentheses
104114 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 ] ;
115+ buildInputs =
116+ ( args . buildInputs or [ ] )
117+ ++ lib . optionals stdenv . hostPlatform . isDarwin [ darwin . apple_sdk . frameworks . Security ] ;
118+
119+ nativeBuildInputs =
120+ ( args . nativeBuildInputs or [ ] )
121+ ++ [
122+ cargo-pgrx
123+ postgresql
124+ pkg-config
125+ rustPlatform . bindgenHook
126+ ]
127+ ++ lib . optionals useFakeRustfmt [ fakeRustfmt ] ;
113128
114129 buildPhase = ''
115130 runHook preBuild
143158 cargo-pgrx pgrx stop all
144159
145160 mv $out/${ postgresql } /* $out
161+ mv $out/${ postgresql . lib } /* $out
146162 rm -rf $out/nix
147163
148164 ${ maybeLeaveBuildAndTestSubdir }
155171 RUST_BACKTRACE = "full" ;
156172
157173 checkNoDefaultFeatures = true ;
158- checkFeatures = ( args . checkFeatures or [ ] ) ++ ( lib . optionals usePgTestCheckFeature [ "pg_test" ] ) ++ [ "pg${ pgrxPostgresMajor } " ] ;
174+ checkFeatures =
175+ ( args . checkFeatures or [ ] )
176+ ++ ( lib . optionals usePgTestCheckFeature [ "pg_test" ] )
177+ ++ [ "pg${ pgrxPostgresMajor } " ] ;
159178 } ;
160179in
161180rustPlatform . buildRustPackage finalArgs
0 commit comments