cannot satisfy -package yesod-1.6.0 - haskell

I am trying to create a hello world yesod web application and encounter the error message
cannot satisfy -package yesod-1.6.0
What I've done is, create a project with stack new yeplay and then in the package.yaml file I put, yesod in the dependencies section, that looks as following:
executables:
yeplay-exe:
main: Main.hs
source-dirs: app
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- yeplay
- yesod
What am I doing wrong?

Related

Force static compilation in stack

I use stack with multiple projects, I need to have two ways to compile them a "normal one" for the day-to-day development and one for the deployment.
I use hpack and my projects look like that:
name: test
version: 0.1.0
github: "th/ng"
author: "Me"
description: Ok
dependencies:
- base >= 4.7 && < 5
executables:
test-bootstrap:
main: Main.hs
source-dirs: app
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
For my deployments I need to configure them as following:
executables:
test-bootstrap:
main: Main.hs
source-dirs: app
cc-options: -static
ld-options: -static -pthread
extra-lib-dirs: ./.system-work/lib
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
- -static
Which forces me to run with stack build --docker.
I have tried to leverage stack build --ghc-options "-static"
But I have an horrible trace:
test > /usr/bin/ld.gold: error: /home/stackage/.stack/programs/x86_64-linux/ghc-8.8.3/lib/ghc-8.8.3/ghc-prim-0.5.3/libHSghc-prim-0.5.3.a(Classes.o): requires unsupported dynamic reloc 11; recompile with -fPIC
Is there a way to give cc-options and ld-options to stack, or to have multi-projects flags?
I have leveraged the Yaml include mechanism, here is my flags.yaml for static compilation:
- &deployed_exe
cc-options: -static
ld-options: -static -pthread
extra-lib-dirs: ./.system-work/lib
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
- -static
And my package.yamls:
_flags: !include "../flags.yaml"
executables:
test-bootstrap:
<<: *deployed_exe
main: Main.hs
source-dirs: app
I have a symbolic link I switch depending of my needs.

How to turn all pedantic mode for hie in haskell?

Is it possible to somehow pass --pedantic (as in stack build --pedantic) switch to Haskell-ide-engine? I'd like to see more errors in IDE during compile time as I'm very new to the language, for example for non-exhaustive case patterns.
I cannot find any infos on project page apart from this bug https://github.com/haskell/haskell-ide-engine/issues/449 but this does not seem to adress this issue.
So far as I can tell it is not possible to pass compiler or build tool switches in to HIE. HIE automatically determines your compiler flags based on your build tool and does not have an override mechanism.
Instead you should add the appropriate compiler flags to your build file. stack build --pedantic passes the -Wall and -Werror flags, so those are the flags you want to add to your build file. That way the flags will always be used by both stack build and HIE.
package.yaml
If you have a package.yaml file (the default for most Stack projects) then you should add the following lines to the ghc-options section of that file:
- -Wall
- -Werror
Example:
name: project-name
version: 0.1.0.0
github: "githubuser/project-name"
license: BSD3
author: "Author name here"
maintainer: "example#example.com"
copyright: "2020 Author name here"
description: Example
dependencies:
- base >= 4.7 && < 5
ghc-options:
- -Wall
- -Werror
executables:
project-name-exe:
main: Main.hs
source-dirs: app
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
package-name.cabal
If you do not have a package.yaml file, then add the following lines to all of the executable and library sections your cabal file:
ghc-options:
-Wall
-Werror
Example:
name: project-name
version: 0.1.0.0
-- synopsis:
-- description:
homepage: https://github.com/githubuser/project-name#readme
license: BSD3
license-file: LICENSE
author: Author name here
maintainer: example#example.com
copyright: 2020 Author name here
category: Web
build-type: Simple
cabal-version: >=1.10
extra-source-files: README.md
executable project-name
hs-source-dirs: src
main-is: Main.hs
default-language: Haskell2010
build-depends: base >= 4.7 && < 5
ghc-options:
-Wall
-Werror
More flags
As a side note, GHC's -Wall does not enable all of the warnings, only most of them. You might want to add these extra warnings:
-Wcompat
-Wincomplete-uni-patterns
-Wincomplete-record-updates
-Wredundant-constraints
-Wpartial-fields
See https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/using-warnings.html for more details.
During development you might want to remove -Werror from your package.yaml or cabal file.

