Passing RTS-opts to `stack test` - haskell

How can I pass RTS options to the test-suite of my project using stack?
stack exec allows for passing options to the executable, but since stack test is a synonym for stack build --test I can't see how to accomplish this.
I'm trying to generate some JSON-formatted profiler output for my test-suite using the RTS option -pj (GHC user guide).
I can see where stack places the regular executables, but not the executables for the test-suite.

Related

global GHC from Stack?

I have happily installed Stack, and run my code with stack ghci or stack exec and whatnot.
I would like to use vscode-haskell, and that requires a ghc available in the PATH.
Is it possible to create a ghc command available globally using stack? (e.g. some suitable commans in my powershell/bash profile)
ps. Close duplicates that did not help me are
Using stack ghc as replacement of ghc but only talks about makefiles
Haskell Stack doesn't use system Ghc is about making Stack use a system GHC if it is available which is not the case for me
Haskell stack with global ghc which is close to a dupplicate of [2]

Compile stack script instead of running it

The build tool stack has the feature to treat a usually compiled haskell source file as a script. (https://docs.haskellstack.org/en/stable/GUIDE/#script-interpreter)
Is it also possible to create a compiled executable the same way?
I searched the help section of stack and stack script, but could not find an options that make this possible.
script.hs:
#!/usr/bin/env stack
{-
stack script
--resolver lts-13.14
--package turtle
-}
main = print "hello"
So if given it the right permissions, this file can be executed. I guess behind the scenes stack compiles the file and then just runs it. And I'd like to just get the compiled intermediate binary.
No, it's not compiled. It's run through runhaskell which is a Haskell interpreter. If you want to compile it... do that. Instead of running the script,
take the --resolver and --package options from the script comment and pass them like this
stack ghc --resolver lts-13.14 --package turtle test.hs
The script command takes both --compile and --optimize as flags, which will instruct Stack to first compile to an executable (optionally with -O2 optimization level) before running.

How can I get GHC Core output via stack?

How do I get a stack build command to dump the GHC Core?
I've tried this, to no avail:
stack build :hello_world --ghc-options '-ddump-simpl'
Make sure to clean before, or force recompilation via the stack option --force-dirty and ghc option -fforce-recomp.
The files are dumped somewhere around .stack-work/dist/.../build/hello_world/hello_world-tmp/.

How to add memory profiling options to stack test

when running stack test --profile it automatically adds the -p rts option.
I am trying to do some memory profiling on my test suite and so would like to add the hc, or hy rts option.
This doesn't seem to work
stack test --profile --ghc-options="+RTS -hc -RTS"
it gives the error
ghc: the flag -hc requires the program to be built with -prof
If I have to guess, you intend the +RTS options to be passed to the final test program, but in your invocation above it might be that those options are being received by the ghc executable itself; like you are telling to ghc "compile this code but please profile your memory while you do that". My suggestion is to build the tests with profiling enabled (for example by running the tests first with stack test --profile, although probably you can also use some form of stack build) and then run the generated test executable (with profiling) passing the RTS options.

Can you have different compilers and resolvers on Stack?

I have a Stack project that can build both GHCJS and GHC binaries. How can I specify on stack.yaml that builds should use both compilers?
I think you have to either
use two different files, say ghc.yaml and ghcjs.yaml, you can then use stack --stack-yaml ghc.yaml or stack --stack-yaml ghcjs.yaml to use those
you can set the compiler ghc or ghcjs by setting the resolver (see haskellstack.org/config#resolver)
or there is a compiler option (see haskellstack.org/config#compiler)
or directly use the commandline option --compiler

Resources