···
+
stdenv.hostPlatform.canExecute stdenv.buildPlatform
+
# Building with JIT in pkgsStatic fails like this:
+
# fatal error: 'stdio.h' file not found
+
&& !stdenv.hostPlatform.isStatic,
···
dlSuffix = if olderThan "16" then ".so" else stdenv.hostPlatform.extensions.sharedLibrary;
+
if !stdenv.cc.isClang then
overrideCC llvmPackages.stdenv (
llvmPackages.stdenv.cc.override {
# LLVM bintools are not used by default, but are needed to make -flto work below.
···
stdenv'.mkDerivation (finalAttrs: {
···
__structuredAttrs = true;
···
+
++ lib.optionals jitSupport [ "jit" ]
++ lib.optionals perlSupport [ "plperl" ]
++ lib.optionals pythonSupport [ "plpython3" ]
++ lib.optionals tclSupport [ "pltcl" ];
+
disallowedReferences = [
+
] ++ lib.optionals jitSupport [ "jit" ];
+
disallowedRequisites = [
+
] ++ (map lib.getDev (builtins.filter (drv: drv ? "dev") finalAttrs.buildInputs));
+
disallowedReferences = [
+
] ++ lib.optionals jitSupport [ "jit" ];
+
disallowedRequisites = [
+
] ++ (map lib.getDev (builtins.filter (drv: drv ? "dev") finalAttrs.buildInputs));
+
disallowedReferences = [
+
] ++ lib.optionals jitSupport [ "jit" ];
+
disallowedReferences = [
+
] ++ lib.optionals jitSupport [ "jit" ];
+
// lib.optionalAttrs jitSupport {
+
disallowedReferences = [
+
disallowedRequisites = [
+
] ++ (map lib.getDev (builtins.filter (drv: drv ? "dev") finalAttrs.buildInputs));
···
# 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.
+
CFLAGS = "-fdata-sections -ffunction-sections -flto";
// lib.optionalAttrs perlSupport { PERL = lib.getExe perl; }
// lib.optionalAttrs pythonSupport { PYTHON = lib.getExe python3; }
···
installTargets = [ "install-world" ];
+
substituteInPlace "src/Makefile.global.in" --subst-var out
+
substituteInPlace "src/common/config_info.c" --subst-var dev
+
cat ${./pg_config.env.mk} >> src/common/Makefile
+
# This check was introduced upstream to prevent calls to "exit" inside libpq.
+
# However, this doesn't work reliably with static linking, see this and following:
+
# https://postgr.es/m/flat/20210703001639.GB2374652%40rfd.leadboat.com#52584ca4bd3cb9dac376f3158c419f97
+
# Thus, disable the check entirely, as it would currently fail with this:
+
# > libpq.so.5.17: U atexit
+
# > libpq.so.5.17: U pthread_exit
+
# > libpq must not be calling any function which invokes exit
+
# Don't mind the fact that this checks libpq.**so** in pkgsStatic - that's correct, since PostgreSQL
+
# still needs a shared library internally.
+
+ lib.optionalString (atLeast "15" && stdenv'.hostPlatform.isStatic) ''
+
substituteInPlace src/interfaces/libpq/Makefile \
+
--replace-fail "echo 'libpq must not be calling any function which invokes exit'; exit 1;" "echo;"
···
# Stop lib depending on the -dev output of llvm
remove-references-to -t ${llvmPackages.llvm.dev} "$out/lib/llvmjit${dlSuffix}"
+
moveToOutput "lib/bitcode" "$jit"
+
moveToOutput "lib/llvmjit*" "$jit"
+ lib.optionalString stdenv'.hostPlatform.isDarwin ''
# The darwin specific Makefile for PGXS contains a reference to the postgres
···
this = self.callPackage generic args;
psqlSchema = lib.versions.major version;
+
withJIT = this.withPackages (_: [ this.jit ]);
···
inherit installedExtensions;
withJIT = postgresqlWithPackages {
+
} (_: installedExtensions ++ [ postgresql.jit ]);
withoutJIT = postgresqlWithPackages {
+
} (_: lib.remove postgresql.jit installedExtensions);
+
postgresqlWithPackages {
+
} (ps: installedExtensions ++ f' ps);