10000 Sam/plv8 darwin (#1117) · hscmgroup/postgres@86687f8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 86687f8

Browse files
authored
Sam/plv8 darwin (supabase#1117)
* feat: wip fixing plv8 on darwin aarch64 * fix: build plv8 and success in enabling on darwin * fix: now builds correct and enable on aarch64-linux * fix: pg_regression updated to include plv8 extensions again * fix: print logs to stdout/stderr instead of logfile --------- Co-authored-by: Sam Rose <samuel@supabase.io>
1 parent b661336 commit 86687f8

File tree

4 files changed

+95
-32
lines changed

4 files changed

+95
-32
lines changed

flake.nix

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,12 @@
417417
fi
418418
done
419419
createdb -p 5432 -h localhost testing
420-
psql -p 5432 -h localhost -d testing -Xaf ${./nix/tests/prime.sql}
421-
420+
if ! psql -p 5432 -h localhost -d testing -v ON_ERROR_STOP=1 -Xaf ${./nix/tests/prime.sql}; then
421+
echo "Error executing SQL file. PostgreSQL log content:"
422+
cat $TMPDIR/logfile/postgresql.log
423+
pg_ctl -D "$PGDATA" stop
424+
exit 1
425+
fi
422426
pg_prove -p 5432 -h localhost -d testing ${sqlTests}/*.sql
423427
424428
mkdir -p $out/regression_output

nix/ext/plv8.nix

Lines changed: 66 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
, runCommand
99
, coreutils
1010
, gnugrep
11-
, gcc
11+
, clang
12+
, patchelf
13+
, xcbuild
14+
, darwin
1215
}:
1316

1417
stdenv.mkDerivation (finalAttrs: {
1518
pname = "plv8";
16-
# plv8 latest is https://github.com/plv8/plv8/releases/tag/v3.2.2
17-
# FIXME we need to increment this build toward 3.2.2
18-
# 3.1.7 is the highest version that can be built with pg 16
1919
version = "3.1.5";
2020

2121
src = fetchFromGitHub {
@@ -26,58 +26,105 @@ stdenv.mkDerivation (finalAttrs: {
2626
};
2727

2828
patches = [
29-
# Allow building with system v8.
30-
# https://github.com/plv8/plv8/pull/505 (rejected)
3129
./0001-build-Allow-using-V8-from-system.patch
3230
];
3331

3432
nativeBuildInputs = [
3533
perl
3634
] ++ lib.optionals stdenv.isDarwin [
37-
gcc
35+
clang
36+
xcbuild
3837
];
3938

4039
buildInputs = [
41-
v8
40+
(v8.overrideAttrs (oldAttrs: {
41+
version = "9.7.106.18";
42+
}))
4243
postgresql
44+
] ++ lib.optionals stdenv.isDarwin [
45+
darwin.apple_sdk.frameworks.CoreFoundation
46+
darwin.apple_sdk.frameworks.Kerberos
4347
];
4448

4549
buildFlags = [ "all" ];
4650

4751
makeFlags = [
48-
# Nixpkgs build a v8 monolith instead of separate v8_libplatform.
4952
"USE_SYSTEM_V8=1"
50-
"SHLIB_LINK=-lv8"
5153
"V8_OUTDIR=${v8}/lib"
54+
"PG_CONFIG=${postgresql}/bin/pg_config"
55+
] ++ lib.optionals stdenv.isDarwin [
56+
"CC=${clang}/bin/clang"
57+
"CXX=${clang}/bin/clang++"
58+
"SHLIB_LINK=-L${v8}/lib -lv8_monolith -Wl,-rpath,${v8}/lib"
59+
] ++ lib.optionals (!stdenv.isDarwin) [
60+
"SHLIB_LINK=-L${v8}/lib -lv8_monolith -Wl,-rpath,${v8}/lib"
5261
];
53-
NIX_LDFLAGS = lib.optionalString (stdenv.isDarwin && stdenv.isAarch64)
54-
"-undefined dynamic_lookup";
5562

56-
NIX_CFLAGS_COMPILE = lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [
63+
NIX_LDFLAGS = (lib.optionals stdenv.isDarwin [
64+
"-L${postgresql}/lib"
65+
"-L${v8}/lib"
66+
"-lv8_monolith"
67+
"-lpq"
68+
"-lpgcommon"
69+
"-lpgport"
70+
"-F${darwin.apple_sdk.frameworks.CoreFoundation}/Library/Frameworks"
71+
"-framework" "CoreFoundation"
72+
"-F${darwin.apple_sdk.frameworks.Kerberos}/Library/Frameworks"
73+
"-framework" "Kerberos"
74+
"-undefined" "dynamic_lookup"
75+
"-flat_namespace"
76+
]) ++ (lib.optionals (!stdenv.isDarwin) [
77+
"-L${postgresql}/lib"
78+
"-L${v8}/lib"
79+
"-lv8_monolith"
80+
"-lpq"
81+
"-lpgcommon"
82+
"-lpgport"
83+
]);
84+
85+
NIX_CFLAGS_COMPILE = [
5786
"-I${v8}/include"
5887
"-I${postgresql}/include"
88+
"-I${postgresql}/include/server"
89+
"-I${postgresql}/include/internal"
5990
];
91+
6092
installFlags = [
61-
# PGXS only supports installing to postgresql prefix so we need to redirect this
6293
"DESTDIR=${placeholder "out"}"
6394
];
6495

65-
# No configure script.
6696
dontConfigure = true;
6797

6898
postPatch = ''
6999
patchShebangs ./generate_upgrade.sh
70-
# https://github.com/plv8/plv8/pull/506
71100
substituteInPlace generate_upgrade.sh \
72101
--replace " 2.3.10 " " 2.3.10 2.3.11 2.3.12 2.3.13 2.3.14 2.3.15 "
102+
103+
${lib.optionalString stdenv.isDarwin ''
104+
# Replace g++ with clang++ in Makefile
105+
sed -i 's/g++/clang++/g' Makefile
106+
''}
107+
'';
108+
109+
preBuild = lib.optionalString stdenv.isDarwin ''
110+
export CC=${clang}/bin/clang
111+
export CXX=${clang}/bin/clang++
73112
'';
74113

75114
postInstall = ''
76-
# Move the redirected to proper directory.
77-
# There appear to be no references to the install directories
78-
# so changing them does not cause issues.
79115
mv "$out/nix/store"/*/* "$out"
80116
rmdir "$out/nix/store"/* "$out/nix/store" "$out/nix"
117+
118+
${lib.optionalString stdenv.isDarwin ''
119+
install_name_tool -add_rpath "${v8}/lib" $out/lib/plv8-${finalAttrs.version}.so
120+
install_name_tool -add_rpath "${postgresql}/lib" $out/lib/plv8-${finalAttrs.version}.so
121+
install_name_tool -add_rpath "${stdenv.cc.cc.lib}/lib" $out/lib/plv8-${finalAttrs.version}.so
122+
install_name_tool -change @rpath/libv8_monolith.dylib ${v8}/lib/libv8_monolith.dylib $out/lib/plv8-${finalAttrs.version}.so
123+
''}
124+
125+
${lib.optionalString (!stdenv.isDarwin) ''
126+
${patchelf}/bin/patchelf --set-rpath "${v8}/lib:${postgresql}/lib:${stdenv.cc.cc.lib}/lib" $out/lib/plv8-${finalAttrs.version}.so
127+
''}
81128
'';
82129

83130
passthru = {

0 commit comments

Comments
 (0)
0