From 8f215822a179612ea81c6aa7096f22436a4a78a8 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sun, 3 Jul 2022 02:59:26 +0200 Subject: [PATCH] postgresql: Split out dev output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The package contains some files only necessary for linking other software against PgSQL’s libraries. Those files include compiler flags that reference `dev` outputs of other libraries, unnecessarily increasing the runtime closure. Let’s move those files to a `dev` output, reducing the runtime closure of `out`. We also need to clear out some paths hardcoded into the libs to avoid a dependency cycle between the `dev` and `out` outputs. This includes the path to PGXS files for the `libpgcommon` and `postgres` server (used e.g. by `SELECT pg_config()` query); we restore the path explicitly for `pg_config` program. The `out` output will be the root of the graph. This further reduces the closure size of out from 236.5M to 235.5M. --- pkgs/servers/sql/postgresql/default.nix | 23 ++++-- .../patches/hardcode-pg_config-paths.patch | 70 +++++++++++++++++++ .../patches/hardcode-pgxs-path.patch | 14 ---- .../patches/prevent-output-cycle.patch | 17 +++++ 4 files changed, 103 insertions(+), 21 deletions(-) create mode 100644 pkgs/servers/sql/postgresql/patches/hardcode-pg_config-paths.patch delete mode 100644 pkgs/servers/sql/postgresql/patches/hardcode-pgxs-path.patch create mode 100644 pkgs/servers/sql/postgresql/patches/prevent-output-cycle.patch diff --git a/pkgs/servers/sql/postgresql/default.nix b/pkgs/servers/sql/postgresql/default.nix index 44581e85c8611..46b7e115c8a2a 100644 --- a/pkgs/servers/sql/postgresql/default.nix +++ b/pkgs/servers/sql/postgresql/default.nix @@ -54,8 +54,7 @@ let hardeningEnable = lib.optionals (!stdenv'.cc.isClang) [ "pie" ]; - outputs = [ "out" "lib" "doc" "man" ]; - setOutputFlags = false; # $out retains configureFlags :-/ + outputs = [ "out" "dev" "lib" "doc" "man" ]; buildInputs = [ zlib @@ -100,7 +99,6 @@ let "--with-libxml" "--with-icu" "--sysconfdir=/etc" - "--libdir=$(lib)/lib" "--with-system-tzdata=${tzdata}/share/zoneinfo" "--enable-debug" (lib.optionalString enableSystemd "--with-systemd") @@ -115,7 +113,12 @@ let (if atLeast "16" then ./patches/disable-normalize_exec_path.patch else ./patches/disable-resolve_symlinks.patch) ./patches/less-is-more.patch - ./patches/hardcode-pgxs-path.patch + + # Hardcode the path to pgxs and other dirs so that pg_config returns the path in the package, + # rather than one relative to the location pg_config was executed in. + # The placeholders are resolved in postPatch. + ./patches/hardcode-pg_config-paths.patch + ./patches/specify_pkglibdir_at_runtime.patch ./patches/findstring.patch @@ -138,6 +141,9 @@ let '' else ./patches/remove-refs-from-configure-flags-upto-12.patch) + # Patch out includedir path references in libraries and programs. + ./patches/prevent-output-cycle.patch + ] ++ lib.optionals stdenv'.hostPlatform.isMusl ( let self = { @@ -190,8 +196,9 @@ let LC_ALL = "C"; postPatch = '' - # Hardcode the path to pgxs so pg_config returns the path in $out - substituteInPlace "src/common/config_info.c" --replace HARDCODED_PGXS_PATH "$out/lib" + # Substitute placeholders from hardcode-pg_config-paths.patch + substituteInPlace "src/common/config_info.c" --subst-var out + substituteInPlace "src/bin/pg_config/pg_config.c" --subst-var dev '' + lib.optionalString jitSupport '' # Force lookup of jit stuff in $out instead of $lib substituteInPlace src/backend/jit/jit.c --replace pkglib_path \"$out/lib\" @@ -205,9 +212,11 @@ let moveToOutput "lib/libpgcommon*.a" "$out" moveToOutput "lib/libpgport*.a" "$out" moveToOutput "lib/libecpg*" "$out" + moveToOutput "bin/pg_config" "$dev" + moveToOutput "lib/pgxs" "$dev" # Prevent a retained dependency on gcc-wrapper. - substituteInPlace "$out/lib/pgxs/src/Makefile.global" --replace ${stdenv'.cc}/bin/ld ld + substituteInPlace "$dev/lib/pgxs/src/Makefile.global" --replace ${stdenv'.cc}/bin/ld ld if [ -z "''${dontDisableStatic:-}" ]; then # Remove static libraries in case dynamic are available. diff --git a/pkgs/servers/sql/postgresql/patches/hardcode-pg_config-paths.patch b/pkgs/servers/sql/postgresql/patches/hardcode-pg_config-paths.patch new file mode 100644 index 0000000000000..d7ec0009c9848 --- /dev/null +++ b/pkgs/servers/sql/postgresql/patches/hardcode-pg_config-paths.patch @@ -0,0 +1,70 @@ +diff --git a/src/bin/pg_config/pg_config.c b/src/bin/pg_config/pg_config.c +index 62b97af..e5b71e5 100644 +--- a/src/bin/pg_config/pg_config.c ++++ b/src/bin/pg_config/pg_config.c +@@ -112,6 +112,11 @@ advice(void) + fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname); + } + ++static char* ++get_config_val(ConfigData configdata) { ++ return strcmp(configdata.name, "PGXS") == 0 ? "@dev@/lib/pgxs/src/makefiles/pgxs.mk" : configdata.setting; ++} ++ + static void + show_item(const char *configname, + ConfigData *configdata, +@@ -122,7 +127,7 @@ show_item(const char *configname, + for (i = 0; i < configdata_len; i++) + { + if (strcmp(configname, configdata[i].name) == 0) +- printf("%s\n", configdata[i].setting); ++ printf("%s\n", get_config_val(configdata[i])); + } + } + +@@ -160,7 +165,7 @@ main(int argc, char **argv) + if (argc < 2) + { + for (i = 0; i < configdata_len; i++) +- printf("%s = %s\n", configdata[i].name, configdata[i].setting); ++ printf("%s = %s\n", configdata[i].name, get_config_val(configdata[i])); + exit(0); + } + +diff --git a/src/common/config_info.c b/src/common/config_info.c +index aa643b6..3750c14 100644 +--- a/src/common/config_info.c ++++ b/src/common/config_info.c +@@ -42,11 +42,7 @@ get_configdata(const char *my_exec_path, size_t *configdata_len) + configdata = (ConfigData *) palloc(*configdata_len * sizeof(ConfigData)); + + configdata[i].name = pstrdup("BINDIR"); +- strlcpy(path, my_exec_path, sizeof(path)); +- lastsep = strrchr(path, '/'); +- if (lastsep) +- *lastsep = '\0'; +- cleanup_path(path); ++ strlcpy(path, "@out@/bin", sizeof(path)); + configdata[i].setting = pstrdup(path); + i++; + +@@ -105,8 +101,7 @@ get_configdata(const char *my_exec_path, size_t *configdata_len) + i++; + + configdata[i].name = pstrdup("SHAREDIR"); +- get_share_path(my_exec_path, path); +- cleanup_path(path); ++ strlcpy(path, "@out@/share", sizeof(path)); + configdata[i].setting = pstrdup(path); + i++; + +@@ -117,7 +112,7 @@ get_configdata(const char *my_exec_path, size_t *configdata_len) + i++; + + configdata[i].name = pstrdup("PGXS"); +- get_pkglib_path(my_exec_path, path); ++ strlcpy(path, "/dev/null", sizeof(path)); + strlcat(path, "/pgxs/src/makefiles/pgxs.mk", sizeof(path)); + cleanup_path(path); + configdata[i].setting = pstrdup(path); diff --git a/pkgs/servers/sql/postgresql/patches/hardcode-pgxs-path.patch b/pkgs/servers/sql/postgresql/patches/hardcode-pgxs-path.patch deleted file mode 100644 index 6cd449769baac..0000000000000 --- a/pkgs/servers/sql/postgresql/patches/hardcode-pgxs-path.patch +++ /dev/null @@ -1,14 +0,0 @@ -diff -Naur postgresql-9.6.1-orig/src/common/config_info.c postgresql-9.6.1/src/common/config_info.c ---- postgresql-9.6.1-orig/src/common/config_info.c 2016-11-22 21:39:29.231929261 +0100 -+++ postgresql-9.6.1/src/common/config_info.c 2016-11-22 23:36:53.685163543 +0100 -@@ -118,7 +118,10 @@ - i++; - - configdata[i].name = pstrdup("PGXS"); -+ strlcpy(path, "HARDCODED_PGXS_PATH", sizeof(path)); -+/* commented out to be able to point to nix $out path - get_pkglib_path(my_exec_path, path); -+*/ - strlcat(path, "/pgxs/src/makefiles/pgxs.mk", sizeof(path)); - cleanup_path(path); - configdata[i].setting = pstrdup(path); diff --git a/pkgs/servers/sql/postgresql/patches/prevent-output-cycle.patch b/pkgs/servers/sql/postgresql/patches/prevent-output-cycle.patch new file mode 100644 index 0000000000000..972dac1c4da77 --- /dev/null +++ b/pkgs/servers/sql/postgresql/patches/prevent-output-cycle.patch @@ -0,0 +1,17 @@ +diff --git a/src/port/Makefile b/src/port/Makefile +index bfe1feb..1f9f0d3 100644 +--- a/src/port/Makefile ++++ b/src/port/Makefile +@@ -152,9 +152,9 @@ pg_config_paths.h: $(top_builddir)/src/Makefile.global + echo "#define PGBINDIR \"$(bindir)\"" >$@ + echo "#define PGSHAREDIR \"$(datadir)\"" >>$@ + echo "#define SYSCONFDIR \"$(sysconfdir)\"" >>$@ +- echo "#define INCLUDEDIR \"$(includedir)\"" >>$@ +- echo "#define PKGINCLUDEDIR \"$(pkgincludedir)\"" >>$@ +- echo "#define INCLUDEDIRSERVER \"$(includedir_server)\"" >>$@ ++ echo "#define INCLUDEDIR \"/dev/null/include\"" >>$@ ++ echo "#define PKGINCLUDEDIR \"/dev/null/include\"" >>$@ ++ echo "#define INCLUDEDIRSERVER \"/dev/null/include/server\"" >>$@ + echo "#define LIBDIR \"$(libdir)\"" >>$@ + echo "#define PKGLIBDIR \"$(pkglibdir)\"" >>$@ + echo "#define LOCALEDIR \"$(localedir)\"" >>$@