4
4
, v8
5
5
, perl
6
6
, postgresql
7
- # For test
7
+ # For passthru test on various systems, and local development on macos
8
+ # not we are not currently using passthru tests but retaining for possible contrib
9
+ # to nixpkgs
8
10
, runCommand
9
11
, coreutils
10
12
, gnugrep
13
+ , clang
14
+ , xcbuild
15
+ , darwin
16
+ , patchelf
11
17
} :
12
18
13
19
stdenv . mkDerivation ( finalAttrs : {
@@ -29,22 +35,49 @@ stdenv.mkDerivation (finalAttrs: {
29
35
30
36
nativeBuildInputs = [
31
37
perl
38
+ ] ++ lib . optionals stdenv . isDarwin [
39
+ clang
40
+ xcbuild
32
41
] ;
33
42
34
43
buildInputs = [
35
44
v8
36
45
postgresql
46
+ ] ++ lib . optionals stdenv . isDarwin [
47
+ darwin . apple_sdk . frameworks . CoreFoundation
48
+ darwin . apple_sdk . frameworks . Kerberos
37
49
] ;
38
50
39
51
buildFlags = [ "all" ] ;
40
52
41
53
makeFlags = [
42
54
# Nixpkgs build a v8 monolith instead of separate v8_libplatform.
43
55
"USE_SYSTEM_V8=1"
44
- "SHLIB_LINK=-lv8"
45
56
"V8_OUTDIR=${ v8 } /lib"
57
+ "PG_CONFIG=${ postgresql } /bin/pg_config"
58
+ ] ++ lib . optionals stdenv . isDarwin [
59
+ "CC=${ clang } /bin/clang"
60
+ "CXX=${ clang } /bin/clang++"
61
+ "SHLIB_LINK=-L${ v8 } /lib -lv8_monolith -Wl,-rpath,${ v8 } /lib"
62
+ ] ++ lib . optionals ( ! stdenv . isDarwin ) [
63
+ "SHLIB_LINK=-lv8"
46
64
] ;
47
65
66
+ NIX_LDFLAGS = ( lib . optionals stdenv . isDarwin [
67
+ "-L${ postgresql } /lib"
68
+ "-L${ v8 } /lib"
69
+ "-lv8_monolith"
70
+ "-lpq"
71
+ "-lpgcommon"
72
+ "-lpgport"
73
+ "-F${ darwin . apple_sdk . frameworks . CoreFoundation } /Library/Frameworks"
74
+ "-framework" "CoreFoundation"
75
+ "-F${ darwin . apple_sdk . frameworks . Kerberos } /Library/Frameworks"
76
+ "-framework" "Kerberos"
77
+ "-undefined" "dynamic_lookup"
78
+ "-flat_namespace"
79
+ ] ) ;
80
+
48
81
installFlags = [
49
82
# PGXS only supports installing to postgresql prefix so we need to redirect this
50
83
"DESTDIR=${ placeholder "out" } "
@@ -57,6 +90,11 @@ stdenv.mkDerivation (finalAttrs: {
57
90
patchShebangs ./generate_upgrade.sh
58
91
substituteInPlace generate_upgrade.sh \
59
92
--replace " 2.3.10 " " 2.3.10 2.3.11 2.3.12 2.3.13 2.3.14 2.3.15 "
93
+
94
+ ${ lib . optionalString stdenv . isDarwin ''
95
+ # Replace g++ with clang++ in Makefile
96
+ sed -i 's/g++/clang++/g' Makefile
97
+ '' }
60
98
'' ;
61
99
62
100
postInstall = ''
@@ -65,6 +103,17 @@ stdenv.mkDerivation (finalAttrs: {
65
103
# so changing them does not cause issues.
66
104
mv "$out/nix/store"/*/* "$out"
67
105
rmdir "$out/nix/store"/* "$out/nix/store" "$out/nix"
106
+
107
+ ${ lib . optionalString stdenv . isDarwin ''
108
+ install_name_tool -add_rpath "${ v8 } /lib" $out/lib/plv8-${ finalAttrs . version } .so
109
+ install_name_tool -add_rpath "${ postgresql } /lib" $out/lib/plv8-${ finalAttrs . version } .so
110
+ install_name_tool -add_rpath "${ stdenv . cc . cc . lib } /lib" $out/lib/plv8-${ finalAttrs . version } .so
111
+ install_name_tool -change @rpath/libv8_monolith.dylib ${ v8 } /lib/libv8_monolith.dylib $out/lib/plv8-${ finalAttrs . version } .so
112
+ '' }
113
+
114
+ ${ lib . optionalString ( ! stdenv . isDarwin ) ''
115
+ ${ patchelf } /bin/patchelf --set-rpath "${ v8 } /lib:${ postgresql } /lib:${ stdenv . cc . cc . lib } /lib" $out/lib/plv8-${ finalAttrs . version } .so
116
+ '' }
68
117
'' ;
69
118
70
119
passthru = {
@@ -134,8 +183,8 @@ stdenv.mkDerivation (finalAttrs: {
134
183
meta = with lib ; {
135
184
description = "V8 Engine Javascript Procedural Language add-on for PostgreSQL" ;
136
185
homepage = "https://plv8.github.io/" ;
137
- maintainers = with maintainers ; [ ] ;
138
- platforms = [ "x86_64-linux" "aarch64-linux" ] ;
186
+ maintainers = with maintainers ; [ samrose ] ;
187
+ platforms = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" ] ;
139
188
license = licenses . postgresql ;
140
189
} ;
141
190
} )
0 commit comments