Cabal fails to install dependencies, but can install them if asked directly - haskell

I've seen a very strange recurring problem with Cabal that's interfering with my ability to get repeatable Haskell builds. I have a cabal project with a sandbox. If I do cabal install, I get errors of the form
Y failed during the building phase. The exception was:
ExitFailure 1
X depends on Y which failed to install.
where X is a direct dependency of my project and Y is some transitive dependency. However, if I just type cabal install X, then it works!
Here's a specific example: my project depends on the interpolate package. When I do cabal install --allow-newer, I get errors like this:
Resolving dependencies...
Configuring haskell-src-meta-0.6.0.9...
Building haskell-src-meta-0.6.0.9...
Preprocessing library haskell-src-meta-0.6.0.9...
[1 of 6] Compiling Language.Haskell.TH.Instances.Lift ( src/Language/Haskell/TH/Instances/Lift.hs, dist/dist-sandbox-d2861272/build/Language/Haskell/TH/Instances/Lift.o )
[2 of 6] Compiling Language.Haskell.Meta.Syntax.Translate ( src/Language/Haskell/Meta/Syntax/Translate.hs, dist/dist-sandbox-d2861272/build/Language/Haskell/Meta/Syntax/Translate.o )
[3 of 6] Compiling Language.Haskell.Meta.Parse ( src/Language/Haskell/Meta/Parse.hs, dist/dist-sandbox-d2861272/build/Language/Haskell/Meta/Parse.o )
[4 of 6] Compiling Language.Haskell.Meta.Parse.Careful ( src/Language/Haskell/Meta/Parse/Careful.hs, dist/dist-sandbox-d2861272/build/Language/Haskell/Meta/Parse/Careful.o )
[5 of 6] Compiling Language.Haskell.Meta ( src/Language/Haskell/Meta.hs, dist/dist-sandbox-d2861272/build/Language/Haskell/Meta.o )
[6 of 6] Compiling Language.Haskell.Meta.Utils ( src/Language/Haskell/Meta/Utils.hs, dist/dist-sandbox-d2861272/build/Language/Haskell/Meta/Utils.o )
src/Language/Haskell/Meta/Utils.hs:67:1:
Duplicate instance declarations:
instance Typeable Q
-- Defined at src/Language/Haskell/Meta/Utils.hs:67:1
instance Typeable Q -- Defined in ‘Language.Haskell.TH.Instances’
src/Language/Haskell/Meta/Utils.hs:71:1:
Duplicate instance declarations:
instance Typeable QuasiQuoter
-- Defined at src/Language/Haskell/Meta/Utils.hs:71:1
instance Typeable QuasiQuoter
-- Defined in ‘Language.Haskell.TH.Instances’
Failed to install haskell-src-meta-0.6.0.9
...
haskell-src-meta-0.6.0.9 failed during the building phase. The exception was:
ExitFailure 1
interpolate-0.1.0 depends on haskell-src-meta-0.6.0.9 which failed to install.
However, if I proceed to type cabal install interpolate-0.1.0, the installation succeeds and I'm able to keep installing my project.
This is frustrating because I have to "manually" install several packages before I can get all my dependencies installed. The fact that the original installations fail with compiler errors seems to suggest that the compiler is configured differently somehow?
I'm using GHC 7.8.3 and cabal-install 1.22.4.0 (version 1.22.3.0 of the Cabal library). Many thanks for any help!

Actually it's not a problem with the version of haskell-src-meta but rather with the version of its dependency th-orphans.
haskell-src-meta (versions 0.6.0.8 and 0.6.0.9) has an upper bound th-orphans <0.12.
With --allow-newer you told Cabal to ignore version upper bounds, so Cabal decided to use th-orphans version 0.12.0, since it's newer and presumably better. But, in fact, haskell-src-meta really does not build with th-orphans version 0.12.0, as you found out.
Unrestricted use of --allow-newer is likely to run into this kind of problem in general. It's better to specify the packages whose upper bounds you want to ignore with --allow-newer=base,containers,..., though in some cases doing so can be rather tedious.
In the first sentence of your question you mentioned repeatable builds. If that is what you want, there is no substitute for simply recording the exact versions that you want of all of your direct and indirect dependencies.

Related

haskell stack won't install dates

