How to turn all pedantic mode for hie in haskell? - 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.

Related

stack setup won't recognize changes in .cabal file

I've added "QuickCheck" to the "build depends" section of the .cabal file but when I do stack setup the "QuickCheck" section of the file gets removed and I get this error:
It is a member of the hidden package ‘Cabal-3.2.1.0’.
You can run ‘:set -package Cabal’ to expose it.
(Note: this unloads all the modules in the current scope.)
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
1 | import Distribution.Simple
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
the stack build and stack ghci work fine but stack test gives this error:
Could not find module ‘Test.QuickCheck’
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
3 | import Test.QuickCheck
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Progress 1/2
-- While building package palindrome-testing-0.1.0.0 (scroll up to its section to see the error) using:
/Users/artin/.stack/setup-exe-cache/aarch64-osx/Cabal-simple_mPHDZzAJ_3.2.1.0_ghc-8.10.7 --builddir=.stack-work/dist/aarch64-osx/Cabal-3.2.1.0 build lib:palindrome-testing exe:palindrome-testing-exe test:palindrome-testing-test --ghc-options " -fdiagnostics-color=always"
Process exited with code: ExitFailure 1
.cabal file:
cabal-version: 1.12
-- This file has been generated from package.yaml by hpack version 0.34.6.
--
-- see: https://github.com/sol/hpack
name: palindrome-testing
version: 0.1.0.0
description: Please see the README on GitHub at <https://github.com/githubuser/palindrome-testing#readme>
homepage: https://github.com/githubuser/palindrome-testing#readme
bug-reports: https://github.com/githubuser/palindrome-testing/issues
author: Author name here
maintainer: example#example.com
copyright: 2022 Author name here
license: BSD3
license-file: LICENSE
build-type: Simple
extra-source-files:
README.md
ChangeLog.md
source-repository head
type: git
location: https://github.com/githubuser/palindrome-testing
library
exposed-modules:
Lib
other-modules:
Paths_palindrome_testing
hs-source-dirs:
src
build-depends:
base >=4.7 && <5
default-language: Haskell2010
executable palindrome-testing-exe
main-is: Main.hs
other-modules:
Paths_palindrome_testing
hs-source-dirs:
app
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, palindrome-testing
default-language: Haskell2010
test-suite palindrome-testing-test
type: exitcode-stdio-1.0
main-is: Spec.hs
other-modules:
Paths_palindrome_testing
hs-source-dirs:
test
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, palindrome-testing
, QuickCheck
default-language: Haskell2010
ghc version: 8.10.7
stack version: 2.7.4
cabal version: 3.6.2
I'm running macOS monterey on M1
Your cabal file was generated from the package.yaml file in that directory:
-- This file has been generated from package.yaml by hpack version 0.34.6.
--
-- see: https://github.com/sol/hpack
If you want to add new dependencies, add them to package.yaml. Any changes you make to the .cabal file will get overridden.

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.

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.

How to add dependencies and make it visible to Intero in Haskell

I want to use System.Directory in emacs with Haskell mode and Intero, While the on the fly check warns that Couldn't find module System.Directory. So I add some dependencies in my cabal file. And the warning doesn't disappear while the stack build successfully executed.
Below is my cabal file:
-- This file has been generated from package.yaml by hpack version 0.28.2.
--
-- see: https://github.com/sol/hpack
--
-- hash: 536b5f6ecaaec7d4b7a9694c8f69bbe648a1d21d80fa721e533ac5b139955401
name: find
version: 0.1.0.0
description: Please see the README on GitHub at <https://github.com/Handora/find#readme>
homepage: https://github.com/Handora/find#readme
bug-reports: https://github.com/Handora/find/issues
author: Handora
maintainer: qcdsr970209#gmail.com
copyright: Qian Chen
license: BSD3
license-file: LICENSE
build-type: Simple
cabal-version: >= 1.10
extra-source-files:
ChangeLog.md
README.md
source-repository head
type: git
location: https://github.com/Handora/find
library
exposed-modules:
Lib
RecursiveContents
other-modules:
Paths_find
hs-source-dirs:
src
build-depends:
base >=4.7 && <5
, directory
default-language: Haskell2010
executable find-exe
main-is: Main.hs
other-modules:
Paths_find
hs-source-dirs:
app
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, find
, directory
default-language: Haskell2010
test-suite find-test
type: exitcode-stdio-1.0
main-is: Spec.hs
other-modules:
Paths_find
hs-source-dirs:
test
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, find
default-language: Haskell2010
I add the directory into build dependencies and executable build dependencies. So my question is how to make the System.Directory visible to Intero, so the warnings can disappear.
You can get it to show up by running intero-restart.
There may be a "more correct" way, but this works.

Profiling library via executable in cabal

Silly question. I have a cabal file with a library and an executable that I would like to use to profile the library, but I can't manage to see cost centers from my library (although I see some from other modules like GHC.IO.Encoding).
Here's a simplified version of my cabal file
flag dev
default: False
manual: True
library
exposed-modules: Foo
ghc-options: -Wall
ghc-prof-options: -fprof-auto
build-depends: base
executable dev-example
if !flag(dev)
buildable: False
ghc-options: -ddump-to-file -ddump-simpl -dsuppress-module-prefixes -dsuppress-uniques -ddump-core-stats -ddump-inlinings
ghc-options: -O2 -rtsopts
ghc-prof-options: -fprof-auto
hs-source-dirs: dev-example, ./
main-is: Main.hs
build-depends: base
Where I've been doing
$ cabal configure -fdev -w /usr/local/bin/ghc-7.6.3 --enable-library-profiling --enable-executable-profiling
$ cabal run dev-example -- +RTS -h -p
Ugh, the issue was simply that my library code was being inlined (or at least marked INLINABLE).

Resources