Haskell stack ignores -Wall -Werror cabal ghc-options flags when building

I would like to always use the "-Wall -Werror" options when building with stack (executing stack build) but adding these flags to ghc-options in package.yaml does nothing. I would also like to avoid passing the --pedantic flag to stack build. Here's the config files:
package.yaml
...
executables:
XYZ-exe:
main: Main.hs
source-dirs: app
ghc-options:
- -Wall
- -Werror
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- XYZ
...
XYZ.cabal
...
executable XYZ-exe
main-is: Main.hs
hs-source-dirs:
app
ghc-options: -Wall -Werror -threaded -rtsopts -with-rtsopts=-N
...
The "-Wall -Werror" flags are specified in ghc-options but as-if ignored when building. This is the output for stack build:
stack build
Building all executables for `XYZ' once. After a successful build of all of
them, only specified executables will be rebuilt.
XYZ-0.1.0.0: configure (lib + exe)
Configuring XYZ-0.1.0.0...
XYZ-0.1.0.0: build (lib + exe)
Preprocessing library for XYZ-0.1.0.0..
Building library for XYZ-0.1.0.0..
[ 1 of 105] Compiling Data.List.Extras ( src\Data\List\Extras.hs, .stack-
work\dist\e626a42b\build\Data\List\Extras.o )
... the rest is omitted, all succeed ...
And here's the output for stack build --pedantic
stack build --pedantic
Building all executables for `HStat' once. After a successful build of all of them, only specified executables will be rebuilt.
HStat-0.1.0.0: configure (lib + exe)
Configuring HStat-0.1.0.0...
HStat-0.1.0.0: build (lib + exe)
Preprocessing library for HStat-0.1.0.0..
Building library for HStat-0.1.0.0..
[ 1 of 105] Compiling Data.List.Extras ( src\Data\List\Extras.hs, .stack-work\dist\e626a42b\build\Data\List\Extras.o )
src\Data\List\Extras.hs:4:1: error: [-Wunused-imports, -Werror=unused-imports]
The import of ‘Data.Maybe’ is redundant
except perhaps to import instances from ‘Data.Maybe’
To import instances alone, use: import Data.Maybe()
|
4 | import Data.Maybe
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
This works as expected - src\Data\List\Extras.hs indeed does have an unused Data.Maybe import. What am I doing wrong?
The ghc-options flags had to be separately defined in the library part of package.yaml:
library:
source-dirs: src
ghc-options:
- -Wall
- -Werror
- -fwarn-incomplete-uni-patterns
Doing that solved the issue.

Two executables in one cabal file; stack build does not recognize them

I'm trying to make 2 executables "project". All duplicates of this question did not help me - their answers don't fix my problem. I have .cabal file like this:
name: int-tests
version: 0.1.0.0
synopsis: Integration Tests Suite
description: Integration Tests Suite
license: AllRightsReserved
author: Author name here
maintainer: example#example.com
copyright: 2018 Author name here
build-type: Custom
extra-source-files: README.md
cabal-version: >=1.10
library
hs-source-dirs: common
exposed-modules: Common
build-depends: base
, text
, aeson
, network-uri
default-language: Haskell2010
ghc-options: -Wall -Werror
executable api-tests-exe
hs-source-dirs: api
main-is: Main.hs
ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall -Werror
build-depends: base
, hspec
, QuickCheck
default-language: Haskell2010
executable e2e-tests-exe
hs-source-dirs: e2e
main-is: Main.hs
ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall -Werror
build-depends: base
, hspec
, QuickCheck
default-language: Haskell2010
and when I call stack ide targets I don't see these 2 targets. So, stack build api-tests and stack build e2e-tests don't work too.
How can I create 2 targets' project for stack? I tried also package.yaml but result is the same. Stack version is 1.9.1. I have folders tree like:
api/
...
e2e/
...
where are Main.hs files with content like:
module Main (main) where
main :: IO ()
main = print "Hello"
Also I tried option -main-is Main but without success.
Error looks like:
Error: While constructing the build plan, the following exceptions were encountered:
Unknown package: api-tests
AFAIK, stack build always builds all your targets. But if you want to be run just one executable, you'll need the full name including the -exe. So, stack exec api-tests-exe and stack exec e2e-tests-exe.
But what you really want to do is make these test targets: https://www.haskell.org/cabal/users-guide/developing-packages.html#test-suites
Problem was in stack.yaml file, I had to add '.' folder to "packages:" section.

