Skip to content

Commit 7e3bdbf

Browse files
committed
fix: resolve crane IFD cross-compilation issues
The issue was that crane's modifiedSrc derivation (which copies external Cargo.lock files) was being created with the target platform's stdenv, causing system conflicts during cross-compilation evaluation. Fixed by: - Using buildPackages.stdenv for the modifiedSrc derivation so it runs on the build platform during evaluation - Adding preferLocalBuild and allowSubstitutes flags to ensure proper IFD handling - Re-enabling crane for pg_jsonschema to test the fix This resolves the 'required system not available' errors while maintaining crane's incremental build benefits for native builds.
1 parent 4fd5981 commit 7e3bdbf

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

nix/cargo-pgrx/buildPgrxExtension.nix

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
pkg-config,
3434
rustPlatform,
3535
stdenv,
36+
buildPackages,
3637
writeShellScriptBin,
3738
defaultBindgenHook,
3839
}:
@@ -155,10 +156,15 @@ let
155156
# Copy external Cargo.lock into source directory to satisfy crane's requirements
156157
modifiedSrc =
157158
if useCrane && hasExternalLockFile then
158-
stdenv.mkDerivation {
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 {
159162
name = "${args.pname or "source"}-with-lockfile";
160163
src = args.src;
161164
dontBuild = true;
165+
# Ensure this derivation runs locally during evaluation
166+
preferLocalBuild = true;
167+
allowSubstitutes = false;
162168
installPhase = ''
163169
cp -r $src $out
164170
chmod -R u+w $out

nix/cargo-pgrx/mkPgrxExtension.nix

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,8 @@ let
5959
# Initialize crane with the same Rust toolchain as rustPlatform to ensure consistency.
6060
# crane.mkLib creates a library of crane functions bound to a specific package set,
6161
# then we override the toolchain to match the pgrx-required Rust version.
62-
# Disable crane for cross-compilation to avoid system conflicts
6362
craneLib =
64-
if useCrane && (stdenv.buildPlatform.system == stdenv.hostPlatform.system) then
63+
if useCrane then
6564
assert crane != null;
6665
(crane.mkLib pkgs).overrideToolchain rust-bin.stable.${rustVersion}.default
6766
else

nix/ext/pg_jsonschema/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ let
1515
cargo = rust-bin.stable.${rustVersion}.default;
1616
mkPgrxExtension = callPackages ../../cargo-pgrx/mkPgrxExtension.nix {
1717
inherit rustVersion pgrxVersion;
18-
useCrane = false;
18+
useCrane = true;
1919
};
2020
src = fetchFromGitHub {
2121
owner = "supabase";

0 commit comments

Comments
 (0)