Why am I getting build plan errors running "stack haddock" when "stack test" works? - haskell

I'm creating a new Haskell project using Stack 0.1.3.1 on Windows 8. My stack.yaml file looks like this:
flags: {}
packages:
- 'lazy-engine'
extra-deps: []
resolver: lts-3.4
When I run stack build or stack test, everything works beautifully. I can run haddock manually from the command line and that works, too. But when I run stack haddock I get output like this:
Setting codepage to UTF-8 (65001) to ensure correct output from GHC
NOTE: the haddock command is functionally equivalent to 'build --haddock'
While constructing the BuildPlan the following exceptions were encountered:
-- Failure when adding dependencies:
base: needed (>=4.5 && <4.9), latest is 4.8.1.0, but not present in build plan
needed for package: array-0.5.1.0
-- While attempting to add dependency,
Could not find package base in known packages
-- Failure when adding dependencies:
array: needed (-any), latest is 0.5.1.0, but couldn't resolve its dependencies
base: needed (>=4.2 && <5), latest is 4.8.1.0, but not present in build plan
deepseq: needed (>=1.2 && <1.5), latest is 1.4.1.2, but couldn't resolve its dependencies
ghc-prim: needed (-any), latest is 0.4.0.0, but not present in build plan
needed for package: containers-0.5.6.2
-- Failure when adding dependencies:
array: needed (>=0.3 && <0.6), latest is 0.5.1.0, but couldn't resolve its dependencies
base: needed (==4.3.* || >=4.5 && <4.9), latest is 4.8.1.0, but not present in build plan
needed for package: deepseq-1.4.1.1
-- While attempting to add dependency,
Could not find package ghc-prim in known packages
-- Failure when adding dependencies:
base: needed (>=4.7 && <5), latest is 4.8.1.0, but not present in build plan
containers: needed (==0.5.*), latest is 0.5.6.3, but couldn't resolve its dependencies
needed for package: lazy-engine-0.1.0.0
Recommended action: try adding the following to your extra-deps in
C:\Users\Aaron\Documents\GitHub\lazy-engine\stack.yaml
- base-4.8.1.0
- ghc-prim-0.4.0.0
You may also want to try the 'stack solver' command
Obviously this is nonsense—I shouldn't have to add base to my extra-deps, especially since I'm working off an LTS package set! What is going on here?
Update: As discussed in the answer below, this seems to have been a bug in stack and should be fixed in newer versions. See https://github.com/fpco/minghc/issues/85.

A guess: you're using a GHC install that does not include documentation, or at least not as stack expects it to be discovered. Can you try with "--install-ghc --no-system-ghc"? I may have the specific flag names wrong.
Also, how is GHC installed on your system?

I solved this by installing the ghc-doc package (available in most package managers).

Related

How to resolve dependency tree with different version ranges of same packages?

