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).
Related
Hi I have the following modules in cabal file:
library task1-lib
exposed-modules:
Interpreter,
Parser
build-depends:
base ^>=4.14.3.0,
containers,
mtl,
parsec
ghc-options: -Wall -Werror -Wcompat -Widentities -Wincomplete-uni-patterns -Wincomplete-record-updates -Wno-unused-top-binds -Wno-orphans -Wno-type-defaults
hs-source-dirs:
task1/lib
default-language: Haskell2010
executable task1
main-is: Main.hs
ghc-options: -Wall -Werror -Wcompat -Widentities -Wincomplete-uni-patterns -Wincomplete-record-updates -Wno-unused-top-binds -Wno-orphans -Wno-type-defaults
build-depends:
base ^>=4.14.3.0
hs-source-dirs: task1
default-language: Haskell2010
When I do:
cabal repl
...
GHCi, version 8.10.7: https://www.haskell.org/ghc/ :? for help
[1 of 2] Compiling Interpreter ( task1/lib/Interpreter.hs, interpreted )
[2 of 2] Compiling Parser ( task1/lib/Parser.hs, interpreted )
Ok, two modules loaded.
> :l Parser
I get the following error:
<no location info>: error: [-Wmissing-home-modules, -Werror=missing-home-modules]
These modules are needed for compilation but not listed in your .cabal file's other-modules:
Interpreter
Question
What to do when I want to load a single file to experiment with the functions from that module in repl?
Also when I try the command cabal repl task1-lib the same happens.
EDIT:
There is a possible workaround to modify the cabal in the following way, by adding the -Wwarn=missing-home-modules after the -Werror. This still applies the -Werror for all warnings instead of the missing-home-modules error that remains a warning and makes it possible to :load a module in repl then.
library task1-lib
exposed-modules:
Interpreter,
Parser
build-depends:
base ^>=4.14.3.0,
containers,
mtl,
parsec
ghc-options: -Wall -Werror -Wwarn=missing-home-modules -Wcompat -Widentities -Wincomplete-uni-patterns -Wincomplete-record-updates -Wno-unused-top-binds -Wno-orphans -Wno-type-defaults
hs-source-dirs:
task1/lib
default-language: Haskell2010
executable task1
main-is: Main.hs
ghc-options: -Wall -Werror -Wcompat -Widentities -Wincomplete-uni-patterns -Wincomplete-record-updates -Wno-unused-top-binds -Wno-orphans -Wno-type-defaults
build-depends:
base ^>=4.14.3.0
hs-source-dirs: task1
default-language: Haskell2010
import enables only functions that are exported by the module
Instead of unsing :load or import, try using :module + *NameOfTheModule.
According to the docs for :module:
:module supports the * modifier on modules, which opens the full
top-level scope of a module, rather than just its exports.
This can't be done with ordinary import declarations, which behave much like imports in regular Haskell programs.
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.
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.
ddump-minimal-imports is a valuable tool. i cannot make it work for the executable and test-suites in my cabal file.
in my cabal file i have:
test-suite testDatas6forTestDataItem
type: exitcode-stdio-1.0
main-is: Datas6TestDataItemTest.hs
build-depends:
base -any,
time,
monads-tf,
default-language: Haskell2010
hs-source-dirs: ., srcexe
ghc-options: -threaded -ddump-minimal-imports
i find the imports files for the modules in the dist folder, but nothing for the tests and mains.
is this
due to some error on my part?
intentional behaviour?
the result of some technical limitations?
thank you for help!
I suspected they were emitted, just not where you might expect, so I ran an experiment and confirmed this. I forked kazu's test example package then added the extra minimal import flags to the cabal file like so:
Test-Suite doctest
Type: exitcode-stdio-1.0
...
ghc-options: -threaded -ddump-minimal-imports
Test-Suite spec
Type: exitcode-stdio-1.0
...
ghc-options: -threaded -ddump-minimal-imports
And the files did show up under dist in dist/build/doctest/doctest-tmp/Main.imports and dist/build/spec/spec-tmp/Main.imports. For the spec, which had other files in the suite as well, their imports also showed up in the same directory.
I am trying out c2hs, and wanted to compile a small example of a shared library with Cabal to get started.
I have the following relevant section of the cabal file test.cabal:
executable libtest.so
hs-source-dirs: src
main-is: Dummy.hs
other-extensions: ForeignFunctionInterface
build-depends: base
default-language: Haskell2010
ghc-options: -no-hs-main -threaded
build-tools: c2hs
Then the source. src/Dummy.hs:
import Test
main :: IO ()
main = return
In the file src/Test.chs
{-# LANGUAGE ForeignFunctionInterface #-}
import Foreign
import Foreign.C
module Android where
And then when I try to compile (cabal configure && cabal build -v) I get the following error message:
Component build order: executable 'libtest.so'
creating dist/build
creating dist/build/autogen
Building test-0.1.0.0...
Preprocessing executable 'libtest.so' for test-0.1.0.0...
Building executable libtest.so...
creating dist/build/libtest.so
creating dist/build/libtest.so/libtest.so-tmp
/opt/ghc/bin/ghc --make -no-link -fbuilding-cabal-package -O -j8 -static
-outputdir dist/build/libtest.so/libtest.so-tmp -odir dist/build
/libtest.so/libtest.so-tmp -hidir dist/build/libtest.so/libtest.so-tmp-stubdir
dist/build/libtest.so/libtest.so-tmp -i -idist/build/libtest.so/libtest.so-tmp
-isrc -idist/build/autogen -Idist/build/autogen
-Idist/build/libtest.so/libtest.so-tmp
-optP-include -optPdist/build/autogen/cabal_macros.h -hide-all-packages
-package-db dist/package.conf.inplace -package-id
base-4.7.0.1-1a55ebc8256b39ccbff004d48b3eb834 -XHaskell2010
src/Dummy.hs -no-hs-main -threaded
src/Dummy.hs:1:8:
Could not find module ‘Test’
Use -v to see a list of the files searched for.
Please, can you tell me what the cause of the error is? What am I missing?
You need to add Test to the other-modules field.