I tried running
$ stack build --profile && stack run myexec --rts-options -p
But I get
...
Registering library for mylibrary-0.1.0.1..
Completed 2 action(s).
myexec: the flag -p requires the program to be built with -prof
...
I know I could run
$ .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/myexe/myexe +RTS -p
But what's the point of stack run
then? I don't want to have to know the version of cabal and the architecture etc (this all happens in a makefile).
The command that you use stack run
is a convenience command that not only runs the binary, but also builds it prior to that. So when you run stack build --profile
it compiles you binary with all of the necessary ghc flags, but when you call stack run
it compiles it again, but now without all of the profiling flags. So there are two way to do it properly:
stack build
, since it is redundant:$ stack --profile run myexec --rts-options -p
+RTS
flags, but make sure to pass --profile
to both stack
invocations, otherwise the stack exec
will be looking in the wrong place for the binary (namely non-profiling build) and will fail to find it.$ stack --profile build
$ stack --profile exec -- myexec +RTS -p
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With