In a standalone module I'm using the dates package http://hackage.haskell.org/package/dates installed via cabal and it works fine. But a problem emerges when I try to make a small package out of this module using stack. The dates package is appropriately listed in dependencies and all but it doesn't work. When I try to manually install the package using stack in the project sandbox, I get the below error. Meanwhile I can install this package with cabal outside the stack sandbox without issues.
VERSIONS IN THE SANDBOX:
ghc-8.4.3
stack-1.7.1
SYSTEM VERSIONS:
ghc-8.0.2
cabal-1.24.0.2 (compiled 1.24.2.0)
error message:
Configuring dates-0.2.2.1...
Preprocessing library for dates-0.2.2.1..
Building library for dates-0.2.2.1..
[1 of 4] Compiling Data.Dates.Internal ( Data/Dates/Internal.hs, .stack-work/dist/x86_64-linux/Cabal-2.2.0.1/build/Data/Dates/Internal.o )
[2 of 4] Compiling Data.Dates.Types ( Data/Dates/Types.hs, .stack-work/dist/x86_64-linux/Cabal-2.2.0.1/build/Data/Dates/Types.o )
/tmp/stack16211/dates-0.2.2.1/Data/Dates/Types.hs:62:10: error:
• No instance for (Semigroup DateTime)
arising from the superclasses of an instance declaration
• In the instance declaration for ‘Monoid DateTime’
|
62 | instance Monoid DateTime where
| ^^^^^^^^^^^^^^^
In the end I needed to change the resolver in the stack.yaml file to an older version (lts-8.24) which would enforce the use of ghc-8.0.2. Using
stack --resolver ghc-8.0.2 setup/build
did not prevent stack from using the latest ghc version when I did
stack exec blah-exe
which raised the conflict.

Cannot install Haskell package stream-fusion-0.1.2.5: Ambiguous occurence

I'm trying to build the project Barbarosa which requires the package stream-fusion-0.1.2.5. However cabal install fails with the following
[3 of 3] Compiling Control.Monad.Stream ( Control/Monad/Stream.hs, dist/dist-sandbox-8bb5b9c9/build/Control/Monad/Stream.o )
Control/Monad/Stream.hs:136:10:
Ambiguous occurrence ‘MonadPlus’
It could refer to either ‘Control.Monad.Stream.MonadPlus’,
defined at Control/Monad/Stream.hs:124:1
or ‘GHC.Base.MonadPlus’,
imported from ‘GHC.Base’ at Control/Monad/Stream.hs:80:1-15
Control/Monad/Stream.hs:140:10:
Ambiguous occurrence ‘MonadPlus’
It could refer to either ‘Control.Monad.Stream.MonadPlus’,
defined at Control/Monad/Stream.hs:124:1
or ‘GHC.Base.MonadPlus’,
imported from ‘GHC.Base’ at Control/Monad/Stream.hs:80:1-15
I'm using GHC version 7.10.2 on OS X 10.11, installed via Haskell Platform.
It seems that the only dependency of stream-fusion is base whose version should be fine, so I'm not sure what's wrong here.
I was able to get things to compile by replacing the three occurrences of
import Data.List.Stream
with:
import Data.List
and removing stream-fusion from the build-depends: section of the cabal file.

How do you set up Haskell + ghc-mod on OS/X?

