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