nh2 / static-haskell-nix

easily build most Haskell programs into fully static Linux executables
388 stars 36 forks source link

Patch cabal to pass --static flags to pkg-config #62

Open nh2 opened 4 years ago

nh2 commented 4 years ago

pkg-config takes a --static flag to output .a files for --libs. We currently add those manually in static-haskell-nix.

Instead, we should teach cabal to pass it, given that .cabal files can specify pkg-config dependencies.

Hopefully we can then get rid of pkg-config related overrides in static-haskell-nix and fundamentally fix issues like #57, so that Haskell libraries "remember" which static system libraries they need.

nh2 commented 4 years ago

At NixCon I found that this requires adding a new field to ghc-pkg's .conf files, like extra-libraries-static, because libraries can't know at the time they invoke pkg-config whether they will eventually be linked statically or not, so we must carry along both sets of flags.

nh2 commented 4 years ago

Before realising the above, I made a WIP for passing --static to pkg-config from cabal only:

https://github.com/nh2/cabal/tree/pkg-config-static-flag

Today I also made a WIP for the more significant change of adding the relevant fields to .conf files:

https://github.com/nh2/cabal/tree/extraLibrariesStatic-field

I still have to implement the GHC side.

nh2 commented 4 years ago

Blocking Hadrian issue that prevenets me from adding fields to Cabal:

https://gitlab.haskell.org/ghc/ghc/issues/17468

alexbiehl commented 4 years ago

https://gitlab.haskell.org/ghc/ghc/issues/17468 has been fixed!

alexbiehl commented 4 years ago

@nh2 I am picking this up again. Can you elaborate what changes need to happen on the GHC side? Looking at

https://github.com/nh2/cabal/tree/extraLibrariesStatic-field I still have to implement the GHC side.

in https://github.com/nh2/static-haskell-nix/issues/62#issuecomment-552692276.

I was under the impression that Cabal would control the linker line and that GHC wouldn't need to do anything special with extra-libraries-static?