Failure to install hsev on Windows 10 via `stack install hsdev` - haskell

I get this error when running stack install hsdev outside and inside of a project:
λ stack install hsdev
Run from outside a project, using implicit global project config
Using resolver: lts-5.11 from implicit global project's config file: C:\Users\atc\AppData\Roaming\stack\global-project\stack.yaml
While constructing the BuildPlan the following exceptions were encountered:
-- While attempting to add dependency,
Could not find package hformat in known packages
-- Failure when adding dependencies:
hformat: needed (>=0.1), stack configuration has no specified version (latest applicable is 0.1.0.0)
simple-log: needed (>=0.3.4), stack configuration has no specified version (latest applicable is 0.3.4)
text-region: needed (>=0.1), stack configuration has no specified version (latest applicable is 0.1.0.0)
needed for package hsdev-0.1.8.2
-- While attempting to add dependency,
Could not find package simple-log in known packages
-- While attempting to add dependency,
Could not find package text-region in known packages
Recommended action: try adding the following to your extra-deps in C:\Users\atc\AppData\Roaming\stack\global-project\stack.yaml
- hformat-0.1.0.0
- simple-log-0.3.4
- text-region-0.1.0.0
I have run stack update prior to attempting this. I want to install hsdev so I can use SublimeHaskell.
stack solver gives:
λ stack solver
Run from outside a project, using implicit global project config
Using resolver: lts-5.11 from implicit global project's config file: C:\Users\atc\AppData\Roaming\stack\global-project\stack.yaml
Using configuration file: AppData\Roaming\stack\global-project\stack.yaml
The following packages are missing from the config:
<snip long list of references to directories in AppData\Local\Temp\stack14228\>
No cabal packages found in AppData\Roaming\stack\global-project\stack.yaml. Please add at least one directory containing a .cabal file. You can also use 'stack init' to automatically generate the config file.
Relevant stack info:
λ stack --version
Version 1.0.4, Git revision cf18703b1392a96a5a4896a560309e501af63260 (3220 commits) x86_6

I got hsdev installed on my windows machine by the following steps.
Run stack unpack hsdev to download the source of hsdev to the working directory.
Move into the directory, run stack init --solver to create a proper stack.yaml build config.
Run stack install to build and copy the executables to your local bin directory. If stack reports an error about a missing LICENSE file create an empty LICENSE file under ./tests/test-package.

Related

Which stackage snapshot does stack install use?

