使用 stack exec 将 +RTS 选项传递给程序 运行

Pass +RTS options to program run with stack exec

如何将 +RTS 选项传递给具有 stack exec 的程序 运行?

我已将 -rtsopts 添加到我的 cabal 文件中的 ghc-options,并使用 stack build 构建了一个程序。如果我 运行 程序手动正常和 +RTS 命令行参数工作:

>.stack-work\dist\ca59d0ab\build\iterate-strict-exe\iterate-strict-exe.exe 25 +RTS -s
OK
   3,758,156,184 bytes allocated in the heap
         297,976 bytes copied during GC
         ...

但是如果我 运行 它与 stack exec 只有正常选项到达程序

>stack exec iterate-strict-exe -- 25 +RTS -s
OK

其他不起作用的东西

如果我按照@epsilonhalbe 的建议调整参数的顺序,我会得到相同的结果。

>stack exec -- iterate-strict-exe 25 +RTS -s
OK

似乎没有建议的 --rts-options 选项传递给 stack exec

>stack exec --rts-options "-s" -- iterate-strict-exe 25
Invalid option `--rts-options'

Usage: stack exec CMD [-- ARGS (e.g. stack ghc -- X.hs -o x)] ([--plain] |
                  [--[no-]ghc-package-path] [--[no-]stack-exe] [--package ARG])
                  [--help]
  Execute a command

我正在使用 stack 版本 1.1.2

>stack --version
Version 1.1.2, Git revision c6dac65e3174dea79df54ce6d56f3e98bc060ecc (3647 commits) x86_64 hpack-0.14.0

stack upgrade1.4.0 后相同。


将整个命令作为字符串传递(另一个建议)会导致找不到具有该名称的命令

>stack exec -- "iterate-strict-exe 25 +RTS -s"
Executable named iterate-strict-exe 25 +RTS -s not found on path: ...

您似乎在 Windows 上遇到了 GHC 错误 #13287 (to be fixed in 8.2). See also stack issues 2022 and 2640。显然,解决方法是在 -- 之前添加 --RTS,例如

stack exec iterate-strict-exe --RTS -- 25 +RTS -s