pkg-config: Use --libs --static when building with using --enable-executable-static
When --enable-executable-static is enabled Cabal passes --static to pkg-config to obtain linker flags for static linking.
Please include the following checklist in your PR:
- [X] Patches conform to the coding conventions.
- [X] Any changes that could be relevant to users have been recorded in the changelog (add file to
changelog.ddirectory). - [X] The documentation has been updated, if necessary.
Please also shortly describe how you tested your change. Bonus points for added tests!
@nh2 does this look good? If you say so, I'll merge this without requiring a test case
The motion is great, and I want and need this, but I think what's in this PR is not enough to make it work well.
I already did most of this work in the past, please read https://github.com/nh2/static-haskell-nix/issues/62.
Key important part:
At NixCon I found that this requires adding a new field to ghc-pkg's
.conffiles, likeextra-libraries-static, because libraries can't know at the time they invokepkg-configwhether they will eventually be linked statically or not, so we must carry along both sets of flags.
This requires Cabal changes (which I provide in 2 branches, linked from there), and a GHC change (which I got blocked on because of Hadrian bugs).
I think the right way to do this is to fix Hadrian (I already provided a WIP GHC PR, linked, but then ran out of time for now), and then do the GHC side and rebase the Cabal patches.
I'd be happy to advise on those topics if you'd like to do it @alexbiehl because i'm currently too busy to finish it myself.
Great! I lam willing to take this on. It will take a while as I am on vacations though. So feel free to take this up again in the meantime. I will leave a note when I start working on it actively.
@alexbiehl any plans to return to this?
Hi! Thanks for the gentle reminder. I lost track of this but static linking is still near and dear to my heart and would love to get this done. I have put this on my backlog for tue weekend to evaluate and see what’s left to do.
Oh, great news. In case it matters, here's a probably superficially related newer issue not yet mentioned in pingbacks above: #7236,
@alexbiehl would you like my help with fixing the conflicts of your PR?
@Kleidukos sure! Feel free to to resolve and push!
@Kleidukos: I have an impression the actual change got literally lost while formatting. If I'm mistaken, Could you point out what the original change has been? Ideally, it'd be in a commit separate from the formatting changes.
I remove needs-review for now because it currently needs some love (see Mikolaj's comment above)..
Hello, I am going through old PRs to check whether they are stale.
If this PR is still “live”, write a comment and I will remove the consider closing label. Otherwise in ≃ 2 weeks this PR will be closed.
All I see in the current diff are formatting changes, and current master seems to invoke pkg-config --libs --static.
https://github.com/haskell/cabal/blob/6953972bfa6ec706d171cda8bfcba2b7354a8206/Cabal/src/Distribution/Simple/Configure.hs#L2440
I don't see this working at all.
I'm linking against a Haskell library, which itself requires further libraries when statically linking against it.
Cabal doesn't seem to gather the pkgconfig-depends from libraries in the depgraph to unpack further private libs. If you try to add those explicitly to your current cabal file (which is a hack)... then it doesn't work either, because it inserts them at the beginning of the linker line, which is useless.
Here's a minimal reproducer: https://github.com/hasufell/cabal-extra-libraries
curl-1.3.8-inplace.conf will show:
extra-libraries-static:
curl ssl crypto z brotlidec brotlicommon zstd ssl crypto dl psl
unistring idn2 unistring nghttp2 cares pthread
...which is correctly derived from pkg-config --libs --static libcurl, but it never makes it into the linker line of the executable that depends on the haskell curl library.