Using local packages with Haskell Stack - haskell

Say I have two projects (project-a and project-b) and I wanted to include project-a into project-b without uploading project-a to stackage. How could I publish the package locally and include it into project-b like so?
# package.yaml for project-b
dependencies:
- base >= 4.7 && < 5
- project-a == 2.0.0.0

Special thanks to #arrowd for pointing me in the right direction. This is an answer to my question but if someone else has a better one I will accept it.
In project a run the command
> stack sdist
that will package your project up into a tarball and show you what directory it is in.
Then go to project b and add the following to the stack.yaml file under the extra-deps section
extra-deps:
- archive: /path/to/project-a/tar/file
and in your package.yaml file under dependencies
dependencies:
# other dependencies
- project-a == 2.0.0.0
then run
> stack build
and project-a will be included in project-b.

Related

Using a package that's not on Hackage

I am trying to use EuterpeaLite (https://github.com/Euterpea/EuterpeaLite), but it is not on Hackage.
I imported it like such import EuterpeaLite as EL and I added it to my cabal file like this:
build-depends:
base >=4.7 && <5
, postgresql-simple
, EuterpeaLite
But when I run stack build or stack ghci, I get this error:
Error: While constructing the build plan, the following exceptions were encountered:
In the dependencies for engine-0.1.0.0:
EuterpeaLite needed, but the stack configuration has no specified version (no package with that name found, perhaps there
is a typo in a package's build-depends or an omission from the stack.yaml packages list?)
needed since engine is a build target.
Some different approaches to resolving this:
Plan construction failed.
Is there a special process for non-Hackage packages?
I used the following procedure.
Create a new stack project stack new myproject --resolver=14.27. I needed to specify an older resolver, since EuterpeaLite wouldn't build with lts-15.3
In the myproject directory, add the following lines to stack.yaml:
extra-deps:
- git: https://github.com/Euterpea/EuterpeaLite.git
commit: 5fe2d129bd3087dd78c0feaf4d35fc03ffd36215
Also in the myproject directory, I added the following dependency to package.yaml:
dependencies:
- base >= 4.7 && < 5
- EuterpeaLite # <- added this line
Ran stack build in the myproject directory.
As you noted, instead of using package.yaml, you could change your .cabal file.

Getting error while using gtk2hs-buildtool library in Haskell project using Stack

I am trying to add dependency of gtk2hs-buildtool to my Haskell project but following error while building stack.
In the dependencies for TicTacToe-0.1.0.0:
gtk2hs-buildtools needed, but the stack configuration has no specified version (latest matching
version is 0.13.5.4)
needed since TicTacToe is a build target.
TicTacToe.cabal file:
library
exposed-modules:
TicTacToeEngine
other-modules:
Paths_TicTacToe
hs-source-dirs:
src
build-depends:
base >=4.7 && <5,
gtk2hs-buildtools
default-language: Haskell2010
If you are using stack tool you shouldn't touch the <packagename>.cabal file. stack is in charge to generate it from package.yaml. Despite of the fact that is a common practise to modify the <packagename>.cabal, development workflow will be easier if you don't.
The files you are interested in (and the ones that stack tool uses) are the stack.yaml and package.yaml.
In stack.yaml you should see an entry called resolver: lts-XX.XX. That means that your dependencies version are managed such that they match those in the given lts (a.k.a. snapshot). You can go to https://www.stackage.org/, click on your lts version and search for the gtk2hs-buildtools package to get the right version for your project (example: lts-12.26 uses gtk2hs-buildtools-0.13.4.0). In your package.yaml, in the dependencies section write the entry entry - gtk2hs-buildtools
From lts-13.11 and above gtk2hs-buildtools is not available in stackage, so you need to add it as an extra-dep. in the stack.yaml, in the section extra-dep add the following entry gtk2hs-buildtools-0.13.4.0 (or the version number you'd like to use). Then add in the package.yaml and entry gtk2hs-buildtools. It is necessary to add the entry in both files. Refer to stack docs o understand why.
Just to ensure you can build your project, your files should something look like the following:
if using resolver above or equal to 13.11
stack.yaml
resolver: lts-13.11
extra-deps:
- gtk2hs-buildtools-0.13.4.0
package.yaml
dependencies:
- base
- gtk2hs-buildtools
if using resolver below 13.11
stack.yaml
resolver: lts-12.26
extra-deps:
package.yaml
dependencies:
- base
- gtk2hs-buildtools

Cannot install z3 package for Haskell on Windows 10

I'm trying to install a project that uses the z3 package under Windows 10 and haskell stack with the following setup:
The z3 precompiled binaries (with includes under ./z3/includes and dll files under ./z3/bin) are located under the project root
myProject/
- app/
- dist/
- src/
- z3/
- package.yaml
- Setup.hs
- stack.yaml
- myProject.cabal
The package.yaml file contains:
dependencies:
- base >= 4.7 && < 5
- containers
- parsec
- z3 <= 408.0
The stack.yaml file contains:
extra-deps:
- z3-408.0#sha256:89bbc2d828dc1fe1f19666e8e501c69ce5d0ed8026e4a02f7eae1e69f4a352af
extra-include-dirs:
- ./z3/include
extra-lib-dirs:
- ./z3/lib
When I try to stack install I get the following error:
Process exited with code: ExitFailure 1
Logs have been written to: C:\Users\jmueller\repos\synthImp\.stack-work\logs\z3-408.0.log
z3-408.0: configure
Progress 1/2
-- While building package z3-408.0 using:
<...>
--extra-include-dirs=C:\Users\jmueller\repos\synthImp\./z3/include
<...>
--extra-lib-dirs=C:\Users\jmueller\repos\synthImp\./z3/lib
Configuring z3-408.0...
Cabal-simple_Z6RU0evB_2.4.0.1_ghc-8.6.5.exe: Missing dependency on a foreign
library:
* Missing (or bad) C library: z3
This problem can usually be solved by installing the system package that
provides this library (you may need the "-dev" version). If the library is
already installed but in a non-standard location then you can use the flags
--extra-include-dirs= and --extra-lib-dirs= to specify where it is.If the
library file does exist, it may contain errors that are caught by the C
compiler at the preprocessing stage. In this case you can re-run configure
with the verbosity flag -v3 to see the error messages.
The extra include and extra lib dirs are there and obviously the include is found too ... there seems to be a problem on the level of the c compiler
I tried both binaries for z3 (x64 and x86) and I don't know how to capture the output of the c preprocessor for further debugging.
Any help is highly appreciated!
Many thanks in advance

Cannot add extra-deps to Stack project

I'm trying to set up a Haskell project with Stack. I have created a project: stack new project1 and added the suggested dependency (acme-missile) just to see how it works.
extra-deps:
- acme-missiles-0.3
But when I try to invoke launchMissile in the Main it won't work. I get
Error:(3, 1) Could not find module ‘Acme.Missiles’
Use -v to see a list of the files searched for.
|
3 | import Acme.Missiles
| ^^^^^^^^^^^^^^^^^^^^
What is the problem? What am I missing?
EDIT
When I run stack solver I get this:
Using configuration file: stack.yaml
Using cabal packages:
- ./
The following changes will be made to stack.yaml:
* Dependencies to be deleted
extra-deps:
- acme-missiles-0.3
To automatically update stack.yaml, rerun with '--update-config'
Isn't that strange? Like it thinks my dependency is not needed?
You'll need to add the dependency to project1.cabal as well:
build-depends:
base >=4.7 && <5
, project1
, acme-missiles
Alternatively, on newer versions of Stack, it looks like you should use package.yaml instead:
dependencies:
- base >= 4.7 && < 5
- acme-missiles
I can't say that I have deep knowledge of how this works, but if I understand it correctly, the main file where you're supposed to add dependencies is in the .cabal or package.yaml file. The extra-deps field in stack.yaml is where you can indicate if you have dependencies that deviate from the LTS that you currently use.

Difference between new-template.cabal and stack.yaml

I want to use reactive-banana in my new Haskell project. I never used cabal-install or stack before. I created a directory and initialized project files in it using stack new. I see now 2 files in the directory: new-template.cabal and stack.yaml.
How do I set dependencies and make sure they are downloaded and compiled?
At first I tried to add - reactive-banana-0.8.0.2 in stack.yaml under extra-deps:, but both stack build and stack solver didn't download it. Then I augmented a part called library in new-template.cabal to this:
library
hs-source-dirs: src
exposed-modules: Lib
build-depends: base >= 4.7 && < 5
, reactive-banana >= 0.8
default-language: Haskell2010
Every time I tried to run stack build, it crashed with an error and suggestion to add some package to stack.yaml under extra-deps:, and this happened three times until finally all packages installed, and I could import them in stack ghci REPL.
So my question is, what is the idiomatic way to use stack? Which of these 2 files should I use to specify dependencies and other project metadata? What is the sample workflow of an average Haskell developer with stack?
When using stack I generally don't put any versions bounds in my .cabal file. I let the resolver and extra-deps setting in the stack.yaml file determine which versions of packages to select.
Here is a stack.yaml file which brings in reactive-banana-0.8.1.2:
flags: {}
packages:
- '.'
extra-deps:
- reactive-banana-0.8.1.2
- psqueues-0.2.0.2
resolver: lts-2.17
In my .cabal file I just have:
build-depends: base >= 4.7 && < 5, reactive-banana
The reactive-banana version is pinned by the stack.yaml file.
If you want to use GHC 7.10 change the resolver to something like nightly-2015-06-17.
I determine the extra-deps iteratively, by just running stack build and adding whatever dependencies are missing to the stack.yaml file until all dependencies are satisfied.
You will only need to do this with packages which are not in Stackage - like reactive-banana. A great many of commonly used packages are in Stackage and their versions will be determined by the resolver setting.
In the default configuration, stack works with two package databases: a centralised per-user one and a project-specific one. The centralised database only pulls packages from Stackage, a subset of Hackage with known-to-be-compatible packages, while you can put whatever you want on the project-specific database. All packages you use must be in the cabal file, but those not on Stackage (that is, the ones that will go to the project-specific database) must also be listed in the extra-deps section of stack.yaml. reactive-banana is not on Stackage, so you need to add it to stack.yaml, like this:
# etc.
extra-deps:
- reactive-banana-0.8.1.2
# etc.
stack solver can fill in the extra dependencies in stack.yaml for you.

Resources