I'm trying to install aeson on GHC 9.2.1. I first ran cabal install --allow-newer --lib aeson
, which failed when it got to building attoparsec. It turns out this problem is already fixed in their Git repo, but hasn't landed in a release on Hackage yet. I then did these steps to build a local version with the fix:
git clone https://github.com/haskell/attoparsec.git
cd attoparsec
cabal install --allow-newer --lib .
cd ..
That succeeded, but then when I did cabal install --allow-newer --lib aeson
again, it tried to build attoparsec from Hackage again, and so failed again. How can I make cabal use what I just built and installed instead?
CodePudding user response:
There are two main methods.
One is to create a cabal project that includes both the cloned version of attoparsec and the local packages that you are working on (packages that might depend on aeson). It could be as simple as
packages: attoparsec yourpackage
In fact, you don't even need to clone the repo, you could use the source-repository-package
field instead.
Because local packages always take precedence over external ones, the repo version will be chosen when resolving dependencies.
This approach works well but has the disadvantage that if you use the patched attoparsec in many different projects, you'll have to reference and re-compile it each time.
Another approach is to create a local no-index repository in your machine, give it priority over stardard Hackage, and put attoparsec's sdist tarball there.
You need to declare the extra repository using the repository
field of your global cabal config (the path to the config is displayed in the last line of cabal help
). By default, there's only Hackage:
repository hackage.haskell.org
url: http://hackage.haskell.org/
To give the local repository priority over Hackage, you need to use the active-repositories
field, either in your global Cabal config or in a cabal.project
file.
The advantage of this method is that you don't need to create a Cabal project, and that the patched version of attoparsec will only be compiled once (as if it came from Hackage).