1
votes

When I build a Cabal project without a sandbox, Cabal uses existing libraries from my Haskell Platform installation. However, if I try to do the same inside a Cabal sandbox, Cabal forcibly rebuilds all my dependencies into the sandbox.

To save on build times and disk space, it'd be great to be able to instruct Cabal to use existing Haskell Platform libraries instead of rebuilding them. Is this possible?

Example (files in a gist):

executable blog
  hs-source-dirs:    .
  main-is:           Test.hs
  build-depends:     base >= 4.5 && < 5
                   , text

If I cabal build in the directory containing this .cabal file, my Test module gets built against the Haskell Platform version of text.

However, if I do the same in a sandbox:

cabal clean # (or alternatively clone an empty gist)
cabal sandbox init
cabal build

I get this:

$ cabal build
Package has never been configured. Configuring with default flags. If this
fails, please run configure manually.
Resolving dependencies...
Configuring install-test-0.1...
cabal: At least the following dependencies are missing:
text -any

If I now go and cabal install, the latest text library is built from scratch under my sandbox.

1
I just tried git clone https://gist.github.com/8964143.git && cd 8964143 && cabal sandbox init && cabal run and this worked for me without recompiling the dependencies. cabal-install 1.18.0.2 with Cabal 1.18.1.2 on Windows. - Toxaris
Hmm, perhaps I need to try it on a newer cabal. Mine is cabal --version: cabal-install version 1.18.0.2, using version 1.18.1.1 of the Cabal library. Or it's some kind of an installation version conflict. :( - Nurpax
@Toxaris: Did you do a cabal clean between the first cabal build and the second cabal sandbox init && cabal build? If that works for you, what about cloning the gist and then directly doing cabal sandbox init && cabal build? I realize my instructions didn't mention the part about clean builds. I'll edit my post to include this information. - Nurpax
I executed literally the command line from my comment, so yes, I cloned the gist and then directly did cabal sandbox init. Now I also tried git clone https://gist.github.com/8964143.git && cd 8964143 && cabal build && cabal sandbox init && cabal run as well as git clone https://gist.github.com/8964143.git && cd 8964143 && cabal build && cabal sandbox init && cabal run. They all do some configuring and compilation, and then print "hello". - Toxaris
I think in both cases you get left overs from cabal build which means the sandboxed build does nothing. Can you try git clone https://gist.github.com/8964143.git && cd 8964143 && cabal sandbox init && cabal run - it shouldn't work. Sorry for this back and forth. - Nurpax

1 Answers

0
votes

As per cabal-install bug #1695, this is currently not supported. It's something that may eventually be built, see multi-instance packages for more information.

If anyone's reading and cares, an alternative that should work for some users would be to share a single cabal sandbox among multiple projects. This way you could still keep your Haskell Platform installation separate from library installations you need during your development. More on that in An Introduction to Cabal sandboxes