Skip to content

Commit 25428b6

Browse files
committed
fix: build plv8 and success in enabling on darwin
1 parent 92e190e commit 25428b6

File tree

2 files changed

+46
-21
lines changed

2 files changed

+46
-21
lines changed

nix/ext/plv8.nix

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
13
{ stdenv
24
, lib
35
, fetchFromGitHub
@@ -8,16 +10,14 @@
810
, runCommand
911
, coreutils
1012
, gnugrep
11-
, gcc
13+
, clang
1214
, patchelf
1315
, xcbuild
16+
, darwin
1417
}:
1518

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

2323
src = fetchFromGitHub {
@@ -28,15 +28,13 @@ stdenv.mkDerivation (finalAttrs: {
2828
};
2929

3030
patches = [
31-
# Allow building with system v8.
32-
# https://github.com/plv8/plv8/pull/505 (rejected)
3331
./0001-build-Allow-using-V8-from-system.patch
3432
];
3533

3634
nativeBuildInputs = [
3735
perl
3836
] ++ lib.optionals stdenv.isDarwin [
39-
gcc
37+
clang
4038
xcbuild
4139
];
4240

@@ -45,49 +43,76 @@ stdenv.mkDerivation (finalAttrs: {
4543
version = "9.7.106.18";
4644
}))
4745
postgresql
46+
] ++ lib.optionals stdenv.isDarwin [
47+
darwin.apple_sdk.frameworks.CoreFoundation
48+
darwin.apple_sdk.frameworks.Kerberos
4849
];
4950

5051
buildFlags = [ "all" ];
5152

5253
makeFlags = [
53-
# Nixpkgs build a v8 monolith instead of separate v8_libplatform.
5454
"USE_SYSTEM_V8=1"
55-
"SHLIB_LINK=-L${v8}/lib -lv8_monolith -Wl,--no-as-needed"
5655
"V8_OUTDIR=${v8}/lib"
56+
"PG_CONFIG=${postgresql}/bin/pg_config"
57+
] ++ lib.optionals stdenv.isDarwin [
58+
"CC=${clang}/bin/clang"
59+
"CXX=${clang}/bin/clang++"
60+
"SHLIB_LINK=-L${v8}/lib -lv8_monolith -Wl,-rpath,${v8}/lib"
5761
];
58-
NIX_LDFLAGS = lib.optionalString (stdenv.isDarwin && stdenv.isAarch64)
59-
"-undefined dynamic_lookup";
6062

61-
NIX_CFLAGS_COMPILE = lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [
63+
NIX_LDFLAGS = lib.optionals stdenv.isDarwin (lib.concatStringsSep " " [
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+
]);
77+
78+
NIX_CFLAGS_COMPILE = lib.optionals stdenv.isDarwin [
6279
"-I${v8}/include"
6380
"-I${postgresql}/include"
81+
"-I${postgresql}/include/server"
82+
"-I${postgresql}/include/internal"
6483
];
84+
6585
installFlags = [
66-
# PGXS only supports installing to postgresql prefix so we need to redirect this
6786
"DESTDIR=${placeholder "out"}"
6887
];
6988

70-
# No configure script.
7189
dontConfigure = true;
7290

7391
postPatch = ''
7492
patchShebangs ./generate_upgrade.sh
75-
# https://github.com/plv8/plv8/pull/506
7693
substituteInPlace generate_upgrade.sh \
7794
--replace " 2.3.10 " " 2.3.10 2.3.11 2.3.12 2.3.13 2.3.14 2.3.15 "
95+
96+
${lib.optionalString stdenv.isDarwin ''
97+
# Replace g++ with clang++ in Makefile
98+
sed -i 's/g++/clang++/g' Makefile
99+
''}
100+
'';
101+
102+
preBuild = lib.optionalString stdenv.isDarwin ''
103+
export CC=${clang}/bin/clang
104+
export CXX=${clang}/bin/clang++
78105
'';
79106

80107
postInstall = ''
81-
# Move the redirected to proper directory.
82-
# There appear to be no references to the install directories
83-
# so changing them does not cause issues.
84108
mv "$out/nix/store"/*/* "$out"
85109
rmdir "$out/nix/store"/* "$out/nix/store" "$out/nix"
86110
87-
# Use install_name_tool for macOS
88111
${lib.optionalString stdenv.isDarwin ''
89112
install_name_tool -add_rpath "${v8}/lib" $out/lib/plv8-${finalAttrs.version}.so
113+
install_name_tool -add_rpath "${postgresql}/lib" $out/lib/plv8-${finalAttrs.version}.so
90114
install_name_tool -add_rpath "${stdenv.cc.cc.lib}/lib" $out/lib/plv8-${finalAttrs.version}.so
115+
install_name_tool -change @rpath/libv8_monolith.dylib ${v8}/lib/libv8_monolith.dylib $out/lib/plv8-${finalAttrs.version}.so
91116
''}
92117
'';
93118

nix/tests/prime.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ ERROR: could not load library "/nix/store/..../lib/plv8-3.1.5.so
6868
symbol not found in flat namespace
6969
*/
7070
create extension plv8;
71-
-- create extension plcoffee;
72-
-- create extension plls;
71+
create extension plcoffee;
72+
create extension plls;
7373

7474
create extension postgis;
7575
create extension postgis_raster;

0 commit comments

Comments
 (0)