27
27
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
28
# SOFTWARE.
29
29
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 ,
37
38
} :
38
39
39
40
# The idea behind: Use it mostly like rustPlatform.buildRustPackage and so
47
48
# unnecessary and heavy dependency. If you set this to true, you also
48
49
# have to add `rustfmt` to `nativeBuildInputs`.
49
50
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 :
62
64
let
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
+ ) ;
64
68
in
65
69
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" ;
70
76
assert lib . asserts . assertMsg ( useFakeRustfmt -> ! rustfmtInNativeBuildInputs )
71
77
"The parameter useFakeRustfmt is set to true, but rustfmt is included in nativeBuildInputs. Either set useFakeRustfmt to false or remove rustfmt from nativeBuildInputs." ;
72
78
assert lib . asserts . assertMsg ( ! useFakeRustfmt -> rustfmtInNativeBuildInputs )
@@ -75,7 +81,7 @@ assert lib.asserts.assertMsg (!useFakeRustfmt -> rustfmtInNativeBuildInputs)
75
81
let
76
82
fakeRustfmt = writeShellScriptBin "rustfmt" ''
77
83
exit 0
78
- '' ;
84
+ '' ;
79
85
maybeDebugFlag = lib . optionalString ( buildType != "release" ) "--debug" ;
80
86
maybeEnterBuildAndTestSubdir = lib . optionalString ( buildAndTestSubdir != null ) ''
81
87
export CARGO_TARGET_DIR="$(pwd)/target"
97
103
pg_ctl stop
98
104
'' ;
99
105
100
- argsForBuildRustPackage = builtins . removeAttrs args [ "postgresql" "useFakeRustfmt" "usePgTestCheckFeature" ] ;
106
+ argsForBuildRustPackage = builtins . removeAttrs args [
107
+ "postgresql"
108
+ "useFakeRustfmt"
109
+ "usePgTestCheckFeature"
110
+ ] ;
101
111
102
112
# so we don't accidentally `(rustPlatform.buildRustPackage argsForBuildRustPackage) // { ... }` because
103
113
# we forgot parentheses
104
114
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 ] ;
113
128
114
129
buildPhase = ''
115
130
runHook preBuild
143
158
cargo-pgrx pgrx stop all
144
159
145
160
mv $out/${ postgresql } /* $out
161
+ mv $out/${ postgresql . lib } /* $out
146
162
rm -rf $out/nix
147
163
148
164
${ maybeLeaveBuildAndTestSubdir }
155
171
RUST_BACKTRACE = "full" ;
156
172
157
173
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 } " ] ;
159
178
} ;
160
179
in
161
180
rustPlatform . buildRustPackage finalArgs
0 commit comments