I first set up Haskell from https://www.haskell.org/platform/ but ghc-mod had problems with sandboxes and to update it I needed a newer cabal which needed a newer ghc. Or something like that. (https://stackoverflow.com/a/28049104/131227 ??)
So I deleted everything, and installed from http://ghcformacosx.github.io/.
Then some strange failure setting up a new sandbox was because something didn't properly have a dependancy for happy. (https://github.com/haskell-suite/haskell-src-exts/issues/14)
Ok. Installed happy. Now trying (again) to install ghc-mod and I get a giant mess (below).
Should I use http://www.stackage.org/?
I've seen some people mention ghc-pkg recache or cabal install cabal-install... Are those things I need to do?
Mess:
Resolving dependencies... Configuring ghc-mod-5.2.1.2... Building ghc-mod-5.2.1.2... Failed to install ghc-mod-5.2.1.2 Build log ( /Users/mark/.cabal/logs/ghc-mod-5.2.1.2.log ): Configuring ghc-mod-5.2.1.2... Building ghc-mod-5.2.1.2... Preprocessing library ghc-mod-5.2.1.2...
Language/Haskell/GhcMod/Convert.hs:1:51: Warning:
-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS [ 1 of 38] Compiling Language.Haskell.GhcMod.Read ( Language/Haskell/GhcMod/Read.hs, dist/build/Language/Haskell/GhcMod/Read.o ) [ 2 of 38] Compiling Language.Haskell.GhcMod.Cabal21 ( Language/Haskell/GhcMod/Cabal21.hs, dist/build/Language/Haskell/GhcMod/Cabal21.o ) [ 3 of 38] Compiling Language.Haskell.GhcMod.Cabal18 ( Language/Haskell/GhcMod/Cabal18.hs, dist/build/Language/Haskell/GhcMod/Cabal18.o ) [ 4 of 38] Compiling Language.Haskell.GhcMod.Cabal16 ( Language/Haskell/GhcMod/Cabal16.hs, dist/build/Language/Haskell/GhcMod/Cabal16.o ) [ 5 of 38] Compiling Language.Haskell.GhcMod.GHCChoice ( Language/Haskell/GhcMod/GHCChoice.hs, dist/build/Language/Haskell/GhcMod/GHCChoice.o ) [ 6 of 38] Compiling Language.Haskell.GhcMod.Error ( Language/Haskell/GhcMod/Error.hs, dist/build/Language/Haskell/GhcMod/Error.o )
Language/Haskell/GhcMod/Error.hs:12:1: Warning:
Module ‘Control.Monad.Error’ is deprecated:
Use Control.Monad.Except instead
Language/Haskell/GhcMod/Error.hs:40:10: Warning:
In the use of type constructor or class ‘Error’
(imported from Control.Monad.Error, but defined in Control.Monad.Trans.Error):
Deprecated: "Use Control.Monad.Trans.Except instead"
Language/Haskell/GhcMod/Error.hs:40:10: Warning:
In the use of type constructor or class ‘Error’
(imported from Control.Monad.Error, but defined in Control.Monad.Trans.Error):
Deprecated: "Use Control.Monad.Trans.Except instead" [ 7 of 38] Compiling Language.Haskell.GhcMod.Utils ( Language/Haskell/GhcMod/Utils.hs, dist/build/Language/Haskell/GhcMod/Utils.o )
Language/Haskell/GhcMod/Utils.hs:15:1: Warning:
The import of ‘Control.Applicative’ is redundant
except perhaps to import instances from ‘Control.Applicative’
To import instances alone, use: import Control.Applicative()
Language/Haskell/GhcMod/Utils.hs:45:51: Warning:
In the use of ‘strMsg’
(imported from Language.Haskell.GhcMod.Error, but defined in Control.Monad.Trans.Error):
Deprecated: "Use Control.Monad.Trans.Except instead" [ 8 of 38] Compiling Language.Haskell.GhcMod.Types ( Language/Haskell/GhcMod/Types.hs, dist/build/Language/Haskell/GhcMod/Types.o ) [ 9 of 38] Compiling Language.Haskell.GhcMod.Gap ( Language/Haskell/GhcMod/Gap.hs, dist/build/Language/Haskell/GhcMod/Gap.o )
Language/Haskell/GhcMod/Gap.hs:256:18:
Not in scope: data constructor ‘ExposePackageId’
Perhaps you meant ‘ExposePackage’ (imported from DynFlags) cabal: Error: some packages failed to install: ghc-mod-5.2.1.2 failed during the building phase. The exception was: ExitFailure 1
After applying the accepted answer (which seemed to install ghc-mod), running gch-mod gives the following:
> ghc-mod check x.hs
cabal-helper-wrapper: Installing a private copy of Cabal, this might take a
while but will only happen once per Cabal version.
If anything goes horribly wrong just delete this directory and try again:
/Users/mark/.ghc-mod/cabal-helper
If you want to avoid this automatic installation altogether install version
1.22.0.0 of Cabal manually (into your user or global package-db):
$ cabal install Cabal-1.22.0.0
...In order, the following would be installed:
filepath-1.3.0.1 (latest: 1.4.0.0) (new version)
directory-1.2.2.1 (new version)
process-1.2.3.0 (reinstall) changes: directory-1.2.2.0 -> 1.2.2.1,
filepath-1.4.0.0 -> 1.3.0.1
Cabal-1.22.0.0 (latest: 1.22.2.0) (new version)
cabal: The following packages are likely to be broken by the reinstalls:
ghc-7.10.1
Cabal-1.22.2.0
Use --force-reinstalls if you want to install anyway.
cabal-helper-wrapper: Installing Cabal version 1.22.0.0 failed.
nYou have two choices now:
- Either you install this version of Cabal in your globa/luser package-db
somehow
n- Or you can see if you can update your cabal-install to use a different
version of the Cabal library that we can build with:
$ cabal install cabal-install --constraint 'Cabal > 1.22.0.0'
nTo check the version cabal-install is currently using try:
$ cabal --version
ghc-mod: readCreateProcess: /Users/mark/.cabal/libexec/cabal-helper-wrapper "/Users/mark/work/haskell/ixberg/dist" "entrypoints" "source-dirs" "ghc-options" "ghc-src-options" "ghc-pkg-options" "--with-ghc=ghc" "--with-ghc-pkg=ghc-pkg" "--with-cabal=cabal" (exit 1): failed
Strangely, it wants the version of Cabal that is currently installed:
> cabal --version
cabal-install version 1.22.0.0
using version 1.22.0.0 of the Cabal library
Edit (August 2015) Better fix
A better command line tool for installing Haskell binaries and libraries by the awesome FPComplete group called stack means you can install ghc-mod with stack install ghc-mod (outside a project to make it global) and it will just work. The binary will be installed to ~/.local/bin and should be put on your path so your editor can find it.
I will leave the below for anyone who wishes to know what cabal Hell really meant.
Problem With DanielG's Fork
I asked on the Haskell reddit and NihillstDandy explained that the GHC for Mac OS X does not register the Cabal library. This is not true for your install from http://ghcformacosx.github.io/. It does register the Cabal library.
ghc-mod needs the cabal library to work, but it does not compile with the cabal library. Instead it compiles with cabal-helper and that looks to see if you have a registered version of the cabal library. If it does not find any then cabal-helper-wrapper will install a private copy and in this case it tired to install the same version as what cabal-install was compiled with, cabal-1.22.0.0.
When I installed DanielG's Fork it worked for my current project, but after testing it in other projects I am getting the same error you are. This is a problem with the fork and not Haskell (as far as I can tell).
Original Answer
So, while I was putting this post together ghc-mod was fixed for GHC-7.10. Thanks to DanielG!
git clone https://github.com/DanielG/ghc-mod
cd ghc-mod
cabal install -j4
And if you get errors that say "setup-Simple-Cabal-1.22.2.0-x86_64-osx-ghc-7.10.1: The program 'happy' version
>=1.17 is required but it could not be found."
cabal install happy -j4
The same for any other problems and it should work. (Although you have happy installed, so it should just work).
The rest of the post is on how to downgrade the cabal executable, also known as cabal-install, to version 1.20.0.3. Although you could really use this to downgrade to any version. Since there is a working fork of ghc-mod that works with GHC-7.10 and cabal-1.22 you do not need to downgrade to fix ghc-mod.
I'm just leaving the rest of the post up here since, unfortunately, this is a problem with Haskell as a whole. Halcyon and nix are ways to deal with Haskell's shortcomings in this regard.
How to downgrade Cabal in Haskell
When I wrote this post ghc-mod, nor any fork, compiled with GHC-7.10 and versions below 7.10 broke with cabal-1.22 sandboxes.
However, even if you compile ghc-mod with GHC-7.8.4 (the version before 7.10) and cabal-1.20.0.3 you still cannot use ghc-mod inside a sandbox created by cabal-1.22 and above. So the only way to use ghc-mod is to either downgrade your entire system to cabal-1.20.0.3 or don't use sandboxes. This means you can still use GHC-7.10, but you have to use the older version of cabal. That is unless you want to wait until the convener or someone else fixes it for GHC-7.10. Its been over a week already, but some kind Haskell programmer fixed it in a fork (see above).
If this is something you still want here is how to compile ghc-mod with GHC-7.8.4 and cabal-1.20.0.3. Also, I replace the executable cabal-1.22 with the older cabal-1.20.0.3. Note, it does not matter what directory you download the sources to.
download GHC-7.8.4 source for your OS from here
tar -xf path_to_zipped_source
cd path_to_ghc-7.8.4
The next steps will install ghc-7.8.4 as ghc-7.8.4 in the same folder as ghc-7.10 is install for you. The -j4 is to tell make to use 4 threads to compile it.
./configure
make install -j4
To get the correct version of cabal we can just ask cabal to get it.
cabal get cabal-install-1.20.0.3
cd cabal-install-1.20.0.3
Now to install cabal with ghc-7.8.4. Here cabal-1.22 will pull all the decencies and should give you some warning about installing another version of the cabal library (not to be confused with cabal-install), this should not cause problems.
cabal --with-compiler=ghc-7.8.4 install
So now you should have cabal-1.20.0.4 installed, but not on your path. It will be in ~/.cabal/bin. We need to make this global, so remove cabal-1.22 (it only removes the symlink).
rm `which cabal`
And create the symlink to cabal-1.20.0.4. Btw, you will need to remove any sandboxes you made with cabal-1.22 and remake them with cabal-1.20.0.4.
If you do not have realpath you can just type in the full path of cabal. I use it for connivence.
cd ~/.cabal/bin
ln -s `realpath cabal` /usr/local/bin
Now this is how I compiled ghc-mod on my mac (you may run into your own problems). I'm not sure why cabal couldn't do it in one call, but this worked in the end.
cabal --with-compiler=ghc-7.8.4 install happy
cabal --with-compiler=ghc-7.8.4 install haskell-src-exts-1.16.0.1
cabal --with-compiler=ghc-7.8.4 install hlint-1.9.19
cabal --with-compiler=ghc-7.8.4 install ghc-mod
Now you should be able to call ghc-mod from anywhere. To test it just type ghc-mod after you have cabal sandbox init. If it does not throw any errors then your in the clear.
The version of executable cabal that is used to configure this project should be the same as the version of the global Cabal package.
It's easier to install a compatible version of cabal-install than Cabal as follows:
$ ghc-pkg list | grep Cabal
Cabal-1.22.2.0
$ cabal install cabal-install-1.22.2.0
Or build one in sandbox and replace/shadow the original one.
Then don't forget to re-configure the project with the new cabal:
$ cabal clean && cabal configure
Now the ghc-mod should works.
If Cabal-1.22 isn't registered (ghc-pkg list cabal), the cabal-helper-wrapper will install a private copy because it needs the library installed to work, but it doesn't want to stomp on anything you have that might break by upgrading Cabal directly.
GHC for Mac OS X doesn't register the Cabal library, it comes bundled with a version of cabal-install built against it.

