8
8
, runCommand
9
9
, coreutils
10
10
, gnugrep
11
- , gcc
11
+ , clang
12
+ , patchelf
13
+ , xcbuild
14
+ , darwin
12
15
} :
13
16
14
17
stdenv . mkDerivation ( finalAttrs : {
15
18
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
19
19
version = "3.1.5" ;
20
20
21
21
src = fetchFromGitHub {
@@ -26,58 +26,105 @@ stdenv.mkDerivation (finalAttrs: {
26
26
} ;
27
27
28
28
patches = [
29
- # Allow building with system v8.
30
- # https://github.com/plv8/plv8/pull/505 (rejected)
31
29
./0001-build-Allow-using-V8-from-system.patch
32
30
] ;
33
31
34
32
nativeBuildInputs = [
35
33
perl
36
34
] ++ lib . optionals stdenv . isDarwin [
37
- gcc
35
+ clang
36
+ xcbuild
38
37
] ;
39
38
40
39
buildInputs = [
41
- v8
40
+ ( v8 . overrideAttrs ( oldAttrs : {
41
+ version = "9.7.106.18" ;
42
+ } ) )
42
43
postgresql
44
+ ] ++ lib . optionals stdenv . isDarwin [
45
+ darwin . apple_sdk . frameworks . CoreFoundation
46
+ darwin . apple_sdk . frameworks . Kerberos
43
47
] ;
44
48
45
49
buildFlags = [ "all" ] ;
46
50
47
51
makeFlags = [
48
- # Nixpkgs build a v8 monolith instead of separate v8_libplatform.
49
52
"USE_SYSTEM_V8=1"
50
- "SHLIB_LINK=-lv8"
51
53
"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"
52
61
] ;
53
- NIX_LDFLAGS = lib . optionalString ( stdenv . isDarwin && stdenv . isAarch64 )
54
- "-undefined dynamic_lookup" ;
55
62
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 = [
57
86
"-I${ v8 } /include"
58
87
"-I${ postgresql } /include"
88
+ "-I${ postgresql } /include/server"
89
+ "-I${ postgresql } /include/internal"
59
90
] ;
91
+
60
92
installFlags = [
61
- # PGXS only supports installing to postgresql prefix so we need to redirect this
62
93
"DESTDIR=${ placeholder "out" } "
63
94
] ;
64
95
65
- # No configure script.
66
96
dontConfigure = true ;
67
97
68
98
postPatch = ''
69
99
patchShebangs ./generate_upgrade.sh
70
- # https://github.com/plv8/plv8/pull/506
71
100
substituteInPlace generate_upgrade.sh \
72
101
--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++
73
112
'' ;
74
113
75
114
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.
79
115
mv "$out/nix/store"/*/* "$out"
80
116
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
+ '' }
81
128
'' ;
82
129
83
130
passthru = {
0 commit comments