In my stack project I have a myproject.cabal file. I would like to try the cabal option --disable-library-profiling documented here:
https://www.haskell.org/cabal/users-guide/installing-packages.html
However, I've been unable to figure out where that option must be used: wherever I put it, subsequent stack runs exit with failure (complaining in one way or another about the option).
My higher-level goal is to see if this speeds up ghc compilation for my project, but that's really secondary as far as this question goes: I'd really just like to know how these configuration options work (in the context of stack projects).
I'm using ghc 6.7. In particular, if I use cabal configure, the option ends up configured in ghc-options in my myproject.cabal file, but GHC then complains:
ghc: unrecognised flag: --disable-library-profiling
I'm already using other ghc-options without running into similar trouble -- stack completes successfully in this case:
ghc-options: -threaded -rtsopts -with-rtsopts=-N -O0 -j +RTS -A128m -n2m -RTS
but not in this case:
ghc-options: -threaded -rtsopts -with-rtsopts=-N -O0 -j +RTS -A128m -n2m -RTS --disable-library-profiling
The stack equivalent of --disable-library-profiling is:
$ stack build --no-library-profiling
Related
I have
ghc-options:
- -Wall
- -Werror
in my package.yaml and it builds fine for GHC 8.6.
But when using the project in a GHC 9 codebase, it errors because of an unnessessary MonadFail import.
How can I change the library such that it won't abort compilation when used in other projects?
I have tried
ghc-options:
"$everything": -Wwarn
in the downstream (dependent) project, but that doesn't seem to affect it. I expected -Wwarn to override the -Werror since $everything should cover even dependencies.
I believe, it is bad practice to specify -Werror on the library itself. Same goes for other compiler flags, such as optimization for example -O2.
Setting -Wall on the other hand is definitely good stuff, plus a few other warning flags of top of my head, eg. -Wincomplete-record-updates, -Wincomplete-uni-patterns, -Wredundant-constraints, etc.
If you want to turn build warnings into errors while working on the library or in CI, which is a sensible thing to do, then you can enable it in your
stack.yaml:
ghc-options:
my-library: -Werror
cabal.project:
package my-library
ghc-options: -Werror
That being said you can turn off -Werror for any library downstream by setting -Wwarn for that library in the exact same fashion as above, which will override the original flag.
I'm trying to get Stack working on an Arch system. I've done the usual:
pacman -S ghc stack cabal-install
And then placed the following in ~/.stack/config.yaml, so that the system GHC is used and dynamic libraries are used (the packages above do not include static libraries):
system-ghc: true
ghc-options:
"$everything": -dynamic
configure-options:
"$everything":
- -dynamic
But when I try to install something, (i.e. stack install wai) I see that it attempts to build a custom Setup script:
/usr/bin/ghc-8.6.5 -rtsopts -threaded -clear-package-db -global-package-db -hide-all-packages -package base -main-is StackSetupShim.mainOverride -package Cabal-2.4.0.1 /home/alba/.stack/setup-exe-src/setup-mPHDZzAJ.hs /home/alba/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs -o /home/alba/.stack/setup-exe-cache/x86_64-linux/tmp-Cabal-simple_mPHDZzAJ_2.4.0.1_ghc-8.6.5
And my options are not honored, so the build tries to use static libraries (and fails). Is there any way to get Stack/Cabal to use certain options when building Setup.hs?
EDIT: I found the relevant issues; it doesn't seem to be possible:
stack: Can't use system GHC without static libraries at all (#3409)
cabal: executable-dynamic: True should apply to build-type: Custom setup #1720
Related: It seems cabal will always attempt to build static + dynamic in some cases, even if you tell it otherwise.
For now, a partial solution I ended up using is to force the option with a wrapper.
At ~/.local/bin/ghc-8.6.5 put:
#!/bin/sh
exec /usr/bin/ghc-8.6.5 -dynamic "$#"
Then:
cd ~/.local/bin
chmod +x ghc-8.6.5
ln -s ghc{-8.6.5,}
ln -s {/usr/bin,.}/ghc-pkg-8.6.5
ln -s {/usr/bin,.}/runghc-8.6.5
ln -s {/usr/bin,.}/haddock-ghc-8.6.5
Make sure it's in your PATH and you're good to go.
I made instrumental build which generates profiling information. I use stack. GHC options in .cabal file are:
ghc-options: -Wall
-O2
-threaded
-prof
-fprof-auto
-rtsopts
-fprof-cafs
"-with-rtsopts=-N -s -h -i0.1 -p -M1G -SMyApplication-S.log"
so running application generates files: MyApplication-S.log, MyApplication.hp, MyApplication.prof, but in current working directory - which is the problem, sure (also I need to run it on Windows and Linux). Is it possible to specify directory of those output files with some option? Because, without it I will get "Can't open ... file..." error due to permission error - Haskell Runtime tries to save all of them in current folder (on Linux and on Windows standard folders for binaries are not allowed for writing).
After reading of GHC source code (Profiling.c and RtsFlags.c) I found that it's possible with -po option:
ghc-options: -Wall
-O2
-threaded
-prof
-fprof-auto
-rtsopts
-fprof-cafs
"-with-rtsopts=-N -s -h -i0.1 -p -po/My/Dir/MyApplication -M1G -S/My/Dir/MyApplication-S.log"
So, will be created same 3 files but now in /My/Dir folder.
I'm building statically linked binary using stack and I try to add debug symbols to it (following: https://downloads.haskell.org/~ghc/master/users-guide/debug-info.html). However GDB reports: no debugging symbols found.
What am I missing?
I've added to the ghc-options in the .cabal file: -g -rtsopts and to the ld-options: -static. I am building using stack with the following command:
stack install \
--install-ghc \
--split-objs \
--ghc-options="-fPIC -fllvm -pgmlo opt -pgmlc llc"
GDB is invoked as follows: gdb --args nodebug-exe +RTS -V0
GHC 8.2.1
Whole source code is here: https://github.com/carbolymer/haskell-missing-debug-symbols
--no-strip prevents debugging information being removed in the stack build.
From the documentation:
stack now supports debugging and profiling with DWARF information,
using the --no-strip, --no-library-stripping, and
--no-executable-stripping flags to disable the default behavior of removing such information from compiled libraries and executables.
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).