|
28 | 28 | # SOFTWARE. |
29 | 29 | { |
30 | 30 | lib, |
31 | | - bash, |
32 | 31 | cargo-pgrx, |
33 | 32 | pkg-config, |
34 | 33 | rustPlatform, |
|
86 | 85 | fakeRustfmt = writeShellScriptBin "rustfmt" '' |
87 | 86 | exit 0 |
88 | 87 | ''; |
| 88 | + |
| 89 | + # Rustc wrapper for pgrx < 0.12.0 to filter out empty postmaster_stub.rs arguments |
| 90 | + # This fixes an issue that causes build failures. |
| 91 | + # Fixed upstream in pgcentralfoundation/pgrx#1435 and #1441, available from pgrx >= 0.12. |
| 92 | + rustcWrapper = writeShellScriptBin "rustc" '' |
| 93 | + original_rustc=$(command -v ${stdenv.cc.targetPrefix}rustc || command -v rustc) |
| 94 | + filtered_args=() |
| 95 | + for arg in "$@"; do |
| 96 | + if [[ -z "$arg" ]]; then |
| 97 | + continue |
| 98 | + fi |
| 99 | + if [[ "$arg" =~ postmaster_stub\.rs$ ]]; then |
| 100 | + if [[ ! -s "$arg" ]]; then |
| 101 | + continue |
| 102 | + fi |
| 103 | + fi |
| 104 | + filtered_args+=("$arg") |
| 105 | + done |
| 106 | + exec "$original_rustc" "''${filtered_args[@]}" |
| 107 | + ''; |
89 | 108 | maybeDebugFlag = lib.optionalString (buildType != "release") "--debug"; |
90 | 109 | maybeEnterBuildAndTestSubdir = lib.optionalString (buildAndTestSubdir != null) '' |
91 | 110 | export CARGO_TARGET_DIR="$(pwd)/target" |
|
94 | 113 | maybeLeaveBuildAndTestSubdir = lib.optionalString (buildAndTestSubdir != null) "popd"; |
95 | 114 | pgrxBinaryName = if builtins.compareVersions "0.7.4" cargo-pgrx.version >= 0 then "pgx" else "pgrx"; |
96 | 115 |
|
| 116 | + # The rustc wrapper is only needed for pgrx < 0.12.0 |
| 117 | + # fixed upstream in pgcentralfoundation/pgrx#1435 and #1441 |
| 118 | + needsRustcWrapper = builtins.compareVersions cargo-pgrx.version "0.12.0" < 0; |
| 119 | + |
97 | 120 | pgrxPostgresMajor = lib.versions.major postgresql.version; |
98 | 121 | preBuildAndTest = '' |
99 | 122 | export PGRX_HOME=$(mktemp -d) |
@@ -137,48 +160,30 @@ let |
137 | 160 | ++ lib.optionals useFakeRustfmt [ fakeRustfmt ]; |
138 | 161 |
|
139 | 162 | buildPhase = '' |
140 | | - runHook preBuild |
141 | | -
|
142 | | - echo "Executing cargo-pgrx buildPhase" |
143 | | - ${preBuildAndTest} |
144 | | - ${maybeEnterBuildAndTestSubdir} |
145 | | -
|
146 | | - export PGRX_BUILD_FLAGS="--frozen -j $NIX_BUILD_CORES ${builtins.concatStringsSep " " cargoBuildFlags}" |
147 | | - export PGX_BUILD_FLAGS="$PGRX_BUILD_FLAGS" |
148 | | -
|
149 | | - # Wrap rustc to filter out empty postmaster_stub.rs arguments |
150 | | - original_rustc=$(command -v rustc) |
151 | | - mkdir -p $out/bin |
152 | | - cat > $out/bin/rustc << EOF |
153 | | - #!${bash}/bin/bash |
154 | | - filtered_args=() |
155 | | - for arg in "\$@"; do |
156 | | - if [[ -z "\$arg" ]]; then |
157 | | - continue |
158 | | - fi |
159 | | - if [[ "\$arg" =~ postmaster_stub\.rs$ ]]; then |
160 | | - if [[ ! -s "\$arg" ]]; then |
161 | | - continue |
162 | | - fi |
163 | | - fi |
164 | | - filtered_args+=("\$arg") |
165 | | - done |
166 | | - exec "$original_rustc" "\''${filtered_args[@]}" |
167 | | - EOF |
168 | | - chmod +x $out/bin/rustc |
169 | | - export PATH="$out/bin:$PATH" |
170 | | - export RUSTC="$out/bin/rustc" |
171 | | -
|
172 | | - ${lib.optionalString stdenv.hostPlatform.isDarwin ''RUSTFLAGS="''${RUSTFLAGS:+''${RUSTFLAGS} }-Clink-args=-Wl,-undefined,dynamic_lookup"''} \ |
173 | | - cargo ${pgrxBinaryName} package \ |
174 | | - --pg-config ${lib.getDev postgresql}/bin/pg_config \ |
175 | | - ${maybeDebugFlag} \ |
176 | | - --features "${builtins.concatStringsSep " " buildFeatures}" \ |
177 | | - --out-dir "$out" |
178 | | -
|
179 | | - ${maybeLeaveBuildAndTestSubdir} |
180 | | -
|
181 | | - runHook postBuild |
| 163 | + runHook preBuild |
| 164 | +
|
| 165 | + echo "Executing cargo-pgrx buildPhase" |
| 166 | + ${preBuildAndTest} |
| 167 | + ${maybeEnterBuildAndTestSubdir} |
| 168 | +
|
| 169 | + export PGRX_BUILD_FLAGS="--frozen -j $NIX_BUILD_CORES ${builtins.concatStringsSep " " cargoBuildFlags}" |
| 170 | + export PGX_BUILD_FLAGS="$PGRX_BUILD_FLAGS" |
| 171 | +
|
| 172 | + ${lib.optionalString needsRustcWrapper '' |
| 173 | + export PATH="${rustcWrapper}/bin:$PATH" |
| 174 | + export RUSTC="${rustcWrapper}/bin/rustc" |
| 175 | + ''} |
| 176 | +
|
| 177 | + ${lib.optionalString stdenv.hostPlatform.isDarwin ''RUSTFLAGS="''${RUSTFLAGS:+''${RUSTFLAGS} }-Clink-args=-Wl,-undefined,dynamic_lookup"''} \ |
| 178 | + cargo ${pgrxBinaryName} package \ |
| 179 | + --pg-config ${lib.getDev postgresql}/bin/pg_config \ |
| 180 | + ${maybeDebugFlag} \ |
| 181 | + --features "${builtins.concatStringsSep " " buildFeatures}" \ |
| 182 | + --out-dir "$out" |
| 183 | +
|
| 184 | + ${maybeLeaveBuildAndTestSubdir} |
| 185 | +
|
| 186 | + runHook postBuild |
182 | 187 | ''; |
183 | 188 |
|
184 | 189 | preCheck = preBuildAndTest + args.preCheck or ""; |
|
0 commit comments