A new user tool for building Cabal packages based on Hadrian and/or Shake
Hello GHC Developers,
Over the last weeks I encountered a problem, that I'm not able to solve. I've did some research which resulted in this proposal. Here are the details:
For my command line application I want to redistribute cabal packages from hackage in binary form. That means to compile them and pack them into ghc-packages. Since the way how to register ghc-packages is not that trivial from an end user perspective I want the packages to be relocatable and ship them together with a relocatable build of ghc. The package registration for ghc has to be done before distribution, which seems to be possible when packages and ghc are both relocatable.
The first way one thinks of to get a relocatable package would be with Cabal. But this is currently not possible without a hackish workaround. There is an open ticket in cabal issues since 2012. There was also a discussion in 2016 to rewrite Cabal's build system based on Shake, but this was not implemented until today (which could be because Stack appeared in the meanwhile). Also things got different since they introduced the new v2-commands. For me, this leads to the conclusion that from Cabal no sustainable solution can be expected in the near future.
An other way would be to build the packages by hand with ghc and ghc-pkg. But this would essentially mean to write a large part of a new build system from scratch, because there would be parsing of .cabal files involved.
Happily there is the new Hadrian build system based on Shake. On a wiki page, see "Shaking up a library" is mentioned that there is the goal to build libraries with Shake. Maybe this feature is implemented in the meanwhile in Hadrian?
My proposal is to provide a new tool for ghc users to build cabal source packages into ghc packages. This could be a command line tool which developers can use in their custom build scripts. The generated packages should be relocatable and there should be an option to register them in a package database of your choice.
The Cabal package specification with .cabal files has become the standard today (Stack uses it too), so I think it makes sense that ghc provides the tools for working with this standard.
A benefit of such a tool could also be that some people might be encouraged to write an alternative build system to Cabal, because Cabal doesn't seem to be in a good shape at the moment.