I'm trying to set up a happstack-lite application using stack.
I initialized project with these commands:
stack new my-happstack
cd my-happstack
stack setup
I changed package.yaml so it contains:
dependencies:
- base >= 4.7 && < 5
- happstack-lite >= 7.3
Then I ran stack build several times and changed extra-deps in stack.yaml in project directory according to recommendations (added dependencies, such as happstack-server).
Apparently, I was asked to add to extra-deps the packages already listed there, with different version bounds and one with the same (template-haskell-2.11.1.0):
stack.yaml content:
extra-deps:
- happstack-lite-7.3.6
- happstack-server-7.4.6.4
- Win32-2.2.2.0#sha256:10ed55dd31315f386910c121c1d1d442df83bd2ee92090a753cd65300735a8ca
- network-2.6.3.6#sha256:1ca79d81af02d7acd6032d5e6c9bde4618a8fdcfbe19bd42b49d420183975df0
- template-haskell-2.11.1.0#sha256:f90d6ab73ad35c749e8547ca132e7ab5d32d2f8e7bb2e2ff6d597be26b58e061
- transformers-compat-0.5.1.4#sha256:1b4bfa8589afb1ca0e719129ab261bd90ef0cc3e6c0b9963f94970c082b61250
output from stack build:
F:\Projects\Haskell\my-happstack>stack build
Error: While constructing the build plan, the following exceptions were encountered:
In the dependencies for Cabal-2.4.1.0:
Win32-2.2.2.0 from stack configuration does not match >=2.3.0.0 && <2.9 (latest matching
version is 2.8.3.0)
needed due to my-happstack-0.1.0.0 -> Cabal-2.4.1.0
In the dependencies for happstack-server-7.4.6.4:
template-haskell-2.14.0.0 from stack configuration does not match <2.12 (latest matching
version is 2.11.1.0)
needed due to my-happstack-0.1.0.0 -> happstack-server-7.4.6.4
In the dependencies for transformers-base-0.4.5.2:
transformers-compat-0.5.1.4 from stack configuration does not match >=0.6.1 (latest matching
version is 0.6.4)
needed due to my-happstack-0.1.0.0 -> transformers-base-0.4.5.2
Some different approaches to resolving this:
* Set 'allow-newer: true' in C:\sr\config.yaml to ignore all version constraints and build anyway.
* Consider trying 'stack solver', which uses the cabal-install solver to attempt to find some
working build configuration. This can be convenient when dealing with many complicated
constraint errors, but results may be unpredictable.
* Recommended action: try adding the following to your extra-deps
in F:\Projects\Haskell\my-happstack\stack.yaml:
Win32-2.8.3.0#sha256:58fa6f52e8a0d455a74bb19445c177f2cc79a0975cae5fd96e2334bd38a516d4
template-haskell-2.11.1.0#sha256:f90d6ab73ad35c749e8547ca132e7ab5d32d2f8e7bb2e2ff6d597be26b58e061
transformers-compat-0.6.4#sha256:d298cd9d1bb7b05160229e244436bae825b53660865e3d5fd695ea0fafec1e6f
Plan construction failed.
I've tried these steps:
1) Set 'allow-newer: true' in C:\sr\config.yaml. In this case, I'm getting error about wrong types usage from inside one of the dependent packages (can paste error output upon request, if needed).
2) Run stack solver. I've got the error from cabal planner (error output upon request).
So, I expect stack to resolve dependencies the way npm does - each package dependencies are resolved independently from other's packages needs. Any advice of how I can solve this particular problem will be helpful, though (including manual dependencies resolving).

Haskell dependency hell

