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.
This commit is contained in:
Wolfgang Walther
2024-08-23 21:37:49 +02:00
parent 5547322a0c
commit 77977286d8
2 changed files with 45 additions and 10 deletions
+32 -10
View File
@@ -23,7 +23,7 @@ let
# JIT
, jitSupport
, nukeReferences, patchelf, llvmPackages
, nukeReferences, patchelf, llvmPackages, overrideCC
# PL/Python
, pythonSupport ? false
@@ -43,7 +43,14 @@ let
pname = "postgresql";
stdenv' = if jitSupport then llvmPackages.stdenv else stdenv;
stdenv' =
if jitSupport then
overrideCC llvmPackages.stdenv (llvmPackages.stdenv.cc.override {
# LLVM bintools are not used by default, but are needed to make -flto work below.
bintools = llvmPackages.bintools;
})
else
stdenv;
in stdenv'.mkDerivation (finalAttrs: {
inherit version;
pname = pname + lib.optionalString jitSupport "-jit";
@@ -53,10 +60,15 @@ let
inherit hash;
};
__structuredAttrs = true;
hardeningEnable = lib.optionals (!stdenv'.cc.isClang) [ "pie" ];
outputs = [ "out" "lib" "doc" "man" ];
setOutputFlags = false; # $out retains configureFlags :-/
outputChecks.lib = {
disallowedReferences = [ "out" "doc" "man" ];
};
buildInputs = [
zlib
@@ -87,9 +99,17 @@ let
buildFlags = [ "world" ];
# Makes cross-compiling work when xml2-config can't be executed on the host.
# Fixed upstream in https://github.com/postgres/postgres/commit/0bc8cebdb889368abdf224aeac8bc197fe4c9ae6
env.NIX_CFLAGS_COMPILE = lib.optionalString (olderThan "13") "-I${libxml2.dev}/include/libxml2";
# libpgcommon.a and libpgport.a contain all paths returned by pg_config and are linked
# into all binaries. However, almost no binaries actually use those paths. The following
# flags will remove unused sections from all shared libraries and binaries - including
# those paths. This avoids a lot of circular dependency problems with different outputs,
# and allows splitting them cleanly.
env.CFLAGS = "-fdata-sections -ffunction-sections"
+ (if stdenv'.cc.isClang then " -flto" else " -fmerge-constants -Wl,--gc-sections")
+ lib.optionalString (stdenv'.isDarwin && jitSupport) " -fuse-ld=lld"
# Makes cross-compiling work when xml2-config can't be executed on the host.
# Fixed upstream in https://github.com/postgres/postgres/commit/0bc8cebdb889368abdf224aeac8bc197fe4c9ae6
+ lib.optionalString (olderThan "13") " -I${libxml2.dev}/include/libxml2";
configureFlags = [
"--with-openssl"
@@ -106,7 +126,10 @@ let
++ lib.optionals gssSupport [ "--with-gssapi" ]
++ lib.optionals pythonSupport [ "--with-python" ]
++ lib.optionals jitSupport [ "--with-llvm" ]
++ lib.optionals stdenv'.isLinux [ "--with-pam" ];
++ lib.optionals stdenv'.isLinux [ "--with-pam" ]
# This could be removed once the upstream issue is resolved:
# https://postgr.es/m/flat/427c7c25-e8e1-4fc5-a1fb-01ceff185e5b%40technowledgy.de
++ lib.optionals (stdenv'.isDarwin && atLeast "16") [ "LDFLAGS_EX_BE=-Wl,-export_dynamic" ];
patches = [
(if atLeast "16" then ./patches/relative-to-symlinks-16+.patch else ./patches/relative-to-symlinks.patch)
@@ -123,6 +146,8 @@ let
map fetchurl (lib.attrValues muslPatches)
) ++ lib.optionals stdenv'.isLinux [
(if atLeast "13" then ./patches/socketdir-in-run-13+.patch else ./patches/socketdir-in-run.patch)
] ++ lib.optionals (stdenv'.isDarwin && olderThan "16") [
./patches/export-dynamic-darwin-15-.patch
];
installTargets = [ "install-world" ];
@@ -137,7 +162,6 @@ let
''
moveToOutput "lib/libpgcommon*.a" "$out"
moveToOutput "lib/libpgport*.a" "$out"
moveToOutput "lib/libecpg*" "$out"
# Prevent a retained dependency on gcc-wrapper.
substituteInPlace "$out/lib/pgxs/src/Makefile.global" --replace ${stdenv'.cc}/bin/ld ld
@@ -254,9 +278,7 @@ let
# resulting LLVM IR isn't platform-independent this doesn't give you much.
# In fact, I tried to test the result in a VM-test, but as soon as JIT was used to optimize
# a query, postgres would coredump with `Illegal instruction`.
broken = (jitSupport && stdenv.hostPlatform != stdenv.buildPlatform)
# Allmost all tests fail FATAL errors for v12 and v13
|| (jitSupport && stdenv.hostPlatform.isMusl && olderThan "14");
broken = jitSupport && !stdenv.hostPlatform.canExecute stdenv.buildPlatform;
};
});
@@ -0,0 +1,13 @@
See https://postgr.es/m/eb249761-56e2-4e42-a2c5-b9ae18c1ca1f%40technowledgy.de
---
--- a/src/makefiles/Makefile.darwin
+++ b/src/makefiles/Makefile.darwin
@@ -5,6 +5,8 @@ DLSUFFIX = .so
# env var name to use in place of LD_LIBRARY_PATH
ld_library_path_var = DYLD_LIBRARY_PATH
+export_dynamic = -Wl,-export_dynamic
+
ifdef PGXS
BE_DLLLIBS = -bundle_loader $(bindir)/postgres
else