Trying to run
stack install git-mediate
(per git-mediate's instructions)
I get an error message regarding dependent package versions:
Error: While constructing the build plan, the following exceptions were encountered:
In the dependencies for git-mediate-1.0.8:
Diff-0.3.4 from stack configuration does not match >=0.4 (latest matching version is 0.4.0)
needed since git-mediate is a build target.
Some different approaches to resolving this:
* Set 'allow-newer: true' in /Users/yairchu/.stack/config.yaml to ignore all version constraints and build anyway.
* Recommended action: try adding the following to your extra-deps in /Users/yairchu/.stack/global-project/stack.yaml:
- Diff-0.4.0#sha256:b5cfbeed498f555a18774ffd549bbeff7a24bdfe5984154dcfc9f4328a3c2847,1275
Plan construction failed.
It's odd that the stack configuration has Diff-0.3.4, as currently both LTS and nightly stackage snapshots currently contain Diff-0.4.0 (lts-16.8 and nightly-2020-10-13).
What is this stack configuration thing and why is it pinned to old versions of libraries?
stack install is an alias for stack build --copy-bins, so it's really just stack build plus the additional step of copying the built executables to ~/.local/bin.
So, the real question is "how does stack build decide what resolver to use?" Well, if you provide it on the command line, it uses that one, as in:
stack install --resolver lts-16.18 git-mediate
If you don't give an explicit resolver, the default depends on where the build command is run. If you run it inside a stack project, it'll default to the resolver specified in the project's stack.yaml file. For example:
stack new --resolver lts-16.0 exampleproject # create project with lts-16.0 resolver
cd exampleproject
stack build git-mediate # this will build git-mediate using lts-16.0
If you build it outside of any project, then it uses the global project setting, which will be whatever resolver is set in ~/.stack/global-project/stack.yaml, as mentioned in the comments / other answer.
Note that the stack install alias will always copy the executable into the "global" ~/.local/bin, regardless of where it was built. So, if you run stack install git-mediate in the exampleproject directory, as above, you'll get the version built with lts-16.0 as the globally installed version.
Soooo... be careful where you run stack install!
Note that, with respect to git-mediate specfically, there was recently a buggy version published to Stackage, as documented here. The error message is slightly different than the one you got, but the underlying problem might have been the same. So, it's possible that just running stack update without having to modify the resolver setting would work to fix your build problem, if you haven't already fixed it.
stack is implicitly using it's "global project" defined in ~/.stack/global-project/stack.yaml. To control the stackage snapshot being used this file can be edited (or just deleted to use the latest LTS)

Stack: 'hdevtools is a library dependency, but the package provides no library needed since my-app is a build target.'

I was trying to add hdevtools to my stack project, so I ran stack build hdevtools. The install seemed to work successfully, and my text editor stopped reporting imported libraries installed via stack (like aeson and tasty) as missing.
However, things went wrong when I added this line to the dependencies section of my package.yaml file:
- hdevtools >= 0.1 && < 1
And then tried to run stack build again. I received the following error output:
Error: While constructing the build plan, the following exceptions were encountered:
In the dependencies for my-app-name-0.1.0.0:
hdevtools is a library dependency, but the package provides no library
needed since my-app-name is a build target.
Some different approaches to resolving this:
* 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.
Plan construction failed.
I tried running stack solver, but that threw the exception documented here.
How can I declare hdevtools as a dependency of my project?
#alexis-king recommends using stack build --copy-compiler-tool hdevtools in this guide, in the section titled Setting up editor integration.
This works for the current project, and other projects using the same GHC version, but you will need to run it again when you upgrade to a new GHC version.
More context from King's guide:
As mentioned above, stack install is not what you want. Tools like ghc-mod, hlint, hoogle, weeder, and intero work best when installed as part of the sandbox, not globally, since that ensures they will match the current GHC version your project is using.
How can I declare hdevtools as a dependency of my project?
hdevtool is an executable and cabal doesn't have a concept of development dependencies (like in other package managers like npm etc). So, all you can do is install hdevtools globally and make it work.

Is there a declarative way to specify packages to be installed into global-project using Haskell stack?

Stack allows global installation of packages using stack install <packagename> outside of a project directory.
Stack also has a ~/.stack/global-project/stack.yaml file that allows configuration of the global-project. However I can't see a way to "install" packages declaratively. The extra-deps and packages key in the yaml file don't seem to work for this method.
Instead I just have to run stack install <...> <...> each time the snapshot version gets updated for my global-project.

Create hackage package that can be installed with stack

When running stack sdist in my project directory, the stack.yaml file isn't included in the tarball (this seems to be expected).
Consequently, when I upload the tarball to hackage, then stack install mypackage it complains about missing dependencies (extra-deps) which I specified in the stack.yaml file.
$ stack install pandoc-placetable
Run from outside a project, using implicit global project config
Using resolver: lts-5.17 from implicit global project's config file: ~/.stack/global-project/stack.yaml
While constructing the BuildPlan the following exceptions were encountered:
-- Failure when adding dependencies:
spreadsheet: needed (>=0.1.3 && <0.1.4), not present in build plan (latest applicable is 0.1.3.4)
needed for package: pandoc-placetable-0.4
-- While attempting to add dependency,
Could not find package spreadsheet in known packages
Recommended action: try adding the following to your extra-deps in /Users/maurobieg/.stack/global-project/stack.yaml
- spreadsheet-0.1.3.4
Or what's the recommended way to make a hackage package stack-installable if it has further hackage dependencies?
Update: I just added extra-source-files: stack.yaml to the cabal file and the stack.yaml is indeed included in the tarbal of the newly published version. Nevertheless, stack install pandoc-placetable-0.4.1 still comes up with the same error.
I could also just tell people who don't want to install cabal-install on their system to clone from GitHub, then build with stack. Is that the recommended approach for tiny packages? Or should I ask them to include the dependency of pandoc-placetable (i.e. spreadsheet) in their global stack.yaml? Smells like polluting a global file...
As mentioned by #mgsloan in the comments above: There's an open stack issue about using stack.yaml from hackage package.
I guess until it's fixed I'll just tell people to clone from GitHub (or as mentioned by #MichaelSnoyman to stack unpack) and then cd into the newly created directory and stack install there.

Prevent stack from recompiling external dependencies

I am relatively new to stack and haskell. Before I explain my question, let me explain our development setup. We use jenkins to build our repo. The haskell project will be a small subset of a larger python project. The haskell project is mainly used to generate artifacts.
The jenkins master does a git clean each time before building a git branch. My haskell project has some external dependency like argparser & aeson. Each time my build scripts execute a stack build, these external dependencies get compiled because they are deleted when jenkins executes the git clean command.
Is there anyway to tell stack to download the external deps to a global folder outside the project folder? Like the global-pkg-db path instead of the .stack-work folder? What is the best way to prevent stack to not recompile the external dependencies?
Should I download argparser & aeson into a custom folder and pass that path into extra-lib-dirs?
# This file was automatically generated by stack init
# For more information, see: http://docs.haskellstack.org/en/stable/yaml_configuration/
# Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2)
resolver: lts-5.8
# 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:
- aeson-0.11.1.1
- argparser-0.3.4
- text-1.2.2.0
# Override default flag values for local packages and extra-deps
flags: {}
# Extra package databases containing global packages
extra-package-dbs: []

Resources