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.
Related
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 it possible to install package from sources with something similar to stack build package-name? (latter works with packages on Stackage, but not with custom ones)
Um, stack build (within the source directory)?
Stack doesn't really have a notion of installing libraries though, it only installs executables. To “install” locally-sourced packages, you need to specify what for you want them installed: add them as dependencies to another project, via a location: field in the packages: field in that project's stack.yaml file.
That's arguably sensible since, one might say, there's nothing you can do with an installed library except invoking it in another Haskell project (or in a REPL, which you can get with stack ghci). I personally don't hold with that though, I like actually being able to say install that library now. Which is one of the reasons I have always stuck to good old cabal-install rather than Stack. With that, you can just
cabal install
from within the source directory.
Cabal-install has often been criticised: its local installs can easily get out of sync and then you have weird dependency conflicts and need to rebuild lots of stuff. I never found this that much of a problem, and anyway this has been adressed in recent Cabal through Nix-style builds, which never produce conflicts.
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.
I'm using the stack install command to save dependencies for a new project. How do I get it to save those dependencies into stack.yaml? Unless I'm missing something, I can't see where stack is recording the project dependencies and I can't seem to find anything in a docs about this.
You still keep your dependencies in a .cabal file. From the Stack FAQ:
A .cabal file is provided for each package, and defines all package-level metadata just like it does in the cabal-install world: modules, executables, test suites, etc. No change at all on this front.
A stack.yaml file references 1 or more packages, and provides information on where dependencies come from.
If you need additional versions of dependencies than the LTS Haskell snapshot you're using, you'll add them to the extra-deps portion of the stack.yaml file.
When trying to build an existing project with Stack I got errors like
bv not found
- Genesis requires >=0.3 && <0.4 && -any
- exp requires -any
during stack init. The packages are all installed in a sandbox and are from hackage. I'm almost sure Stack doesn't look into the sandbox, but why can't it find the packages from hackage? I'm also able to build just by running cabal build.
stack does not look at Hackage at first. It tries to build your project using only packages from a snapshot of Stackage (you can find the exact snapshot you are using in the resolver field of stack.yaml). bv does not seem to be in Stackage (at least it is not in the latest LTS snapshot). Fortunately, the issue is easy to solve: just run stack solver --modify-stack-yaml. That will identify all non-Stackage dependencies and add them to the extra-deps field of stack.yaml. From that point on, those dependencies will be built somewhere in the .stack-work subdirectory of your project, in a very similar way to packages in a cabal-install sandbox.