···
69
-
jitSupport, # not default on purpose, this is set via "_jit or not" attributes
70
+
stdenv.hostPlatform.canExecute stdenv.buildPlatform
71
+
# Building with JIT in pkgsStatic fails like this:
72
+
# fatal error: 'stdio.h' file not found
73
+
&& !stdenv.hostPlatform.isStatic,
···
dlSuffix = if olderThan "16" then ".so" else stdenv.hostPlatform.extensions.sharedLibrary;
138
-
pname = "postgresql";
141
-
if jitSupport && !stdenv.cc.isClang then
143
+
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: {
153
-
pname = pname + lib.optionalString jitSupport "-jit";
155
+
pname = "postgresql";
···
__structuredAttrs = true;
165
-
hardeningEnable = lib.optionals (!stdenv'.cc.isClang) [ "pie" ];
···
175
+
++ lib.optionals jitSupport [ "jit" ]
++ lib.optionals perlSupport [ "plperl" ]
++ lib.optionals pythonSupport [ "plpython3" ]
++ lib.optionals tclSupport [ "pltcl" ];
180
-
disallowedReferences = [
185
-
disallowedRequisites = [
187
-
llvmPackages.llvm.out
188
-
] ++ (map lib.getDev (builtins.filter (drv: drv ? "dev") finalAttrs.buildInputs));
192
-
disallowedReferences = [
198
-
disallowedRequisites = [
200
-
llvmPackages.llvm.out
201
-
] ++ (map lib.getDev (builtins.filter (drv: drv ? "dev") finalAttrs.buildInputs));
183
+
disallowedReferences = [
187
+
] ++ lib.optionals jitSupport [ "jit" ];
188
+
disallowedRequisites = [
190
+
llvmPackages.llvm.out
191
+
] ++ (map lib.getDev (builtins.filter (drv: drv ? "dev") finalAttrs.buildInputs));
205
-
disallowedReferences = [
195
+
disallowedReferences = [
200
+
] ++ lib.optionals jitSupport [ "jit" ];
201
+
disallowedRequisites = [
203
+
llvmPackages.llvm.out
204
+
] ++ (map lib.getDev (builtins.filter (drv: drv ? "dev") finalAttrs.buildInputs));
213
-
disallowedReferences = [
208
+
disallowedReferences = [
212
+
] ++ lib.optionals jitSupport [ "jit" ];
216
+
disallowedReferences = [
220
+
] ++ lib.optionals jitSupport [ "jit" ];
223
+
// lib.optionalAttrs jitSupport {
225
+
disallowedReferences = [
230
+
disallowedRequisites = [
232
+
llvmPackages.llvm.out
233
+
] ++ (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.
275
-
"-fdata-sections -ffunction-sections"
276
-
+ (if stdenv'.cc.isClang then " -flto" else " -fmerge-constants -Wl,--gc-sections");
290
+
CFLAGS = "-fdata-sections -ffunction-sections -flto";
// lib.optionalAttrs perlSupport { PERL = lib.getExe perl; }
// lib.optionalAttrs pythonSupport { PYTHON = lib.getExe python3; }
···
installTargets = [ "install-world" ];
368
-
substituteInPlace "src/Makefile.global.in" --subst-var out
369
-
substituteInPlace "src/common/config_info.c" --subst-var dev
370
-
cat ${./pg_config.env.mk} >> src/common/Makefile
383
+
substituteInPlace "src/Makefile.global.in" --subst-var out
384
+
substituteInPlace "src/common/config_info.c" --subst-var dev
385
+
cat ${./pg_config.env.mk} >> src/common/Makefile
387
+
# This check was introduced upstream to prevent calls to "exit" inside libpq.
388
+
# However, this doesn't work reliably with static linking, see this and following:
389
+
# https://postgr.es/m/flat/20210703001639.GB2374652%40rfd.leadboat.com#52584ca4bd3cb9dac376f3158c419f97
390
+
# Thus, disable the check entirely, as it would currently fail with this:
391
+
# > libpq.so.5.17: U atexit
392
+
# > libpq.so.5.17: U pthread_exit
393
+
# > libpq must not be calling any function which invokes exit
394
+
# Don't mind the fact that this checks libpq.**so** in pkgsStatic - that's correct, since PostgreSQL
395
+
# still needs a shared library internally.
396
+
+ lib.optionalString (atLeast "15" && stdenv'.hostPlatform.isStatic) ''
397
+
substituteInPlace src/interfaces/libpq/Makefile \
398
+
--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}"
447
+
moveToOutput "lib/bitcode" "$jit"
448
+
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;
469
-
jitToggle = this.override {
470
-
jitSupport = !jitSupport;
psqlSchema = lib.versions.major version;
478
-
withJIT = if jitSupport then this else jitToggle;
479
-
withoutJIT = if jitSupport then jitToggle else this;
506
+
withJIT = this.withPackages (_: [ this.jit ]);
···
inherit installedExtensions;
withJIT = postgresqlWithPackages {
594
-
inherit buildEnv lib makeBinaryWrapper;
595
-
postgresql = postgresql.withJIT;
629
+
} (_: installedExtensions ++ [ postgresql.jit ]);
withoutJIT = postgresqlWithPackages {
598
-
inherit buildEnv lib makeBinaryWrapper;
599
-
postgresql = postgresql.withoutJIT;
637
+
} (_: lib.remove postgresql.jit installedExtensions);
641
+
postgresqlWithPackages {
648
+
} (ps: installedExtensions ++ f' ps);