Skip to content

Commit 7797728

Browse files
postgresql: move libecpq to lib output
This library is used by other packages, so should be in the lib output. By removing unused sections, libecpg will not contain any references to other outputs and thus does not increase the closure for the lib output anymore. This will also help massively when splitting a dev output later. As a side-effect, this also unbreaks pkgsMusl.postgresql_12_jit and pkgsMusl.postgresql_13_jit. For, at least to me, unknown reasons, those build fine now.
1 parent 5547322 commit 7797728

2 files changed

Lines changed: 45 additions & 10 deletions

File tree

pkgs/servers/sql/postgresql/generic.nix

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ let
2323

2424
# JIT
2525
, jitSupport
26-
, nukeReferences, patchelf, llvmPackages
26+
, nukeReferences, patchelf, llvmPackages, overrideCC
2727

2828
# PL/Python
2929
, pythonSupport ? false
@@ -43,7 +43,14 @@ let
4343

4444
pname = "postgresql";
4545

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;
4754
in stdenv'.mkDerivation (finalAttrs: {
4855
inherit version;
4956
pname = pname + lib.optionalString jitSupport "-jit";
@@ -53,10 +60,15 @@ let
5360
inherit hash;
5461
};
5562

63+
__structuredAttrs = true;
64+
5665
hardeningEnable = lib.optionals (!stdenv'.cc.isClang) [ "pie" ];
5766

5867
outputs = [ "out" "lib" "doc" "man" ];
5968
setOutputFlags = false; # $out retains configureFlags :-/
69+
outputChecks.lib = {
70+
disallowedReferences = [ "out" "doc" "man" ];
71+
};
6072

6173
buildInputs = [
6274
zlib
@@ -87,9 +99,17 @@ let
8799

88100
buildFlags = [ "world" ];
89101

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";
93113

94114
configureFlags = [
95115
"--with-openssl"
@@ -106,7 +126,10 @@ let
106126
++ lib.optionals gssSupport [ "--with-gssapi" ]
107127
++ lib.optionals pythonSupport [ "--with-python" ]
108128
++ 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" ];
110133

111134
patches = [
112135
(if atLeast "16" then ./patches/relative-to-symlinks-16+.patch else ./patches/relative-to-symlinks.patch)
@@ -123,6 +146,8 @@ let
123146
map fetchurl (lib.attrValues muslPatches)
124147
) ++ lib.optionals stdenv'.isLinux [
125148
(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
126151
];
127152

128153
installTargets = [ "install-world" ];
@@ -137,7 +162,6 @@ let
137162
''
138163
moveToOutput "lib/libpgcommon*.a" "$out"
139164
moveToOutput "lib/libpgport*.a" "$out"
140-
moveToOutput "lib/libecpg*" "$out"
141165
142166
# Prevent a retained dependency on gcc-wrapper.
143167
substituteInPlace "$out/lib/pgxs/src/Makefile.global" --replace ${stdenv'.cc}/bin/ld ld
@@ -254,9 +278,7 @@ let
254278
# resulting LLVM IR isn't platform-independent this doesn't give you much.
255279
# In fact, I tried to test the result in a VM-test, but as soon as JIT was used to optimize
256280
# 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;
260282
};
261283
});
262284

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
See https://postgr.es/m/eb249761-56e2-4e42-a2c5-b9ae18c1ca1f%40technowledgy.de
2+
---
3+
--- a/src/makefiles/Makefile.darwin
4+
+++ b/src/makefiles/Makefile.darwin
5+
@@ -5,6 +5,8 @@ DLSUFFIX = .so
6+
# env var name to use in place of LD_LIBRARY_PATH
7+
ld_library_path_var = DYLD_LIBRARY_PATH
8+
9+
+export_dynamic = -Wl,-export_dynamic
10+
+
11+
ifdef PGXS
12+
BE_DLLLIBS = -bundle_loader $(bindir)/postgres
13+
else

0 commit comments

Comments
 (0)