Adding Dependency to stack Project?

After running:
stack new my-project
cd my-project
stack setup
stack build
I would like to add the Conduit library as a dependency.
I edited the generated, via stack new, stack.yaml to have:
extra-deps:
- conduit-1.2.10
Then, I modified the my-project.cabal from:
executable my-project-exe
hs-source-dirs: app
main-is: Main.hs
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends: base
, my-project
default-language: Haskell2010
to:
executable my-project-exe
hs-source-dirs: app
main-is: Main.hs
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends: base
, my-project
, conduit
default-language: Haskell2010
When I try to stack build the following:
$cat app/Main.hs
module Main where
import Conduit
import Lib
main :: IO ()
main = someFunc
It fails:
$stack build
mtl-2.2.1: using precompiled package
primitive-0.6.1.0: using precompiled package
stm-2.4.4.1: using precompiled package
transformers-compat-0.5.1.4: using precompiled package
exceptions-0.8.3: using precompiled package
mmorph-1.0.9: using precompiled package
transformers-base-0.4.4: using precompiled package
monad-control-1.0.1.0: using precompiled package
lifted-base-0.2.3.10: using precompiled package
resourcet-1.1.9: using precompiled package
conduit-1.2.10: configure
conduit-1.2.10: build
conduit-1.2.10: copy/register
my-project-0.1.0.0: configure (lib + exe)
Configuring my-project-0.1.0.0...
my-project-0.1.0.0: build (lib + exe)
Preprocessing library my-project-0.1.0.0...
[1 of 1] Compiling Lib ( src/Lib.hs, .stack-work/dist/x86_64-osx/Cabal-1.24.2.0/build/Lib.o )
Preprocessing executable 'my-project-exe' for my-project-0.1.0.0...
[1 of 1] Compiling Main ( app/Main.hs, .stack-work/dist/x86_64-osx/Cabal-1.24.2.0/build/my-project-exe/my-project-exe-tmp/Main.o )
/Users/kevinmeredith/Workspace/conduit_sandbox/my-project/app/Main.hs:3:1: error:
Failed to load interface for ‘Conduit’
Use -v to see a list of the files searched for.
Completed 12 action(s).
-- While building package my-project-0.1.0.0 using:
/Users/kevinmeredith/.stack/setup-exe-cache/x86_64-osx/Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 --builddir=.stack-work/dist/x86_64-osx/Cabal-1.24.2.0 build lib:my-project exe:my-project-exe --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1
How can I properly add conduit?
When adding a library to a stack project, do I need to edit both the stack.yaml and/or my-project.cabal?
If you look at the haddocks for conduit, notice the module you want to import is not Conduit, it is Data.Conduit.
The Conduit module comes from the conduit-combinators package. If that is the package you would like to use instead, adjust your cabal file as follows and import Conduit as before:
executable my-project-exe
hs-source-dirs: app
main-is: Main.hs
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends: base
, my-project
, conduit-combinators
default-language: Haskell2010
The differences between the packages are summarized below (this is taken from the project's readme).
conduit-combinators: provides a large number of common functions built-in
conduit: defines the core datatypes and primitive functions
conduit-extra: adds support for many common low-level operations
Side note: You don't need to make any changes to your stack.yaml file as both of these packages are available on stackage.

Resources