Random Word8 duplicate instance declaration during cabal testpack installation

What does the following error message mean when cabal install testpack-2.1.1 has failed:
... Everything above this succeeded with no problems.
[22 of 22] Compiling Control.Monad.Cont ( Control/Monad/Cont.hs, dist/build/Control/Monad/Cont.o )
Registering mtl-2.2.1...
Installing library in /home/ely/.cabal/lib/mtl-2.2.1/ghc-7.4.2
Registering mtl-2.2.1...
Downloading testpack-2.1.1...
Configuring testpack-2.1.1...
Building testpack-2.1.1...
Preprocessing library testpack-2.1.1...
[1 of 3] Compiling Test.QuickCheck.Instances ( src/Test/QuickCheck/Instances.hs, dist/build/Test/QuickCheck/Instances.o )
src/Test/QuickCheck/Instances.hs:50:10:
Duplicate instance declarations:
instance Random Word8
-- Defined at src/Test/QuickCheck/Instances.hs:50:10
instance Random Word8 -- Defined in `System.Random'
cabal: Error: some packages failed to install:
testpack-2.1.1 failed during the building phase. The exception was:
ExitFailure 1
I've tried Googling, but cannot make sense of this install error.
testpack-2.1.1 provides a so called orphan instance for Random Word8, that is, an instance where it doesn't define either the class or the type itself.
One of the several problems with orphan instances is that one of the packages which do define the class or type might choose to add that instance themselves in a later version, which is precisely what the random package has done in this case, and so the instances conflict.
From testpack version 2.1.2 there is a check that makes sure to only define the instance if the random package is too old to have done so itself. So you should be able to fix this by installing a later version of testpack instead.

c2hs installation error with Mac OS X 10.7.5

I'm trying to install c2hs with cabal install c2hs.
I created ~/.cabal/bin to install the binary beforehand.
With the command cabal install c2hs to get the errors.
src/Control/StateTrans.hs:77:1: Warning:
Module `Prelude' does not export `catch'
[ 3 of 26] Compiling Data.Errors ( src/Data/Errors.hs, dist/build/c2hs/c2hs-tmp/Data/Errors.o )
[ 4 of 26] Compiling Data.Attributes ( src/Data/Attributes.hs, dist/build/c2hs/c2hs-tmp/Data/Attributes.o )
[ 5 of 26] Compiling Text.Lexers ( src/Text/Lexers.hs, dist/build/c2hs/c2hs-tmp/Text/Lexers.o )
[ 6 of 26] Compiling Control.StateBase ( src/Control/StateBase.hs, dist/build/c2hs/c2hs-tmp/Control/StateBase.o )
[ 7 of 26] Compiling Data.NameSpaces ( src/Data/NameSpaces.hs, dist/build/c2hs/c2hs-tmp/Data/NameSpaces.o )
[ 8 of 26] Compiling C2HS.C.Attrs ( src/C2HS/C/Attrs.hs, dist/build/c2hs/c2hs-tmp/C2HS/C/Attrs.o )
[ 9 of 26] Compiling C2HS.C.Builtin ( src/C2HS/C/Builtin.hs, dist/build/c2hs/c2hs-tmp/C2HS/C/Builtin.o )
[10 of 26] Compiling Paths_c2hs ( dist/build/autogen/Paths_c2hs.hs, dist/build/c2hs/c2hs-tmp/Paths_c2hs.o )
dist/build/autogen/Paths_c2hs.hs:21:13: Not in scope: `catch'
dist/build/autogen/Paths_c2hs.hs:22:13: Not in scope: `catch'
dist/build/autogen/Paths_c2hs.hs:23:14: Not in scope: `catch'
dist/build/autogen/Paths_c2hs.hs:24:17: Not in scope: `catch'
cabal: Error: some packages failed to install:
c2hs-0.16.5 failed during the building phase. The exception was:
ExitFailure 1
What is wrong with the installation? The ghc version is 7.6.3.
The install worked for me right now, on my Ubuntu box, so I can say for sure that c2hs isn't broken for everyone right now.
I think you might have version issues.... Try
cabal update
and try the install again.
In particular-
The function Prelude.catch was moved to Control.Exception.catch recently, see https://ghc.haskell.org/trac/ghc/ticket/4865. I downloaded the c2hs sources (using cabal unpack c2hs), and looked at what headers Paths_c2hs.hs needs (this seems to be the file with the import problems). This is what the imports section contained-
import qualified Control.Exception as Exception
import Data.Version (Version(..))
import System.Environment (getEnv)
import Prelude
(Paths_c2hs.hs is autogenerated, so I had to build it first).
Indeed, it was using Control.Exception. Because this is a module in base, you should have it, and probably just have out of date/mismatched packages. (In fact, my file's line numbers don't match your error message line numbers above- This is another indication we are using different versions, and I believe mine is up to date :) .)
Although I think that the "cabal update" will fix the problem, if not, try looking in these two places-
Does Control.Exception.catch exist in your base modules? Just try to compile an empty program with an dummy reference to catch, like this-
import Control.Exception
x = catch
main = undefined
Does your autogenerated Paths_c2hs.hs point to the correct catch function. Just use cabal to unpack, configure and build c2hs and then look at dist/build/autogen/Paths_c2hs.hs. (you will probably hit your error in the build phase, but given what you have shown above, it will happen after the Paths_c2hs.hs creation).
The issue was that I installed two different versions of ghc on my mac: one from brew install ghc and the other from haskell platform.
I had to install the newest version of haskell platform, but before doing that I also needed to uninstall old version uninstall-hs only VERSION and brew unistall ghc.
After reinstalling the newest haskell platform, the compilation works fine.
https://github.com/haskell/cabal/issues/1137
How to install Haskell cabal tool for Haskell 7.6.1 on Mac OSX?
Other method can be using brew brew install haskell-platform.

Resources