Skip to content

Commit ca696b0

Browse files
committed
fix: centralize bindgen hook override for pgrx extensions
Move the bindgen hook fix for ARM NEON vector ABI issues from pg_graphql to mkPgrxExtension, making it available to all pgrx-based extensions. This fix applies to pgrx versions 0.6.1 through 0.11.2 when building on aarch64-linux.
1 parent ed00571 commit ca696b0

File tree

3 files changed

+23
-27
lines changed

3 files changed

+23
-27
lines changed

nix/cargo-pgrx/buildPgrxExtension.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
stdenv,
3535
darwin,
3636
writeShellScriptBin,
37+
defaultBindgenHook,
3738
}:
3839

3940
# The idea behind: Use it mostly like rustPlatform.buildRustPackage and so
@@ -56,7 +57,7 @@
5657
# enable override to generate bindings using bindgenHook.
5758
# Some older versions of cargo-pgrx use a bindgenHook that is not compatible with the
5859
# current clang version present in stdenv
59-
bindgenHook ? rustPlatform.bindgenHook,
60+
bindgenHook ? defaultBindgenHook,
6061
# cargo-pgrx calls rustfmt on generated bindings, this is not strictly necessary, so we avoid the
6162
# dependency here. Set to false and provide rustfmt in nativeBuildInputs, if you need it, e.g.
6263
# if you include the generated code in the output via postInstall.

nix/cargo-pgrx/mkPgrxExtension.nix

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
pgrxVersion,
55
makeRustPlatform,
66
rust-bin,
7+
system,
78
}:
89
let
910
inherit ((callPackage ./default.nix { inherit rustVersion; })) mkCargoPgrx;
@@ -31,8 +32,28 @@ let
3132
inherit (mapping) hash cargoHash;
3233
version = pgrxVersion;
3334
};
35+
36+
bindgenHook =
37+
# Fix bindgen error on aarch64-linux for versions using pgrx with bindgen 0.68.1
38+
# This affects pgrx 0.6.1 through 0.11.2 which have issues with ARM NEON vector ABI
39+
if (builtins.compareVersions "0.11.3" pgrxVersion > 0) then
40+
let
41+
nixos2211 = (
42+
import (builtins.fetchTarball {
43+
url = "https://channels.nixos.org/nixos-22.11/nixexprs.tar.xz";
44+
sha256 = "1j7h75a9hwkkm97jicky5rhvzkdwxsv5v46473rl6agvq2sj97y1";
45+
}) { inherit system; }
46+
);
47+
in
48+
rustPlatform.bindgenHook.overrideAttrs {
49+
libclang = nixos2211.clang.cc.lib;
50+
clang = nixos2211.clang;
51+
}
52+
else
53+
rustPlatform.bindgenHook;
3454
in
3555
callPackage ./buildPgrxExtension.nix {
3656
inherit rustPlatform;
3757
inherit cargo-pgrx;
58+
defaultBindgenHook = bindgenHook;
3859
}

nix/ext/pg_graphql/default.nix

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
postgresql,
88
rust-bin,
99
rsync,
10-
system,
11-
rustPlatform,
1210
}:
1311

1412
let
@@ -104,30 +102,6 @@ let
104102
inherit (postgresql.meta) platforms;
105103
};
106104
}
107-
//
108-
lib.optionalAttrs
109-
(
110-
# Fix bindgen error on aarch64-linux for versions using pgrx with bindgen 0.68.1
111-
# This affects pgrx 0.6.1 through 0.11.2 which have issues with ARM NEON vector ABI
112-
# We apply the fix to all versions up to 1.5.1 (last version before 1.5.4 which uses 0.11.2)
113-
builtins.compareVersions "1.5.4" version > 0
114-
)
115-
{
116-
# Fix bindgen error on aarch64-linux by using an older version of clang
117-
bindgenHook =
118-
let
119-
nixos2211 = (
120-
import (builtins.fetchTarball {
121-
url = "https://channels.nixos.org/nixos-22.11/nixexprs.tar.xz";
122-
sha256 = "1j7h75a9hwkkm97jicky5rhvzkdwxsv5v46473rl6agvq2sj97y1";
123-
}) { inherit system; }
124-
);
125-
in
126-
rustPlatform.bindgenHook.overrideAttrs {
127-
libclang = nixos2211.clang.cc.lib;
128-
clang = nixos2211.clang;
129-
};
130-
}
131105
// lib.optionalAttrs (builtins.compareVersions "1.2.0" version >= 0) {
132106
# Add missing Cargo.lock
133107
patches = [ ./0001-Add-missing-Cargo.lock-${version}.patch ];

0 commit comments

Comments
 (0)