|
23 | 23 |
|
24 | 24 | # JIT |
25 | 25 | , jitSupport |
26 | | - , nukeReferences, patchelf, llvmPackages |
| 26 | + , nukeReferences, patchelf, llvmPackages, overrideCC |
27 | 27 |
|
28 | 28 | # PL/Python |
29 | 29 | , pythonSupport ? false |
|
43 | 43 |
|
44 | 44 | pname = "postgresql"; |
45 | 45 |
|
46 | | - stdenv' = if jitSupport then llvmPackages.stdenv else stdenv; |
| 46 | + stdenv' = |
| 47 | + if jitSupport then |
| 48 | + overrideCC llvmPackages.stdenv (llvmPackages.stdenv.cc.override { |
| 49 | + # LLVM bintools are not used by default, but are needed to make -flto work below. |
| 50 | + bintools = llvmPackages.bintools; |
| 51 | + }) |
| 52 | + else |
| 53 | + stdenv; |
47 | 54 | in stdenv'.mkDerivation (finalAttrs: { |
48 | 55 | inherit version; |
49 | 56 | pname = pname + lib.optionalString jitSupport "-jit"; |
|
53 | 60 | inherit hash; |
54 | 61 | }; |
55 | 62 |
|
| 63 | + __structuredAttrs = true; |
| 64 | + |
56 | 65 | hardeningEnable = lib.optionals (!stdenv'.cc.isClang) [ "pie" ]; |
57 | 66 |
|
58 | 67 | outputs = [ "out" "lib" "doc" "man" ]; |
59 | 68 | setOutputFlags = false; # $out retains configureFlags :-/ |
| 69 | + outputChecks.lib = { |
| 70 | + disallowedReferences = [ "out" "doc" "man" ]; |
| 71 | + }; |
60 | 72 |
|
61 | 73 | buildInputs = [ |
62 | 74 | zlib |
|
87 | 99 |
|
88 | 100 | buildFlags = [ "world" ]; |
89 | 101 |
|
90 | | - # Makes cross-compiling work when xml2-config can't be executed on the host. |
91 | | - # Fixed upstream in https://github.com/postgres/postgres/commit/0bc8cebdb889368abdf224aeac8bc197fe4c9ae6 |
92 | | - env.NIX_CFLAGS_COMPILE = lib.optionalString (olderThan "13") "-I${libxml2.dev}/include/libxml2"; |
| 102 | + # libpgcommon.a and libpgport.a contain all paths returned by pg_config and are linked |
| 103 | + # into all binaries. However, almost no binaries actually use those paths. The following |
| 104 | + # flags will remove unused sections from all shared libraries and binaries - including |
| 105 | + # those paths. This avoids a lot of circular dependency problems with different outputs, |
| 106 | + # and allows splitting them cleanly. |
| 107 | + env.CFLAGS = "-fdata-sections -ffunction-sections" |
| 108 | + + (if stdenv'.cc.isClang then " -flto" else " -fmerge-constants -Wl,--gc-sections") |
| 109 | + + lib.optionalString (stdenv'.isDarwin && jitSupport) " -fuse-ld=lld" |
| 110 | + # Makes cross-compiling work when xml2-config can't be executed on the host. |
| 111 | + # Fixed upstream in https://github.com/postgres/postgres/commit/0bc8cebdb889368abdf224aeac8bc197fe4c9ae6 |
| 112 | + + lib.optionalString (olderThan "13") " -I${libxml2.dev}/include/libxml2"; |
93 | 113 |
|
94 | 114 | configureFlags = [ |
95 | 115 | "--with-openssl" |
|
106 | 126 | ++ lib.optionals gssSupport [ "--with-gssapi" ] |
107 | 127 | ++ lib.optionals pythonSupport [ "--with-python" ] |
108 | 128 | ++ lib.optionals jitSupport [ "--with-llvm" ] |
109 | | - ++ lib.optionals stdenv'.isLinux [ "--with-pam" ]; |
| 129 | + ++ lib.optionals stdenv'.isLinux [ "--with-pam" ] |
| 130 | + # This could be removed once the upstream issue is resolved: |
| 131 | + # https://postgr.es/m/flat/427c7c25-e8e1-4fc5-a1fb-01ceff185e5b%40technowledgy.de |
| 132 | + ++ lib.optionals (stdenv'.isDarwin && atLeast "16") [ "LDFLAGS_EX_BE=-Wl,-export_dynamic" ]; |
110 | 133 |
|
111 | 134 | patches = [ |
112 | 135 | (if atLeast "16" then ./patches/relative-to-symlinks-16+.patch else ./patches/relative-to-symlinks.patch) |
|
123 | 146 | map fetchurl (lib.attrValues muslPatches) |
124 | 147 | ) ++ lib.optionals stdenv'.isLinux [ |
125 | 148 | (if atLeast "13" then ./patches/socketdir-in-run-13+.patch else ./patches/socketdir-in-run.patch) |
| 149 | + ] ++ lib.optionals (stdenv'.isDarwin && olderThan "16") [ |
| 150 | + ./patches/export-dynamic-darwin-15-.patch |
126 | 151 | ]; |
127 | 152 |
|
128 | 153 | installTargets = [ "install-world" ]; |
|
137 | 162 | '' |
138 | 163 | moveToOutput "lib/libpgcommon*.a" "$out" |
139 | 164 | moveToOutput "lib/libpgport*.a" "$out" |
140 | | - moveToOutput "lib/libecpg*" "$out" |
141 | 165 |
|
142 | 166 | # Prevent a retained dependency on gcc-wrapper. |
143 | 167 | substituteInPlace "$out/lib/pgxs/src/Makefile.global" --replace ${stdenv'.cc}/bin/ld ld |
|
254 | 278 | # resulting LLVM IR isn't platform-independent this doesn't give you much. |
255 | 279 | # In fact, I tried to test the result in a VM-test, but as soon as JIT was used to optimize |
256 | 280 | # a query, postgres would coredump with `Illegal instruction`. |
257 | | - broken = (jitSupport && stdenv.hostPlatform != stdenv.buildPlatform) |
258 | | - # Allmost all tests fail FATAL errors for v12 and v13 |
259 | | - || (jitSupport && stdenv.hostPlatform.isMusl && olderThan "14"); |
| 281 | + broken = jitSupport && !stdenv.hostPlatform.canExecute stdenv.buildPlatform; |
260 | 282 | }; |
261 | 283 | }); |
262 | 284 |
|
|
0 commit comments