I'm trying to include a specific version of a library in a Haskell project. The library is bed-and-breakfast (which is used for martix operations), but I need the specific version 0.4.3 which fixed a bug with the multiplication implementation.
So, my stack.yaml looks like this:
flags: {}
extra-package-dbs: []
packages:
- .
extra-deps:
- bed-and-breakfast-0.4
- base-4.6.0.1
resolver: lts-12.8
But I'm getting this error when building:
Error: While constructing the build plan, the following exceptions were encountered:
In the dependencies for bed-and-breakfast-0.4:
base-4.11.1.0 from stack configuration does not match >=4.5 && <4.7 (latest matching version
is 4.6.0.1)
needed due to realworldhaskell-0.1.0.0 -> bed-and-breakfast-0.4
Some different approaches to resolving this:
* Set 'allow-newer: true' to ignore all version constraints and build anyway.
* Consider trying 'stack solver', which uses the cabal-install solver to attempt to find some
working build configuration. This can be convenient when dealing with many complicated
constraint errors, but results may be unpredictable.
* Recommended action: try adding the following to your extra-deps
in C:\Users\info\Desktop\Projects\haskell\stack.yaml:
- base-4.6.0.1
I've done the recommended action but it didn't solve anything. I've tried using different resolvers to see if it's an issue with my GHCi version but nothings worked. What is the best way to interpret error messages like this and how should I proceed?
EDIT:
If I remove -base.4.6.0.1 and add allow-newer: true I get this:
WARNING: Ignoring out of range dependency (allow-newer enabled): base-4.11.1.0. bed-and-breakfast requires: >=4.5 && <4.7
bed-and-breakfast-0.4: configure
Progress 1/2
-- While building custom Setup.hs for package bed-and-breakfast-0.4 using:
C:\sr\setup-exe-cache\x86_64-windows\Cabal-simple_Z6RU0evB_2.2.0.1_ghc-8.4.3.exe --builddir=.stack-work\dist\7d103d30 configure --with-ghc=C:\Users\info\AppData\Local\Programs\stack\x86_64-windows\ghc-8.4.3\bin\ghc.EXE --with-g
hc-pkg=C:\Users\info\AppData\Local\Programs\stack\x86_64-windows\ghc-8.4.3\bin\ghc-pkg.EXE --user --package-db=clear --package-db=global --package-db=C:\sr\snapshots\76fd1958\pkgdb --package-db=C:\Users\info\Desktop\Projects\haskell\
.stack-work\install\8c390635\pkgdb --libdir=C:\Users\info\Desktop\Projects\haskell\.stack-work\install\8c390635\lib --bindir=C:\Users\info\Desktop\Projects\haskell\.stack-work\install\8c390635\bin --datadir=C:\Users\info\Desktop\Proj
ects\haskell\.stack-work\install\8c390635\share --libexecdir=C:\Users\info\Desktop\Projects\haskell\.stack-work\install\8c390635\libexec --sysconfdir=C:\Users\info\Desktop\Projects\haskell\.stack-work\install\8c390635\etc --docdir=C:
\Users\info\Desktop\Projects\haskell\.stack-work\install\8c390635\doc\bed-and-breakfast-0.4 --htmldir=C:\Users\info\Desktop\Projects\haskell\.stack-work\install\8c390635\doc\bed-and-breakfast-0.4 --haddockdir=C:\Users\info\Desktop\Pr
ojects\haskell\.stack-work\install\8c390635\doc\bed-and-breakfast-0.4 --dependency=array=array-0.5.2.0 --dependency=base=base-4.11.1.0 --dependency=binary=binary-0.8.5.1 --dependency=deepseq=deepseq-1.4.3.0 --dependency=template-hask
ell=template-haskell-2.13.0.0 --extra-include-dirs=C:\Users\info\AppData\Local\Programs\stack\x86_64-windows\msys2-20150512\mingw64\include --extra-lib-dirs=C:\Users\info\AppData\Local\Programs\stack\x86_64-windows\msys2-20150512\min
gw64\bin --extra-lib-dirs=C:\Users\info\AppData\Local\Programs\stack\x86_64-windows\msys2-20150512\mingw64\lib --exact-configuration
Process exited with code: ExitFailure 1
Logs have been written to: C:\Users\info\Desktop\Projects\haskell\.stack-work\logs\bed-and-breakfast-0.4.log
Configuring bed-and-breakfast-0.4...
Cabal-simple_Z6RU0evB_2.2.0.1_ghc-8.4.3.exe: The package has an impossible
version range for a dependency on an internal library: bed-and-breakfast
==0.3.2. This version range does not include the current package, and must be
removed as the current package's library will always be used.
EDIT 2:
Ok, so I'm guessing that the bed-and-breakfast library needs base 4.11.1.0 which is included in GHCi 6.10.2 (according to https://wiki.haskell.org/Base_package) so I need a resolver which matches that GHCi version. Where can I find out what resolver version that is?
Here is the constraint on the latest available bed-and-breakfast package: base (>=4.5 && <4.7), which means it will likely not even compile with GHC version higher then 7.6. Considering that there is even no LTS snapshot prior to GHC 7.8, you are out of luck with that package.
To say it in another words, the package is outdated and your choices are:
submit an issue and hope maintainer will do something about it
try to make it work with newer ghc yourself
Use a different package

Stack won't resolve a 'hidden' dependency

I am working on my first major Haskell application, and want to add mockery to create disposable test WAI threads. Importing mockery and running stack test resulted in the compiler error:
Failed to load interface for ‘Test.Mockery.Directory’
It is a member of the hidden package ‘mockery-0.3.5’.
Perhaps you need to add ‘mockery’ to the build-depends in your .cabal file.
Use -v to see a list of the files searched for.
So, I added mockery to my cabal file under test dependencies. However, when I run stack build or stack test mockery is automatically removed from the cabal file.
I have also tried listing mockery-0.3.5 under extra-deps in the stack.yaml file. This unsurprisingly didn't work, since mockery is part of my lts, and extra deps is for packages outside of lts.
How can I get stack to recognize that mockery should be included as a dependency to to project?
Here is my stack.yaml:
flags: {}
ghc-options:
! '*': -Wall
packages:
- .
extra-deps: [
]
resolver: lts-9.5
I'm using stack version 1.5.1
I imagine this is a stupid build issue and look forward to confronting my obvious oversight.
In stack.yaml you declare the Stackage LTS version, a curated list of hackage dependencies that you want to depend on. You can also depend on local packages and packages in git that are not in Hackage. You may also change the versions of the packages in LTS as long as they respect the constraints of the other dependencies.
package.yaml is the build file. Any packages you want to import directly in your Haskell code must be declared in here as dependencies, even if they are explicitly declared in the stack.yaml.
Finally, when you see It is a member of the hidden package, that means that one of your dependencies is using that package, but it is not declared as a dependency in your build file.

