-
-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
postgresql: split -lib and -dev outputs cleanly #294504
base: staging
Are you sure you want to change the base?
Conversation
Converting to a draft until the base PRs are merged. |
Yeah, from a first glance I prefer this PR over the alternatives. |
I don't think this Of course the fix is simple - just make |
I wonder how this would work before this PR anyway. Currently, those libraries are in the default output, but neither When I remove those libraries entirely, then
No mention of the -dev output anywhere, but it still works fine. Without knowing exactly what the magic behind the scenes does here, I conclude that this will work just fine without pg_config / pkg-config returning another |
912d957
to
080e95d
Compare
080e95d
to
9900726
Compare
Yep, I came to the same conclusion a while back.
I don't think this is a great solution either. I would find it pretty surprising if installing Alternatively I could see
This is one of the reason I still think a separate |
👍 for avoiding wrappers with |
Note to myself to investigate: #322025 (comment) mentions that we still have |
In particular, in
This is for |
The following patch based on #322025 avoids these references in the output. That is, it removes references from CONFIGURE_ARGS and does not record VAL_{CC,CPPFLAGS,…}. diff --git a/pkgs/servers/sql/postgresql/generic.nix b/pkgs/servers/sql/postgresql/generic.nix
index 2bc8e922205a..01a75227f245 100644
--- a/pkgs/servers/sql/postgresql/generic.nix
+++ b/pkgs/servers/sql/postgresql/generic.nix
@@ -7,6 +7,8 @@ let
, pkg-config, libxml2, tzdata, libkrb5, substituteAll, darwin
, linux-pam
, removeReferencesTo
+ , writeScript
+ , nukeReferences
# This is important to obtain a version of `libpq` that does not depend on systemd.
, systemdSupport ? lib.meta.availableOn stdenv.hostPlatform systemd && !stdenv.hostPlatform.isStatic
@@ -108,6 +110,7 @@ let
makeWrapper
pkg-config
removeReferencesTo
+ nukeReferences
]
++ lib.optionals jitSupport [ llvmPackages.llvm.dev ];
@@ -175,6 +178,31 @@ let
substituteInPlace "src/Makefile.global.in" --subst-var out
# Hardcode the path to pgxs so pg_config returns the path in $dev
substituteInPlace "src/common/config_info.c" --subst-var dev
+
+ # Do not record CC and related build information. See code reference:
+ # https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/common/Makefile;h=3d83299432b948b08e18f8371d514ba70c026845;hb=HEAD#l34
+ substituteInPlace src/common/Makefile \
+ --replace-fail \
+ "override CPPFLAGS += -DVAL_" \
+ "# override CPPFLAGS += -DVAL_"
+
+ # Record arguments without store references.
+ substituteInPlace configure \
+ --replace-fail \
+ '#define CONFIGURE_ARGS "$ac_configure_args"' \
+ '#define CONFIGURE_ARGS "$fakeConfigureArgs"'
+ # PostgreSQL compares configure script timestamps.
+ touch -r configure.${if atLeast "14" then "ac" else "in"} configure
+ '';
+
+ # Avoid implicit references in the recorded configure arguments.
+ configureScript = writeScript "postgresql-configure-wrapper" ''
+ printf %s "''${*@Q}" >fake-configure-args
+ nuke-refs fake-configure-args
+ fakeConfigureArgs=$(<fake-configure-args)
+ rm fake-configure-args
+ export fakeConfigureArgs
+ exec ./configure "$@"
'';
postInstall = This is seems to be a supported behavior, see
|
471c7c7
to
be5ce4d
Compare
First of all, I added a
My thoughts about this:
The only way I found to achieve both is to just empty the This also made me realize that the postgres binary contains some more references to the I left this change as a fixup commit in 02e2ecd for you to have a look at. @Ma27 @tie WDYT about this approach? |
be5ce4d
to
2c3eead
Compare
This sounds reasonable, at least I’m not aware of any pg_config view use cases. Haven’t checked whether fixup commit 02e2ecd still retains |
AFAICT from the postgres source, those |
Eh sorry, I'm not sure if I read about this PR being unblocked and forgot or if I just missed it. Anyways, apologies! But hey, this has been a pleasant surprise at least ;-)
I'm a little torn on this. On one hand I like it (and it solves the output issue!), OTOH this seems a little... unexpected?
I can try it out. I mean, the jit test should explode already if that's the case (but to be sure, I can probably dogfood the change on one of my private systems as soon as I've reviewed it). |
Change is looking pretty promising now. Letting it run on my systems to see if I hit any regressions. Other than that, after the enxt iteration this is hopefully good to go. |
#307880 has landed in master. The Darwin LTO issues should be resolved now. If not, please ping me, so I can investigate. |
2c3eead
to
2899878
Compare
Dynamic modules are technically libraries, but are not used by other packages. Instead they are loaded by PostgreSQL itself, e.g. as extensions. Those just increased the size of the lib output without benefit. This removes the NIX_PGLIBDIR hack introduced in NixOS#17838 and instead makes sure that pg_config always returns the correct PGLIBDIR. The test for postgis introduced in the same PR is still passing with the change.
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 splits a dev output to make the default output not depend on any build dependencies anymore. This also avoids removing references from pgxs' Makefile this way, which should, at least theoretically, be good to build extensions via pgxs, making sure they use the same tooling. ecpg is the "embedded SQL C preprocessor", which is certainly a dev tool. Most important, for closure size anyway, is to move pg_config to the dev output, since it retains paths to all the other outputs. The only thing with references to the dev output remaining is then the postgres binary itself. It contains all the output paths, because it shows those in the pg_config system view. There is no other way than to nuke those references to avoid circular dependencies between outputs - and blowing up closure size again.
The !isDarwin condition seems to have been put in place only because of the use of patchelf, which in turn seemed to be necessary because of nuke-refs. Replacing the big nuke with the more granular remove-references-to allows enabling this for darwin, too.
This prevents silently ignoring errors from "find".
glibc is not available on darwin anyway and isGnu is just shorter.
2899878
to
569f960
Compare
Description of changes
TLDR: This splits outputs for the postgresql package cleanly, using a minimum of patching and/or nuking of references. Instead, dead references to other store paths are removed at compile and link time. The minimal -lib output is then added as a top-level
libpq
package.This builds on my previous work in #292993 and #293996 and contains commits from those two branches. Please ignore the first ~20 commits here and provide feedback for those in the two other PRs. This PR starts with
treewide: prepare pg_config moving to dev
. This commit (by @jtojnar) and the 4 commits after (by @SuperSandro2000) were cherry-picked from #179962. Compared to #179962, the approach taken in this PR is simpler and requires far less patching of postgresql source code. In fact, the overall size of patches is reduced compared to before and fewer references needed to be removed afterwards.While the most work here involved splitting the -dev output, a clean -lib output comes with that naturally. Thus, this PR replaces #179962 and #273175. The cleaned up lib output was discussed in #61580 (comment) (@thoughtpolice). With this output available, it's easy to create a top-level attribute
libpq
pointing to the latest version's lib output automatically as suggested by @danbst in #61580 (comment), which should resolve #61580 (@nh2). A true separate libpq package as proposed in #234470 (@szlend) would then not be necessary. This PR will be followed-up by another PR to build postgresql v16+ based on meson instead of autotools as mentioned in #292993 (comment). With a bit of patching (of which I have a working PoC already), this will allow us to build postgresql (at least libpq, but possibly even more) inpkgsStatic
- which is probably the biggest thing that didn't work so far and why a separate libpq package was asked for in the first place.After the split, the outputs contain the following:
out
:pg_config
andecpg
which are in the dev output. The default output thus includes both server-side and client-side binaries.lib
:/share/locale
folders, if there were any built, which is not the case right nowdoc
andman
as beforedev
:/include
(both server and client)pgxs
infrastructure to build extensionslibpgport*.a
,libpgcommon*.a
andlibpgfeutils.a
ecpg
andpg_config
binaries as mentioned abovepg_config
outputs all paths correctly. Example:One thing that is still missing right now, is that theThis should work, see comment below. I think this question was also raised by @szlend in #273175 (comment).-dev/lib
folder must be added to the pkg-config file, so thatlibpgcommon
,libpgport
etc. can be found. It's still unclear to me whether we need to add this to some other parts of thepg_config
output, too, to make it possible for pg_config-based builds to actually find those static libraries.Maintainer ping, if not mentioned above already: @globin @marsam @ivan @Ma27
Things done
I built all 5 versions (12-16) with and without JIT support, with glibc (default) and via
pkgsMusl
. I also built.tests
for the glibc variants (musl didn't work for me for unrelated reasons). I built all extensions with various versions (which resulted in #294457). This works very well, so far.What I did not build, yet, is any downstream packages actually depending on
postgresql
and the new -dev output. This will be the next step, but I would like to put this PR out for feedback already.nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Add a 👍 reaction to pull requests you find important.