4

If a have a library checked out locally that builds with cabal that is used by an application. I would like to build my application against the the local library rather than something from hackage but I'm not sure how to do this. This seems like something I should be able to do, I'm just don't seem to be able to work out how.

Sandboxing

In case it matters or complicates things, the application is in a cabal sandbox with the cabal-sandbox-config file in the route directory of the application.

What I'm Trying to accomplish

I'm building Yesod application and I want to tweak the behaviour of one of the dependencies (shakespeare). I would like to build my application against my tweaked version.

Gareth Charnock
  • 1,166
  • 7
  • 17

2 Answers2

10

Use cabal sandbox add-source, which is designed specifically for this use case.

Example:

$ git clone https://github.com/SomeUser/SomeDependency
$ cd /path/to/my-project
$ cabal sandbox add-source /path/to/SomeDependency
$ cabal build

As a bonus, if you later update SomeDependency and try to rebuild my-project, cabal will notice that and reinstall SomeDependency.

Mikhail Glushenkov
  • 14,928
  • 3
  • 52
  • 65
1

Option 1:

You can just clone the project, and then run a cabal install in the cloned directory. git clone https://github.com/yesodweb/shakespeare.git

This will give you a directory shakespeare which will contain a .cabal file.

So just enter the directory and run a cabal install. This will install shakespeare. Now continue with installing your project.

The key point:

You need to install shakespeare yourself first so that when you compile your own project, ghc or cabal doesn't try to install the shakespeare dependency (from hackage by default) on its own.

Option 2:

  • Install hackage-server
  • Upload a copy of shakespeare (your tweaked version) to your local hackage
  • Edit your cabal config to prioritize your local hackage over the haskell-hackage

remote-repo: hackage.haskell.org:http://hackage.haskell.org/packages/archive

remote-repo: local.hackage:http://local.hackage/packages/archive

This might make sense if you're going to be tweaking several packages, but you're probably better off not doing this because among other things, keeping track of updates to your tweaked versions is going to be a nightmare.

iamnat
  • 4,056
  • 1
  • 23
  • 36