"Failure installing dependencies" when installing Helm with Stack

I am currently trying to install helm with stack. I created a simple project with
stack new sandbox
and added helm as a dependency on sandbox.cabal:
library
hs-source-dirs: src
exposed-modules: Lib
build-depends: base >= 4.7 && < 5
, helm
default-language: Haskell2010
After that I run the usual stack build and get the error, indicating that I have to add helm-0.7.1 on my stack.yaml file. I do that and also insert elerea-2.8.0, since it was also a requirement.
This is my stack.yaml:
# Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2)
resolver: lts-3.12
# Local packages, usually specified by relative directory name
packages:
- '.'
# Packages to be pulled from upstream that are not in the resolver (e.g., acme-missiles-0.3)
extra-deps:
- helm-0.7.1
- elerea-2.8.0
# Override default flag values for local packages and extra-deps
flags: {}
# Extra package databases containing global packages
extra-package-dbs: []
# Control whether we use the GHC we find on the path
# system-ghc: true
# Require a specific version of stack, using version ranges
# require-stack-version: -any # Default
# require-stack-version: >= 0.1.4.0
# Override the architecture used by stack, especially useful on Windows
# arch: i386
# arch: x86_64
# Extra directories used by stack for building
# extra-include-dirs: [/path/to/dir]
# extra-lib-dirs: [/path/to/dir]
Running stack build again gives me this error.
While constructing the BuildPlan the following exceptions were encountered:
-- Failure when adding dependencies:
helm: needed (-any), couldn't resolve its dependencies
needed for package: sandbox-0.1.0.0
-- Failure when adding dependencies:
cairo: needed (>0.12 && <0.13), 0.13.1.0 found (latest version available)
mtl: needed (>=2.1 && <2.2), 2.2.1 found (latest version available)
pango: needed (>0.12 && <0.13), 0.13.1.0 found (latest version available)
sdl2: needed (>=1.1 && <1.3), 1.3.1 found (latest is 2.1.0)
time: needed (>=1.4 && <1.5), 1.5.0.1 found (latest version available)
needed for package: helm-0.7.1
What does this error mean? From what I understand it is not finding the correct version.
What it's saying is that the stackage resolver you are trying to use (lts-3.12) is incompatible with helm-0.7.1.
For instance, helm-0.7.1 requires a cairo version between 0.12 and 0.13, but the version of cairo supported in lts-3.12 is 0.13.1. Similarly for the other constraints.
It is possible that the helm might actually work with a later version of cairo. To test that, download the helm source, modify the dependency in its cabal file and include it in your stack project as a local package.
Another suggestion is to see if it builds in a cabal sandbox.

How to install a package using stack?

Using cabal, I could install hakyll with the command:
cabal install hakyll
How can I do the same thing using stack?
stack install hakyll
stack offers a curated set of packages that won't blow your machine up. If you want to check what packages are available, or exactly what version is supported, or on what version of GHC you can get it, check out https://www.stackage.org/.
For example, you can get hakyll 4.6.9.0 right now for both GHC 7.8.4 and GHC 7.10.1. Pretty neat. - source
EDIT: I forgot to mention, Yuan Wang's method works for getting the version of hakyll that is not curated into stackage. It's up to you what version you need.
add hakyll in stack.yaml generated by stack init or stack new
yaml file should look like:
flags: {}
packages:
- '.'
extra-deps:
- hakyll-4.7.1.0
resolver: lts-2.15
after that, run stack solver installs it
https://github.com/commercialhaskell/stack/wiki/stack.yaml
This documentation worked for me
On package.yaml add the library under dependencies, for example:
dependencies:
- base >= 4.7 && < 5
- hakyll # added here

Resources