|
33 | 33 | pkg-config, |
34 | 34 | rustPlatform, |
35 | 35 | stdenv, |
36 | | - buildPackages, |
37 | 36 | writeShellScriptBin, |
38 | 37 | defaultBindgenHook, |
39 | 38 | }: |
|
45 | 44 | # Crane separates dependency builds from main crate builds, enabling better caching. |
46 | 45 | # Both approaches accept the same arguments and produce compatible outputs. |
47 | 46 | # |
| 47 | +# IMPORTANT: External Cargo.lock files are handled by extensions' postPatch phases, |
| 48 | +# not by copying during evaluation. This avoids IFD (Import From Derivation) issues |
| 49 | +# that caused cross-compilation failures when evaluating aarch64 packages on x86_64. |
| 50 | +# |
48 | 51 | # Additional arguments: |
49 | 52 | # - `postgresql` postgresql package of the version of postgresql this extension should be build for. |
50 | 53 | # Needs to be the build platform variant. |
@@ -144,37 +147,15 @@ let |
144 | 147 | pg_ctl stop |
145 | 148 | ''; |
146 | 149 |
|
147 | | - # Crane-specific: handle external Cargo.lock files |
148 | | - # Crane expects Cargo.lock at source root, but rustPlatform allows external lockFile paths. |
149 | | - # Without this, crane fails with: |
150 | | - # "error: unable to find Cargo.lock at /nix/store/...-source. please ensure one of the following: |
151 | | - # - a Cargo.lock exists at the root of the source directory" |
| 150 | + # Crane-specific: Determine if we're using crane and handle cargo lock info |
| 151 | + # Note: External lockfiles are handled by extensions' postPatch, not here, to avoid |
| 152 | + # creating platform-specific derivations during evaluation (prevents IFD issues) |
152 | 153 | useCrane = craneLib != null; |
153 | 154 | cargoLockInfo = args.cargoLock or null; |
154 | | - hasExternalLockFile = cargoLockInfo != null && cargoLockInfo ? lockFile; |
155 | | - |
156 | | - # Copy external Cargo.lock into source directory to satisfy crane's requirements |
157 | | - modifiedSrc = |
158 | | - if useCrane && hasExternalLockFile then |
159 | | - # Use buildPackages.stdenv to ensure this runs on the build platform |
160 | | - # This derivation just copies files and should be buildable during evaluation |
161 | | - buildPackages.stdenv.mkDerivation { |
162 | | - name = "${args.pname or "source"}-with-lockfile"; |
163 | | - src = args.src; |
164 | | - dontBuild = true; |
165 | | - # Ensure this derivation runs locally during evaluation |
166 | | - preferLocalBuild = true; |
167 | | - allowSubstitutes = false; |
168 | | - installPhase = '' |
169 | | - cp -r $src $out |
170 | | - chmod -R u+w $out |
171 | | - ${lib.optionalString (cargoLockInfo ? lockFile) '' |
172 | | - cp ${cargoLockInfo.lockFile} $out/Cargo.lock |
173 | | - ''} |
174 | | - ''; |
175 | | - } |
176 | | - else |
177 | | - args.src; |
| 155 | + |
| 156 | + # External Cargo.lock files are handled by the extension's postPatch phase |
| 157 | + # which creates symlinks. Crane finds them during build, not evaluation. |
| 158 | + # This approach prevents IFD cross-compilation issues. |
178 | 159 |
|
179 | 160 | # Use rustPlatform.importCargoLock instead of crane's vendorCargoDeps for git dependencies. |
180 | 161 | # crane's vendorCargoDeps uses builtins.fetchGit which only searches the default branch, |
|
183 | 164 | # 'refs/heads/main' of repository 'https://github.com/burmecia/iceberg-rust'!" |
184 | 165 | # rustPlatform.importCargoLock with allowBuiltinFetchGit searches all refs (branches/tags). |
185 | 166 | cargoVendorDir = |
186 | | - if useCrane && hasExternalLockFile && cargoLockInfo ? outputHashes then |
| 167 | + if useCrane && cargoLockInfo != null && cargoLockInfo ? outputHashes then |
187 | 168 | rustPlatform.importCargoLock { |
188 | 169 | lockFile = cargoLockInfo.lockFile; |
189 | 170 | outputHashes = cargoLockInfo.outputHashes; |
|
212 | 193 | commonArgs = |
213 | 194 | argsForBuilder |
214 | 195 | // { |
215 | | - src = modifiedSrc; |
| 196 | + src = args.src; # Use original source - extensions handle external lockfiles via postPatch |
216 | 197 | strictDeps = true; |
217 | 198 |
|
218 | 199 | buildInputs = (args.buildInputs or [ ]); |
|
0 commit comments