开发者

Building with runtime flags using cabal and ghc

I have a program written in Haskell and intended to be compiled with GHC. The program scales very well on multiple cores, so enabling multithreading is very important. In my .cabal file I've added ghc-options: -O3 -threaded to link with the threaded runtime. The problem is that with this approach the user would need to run the program with foo +RTS -N, which seems a bit cryptic and not very user friendly.

How can开发者_C百科 I tell cabal/ghc to enable those runtime flags invisibly to the user? I've read about --with-rtsopts, but GHC (7.0.3) just spits out unrecognized flag when I try to use it.


The flag is -with-rtsopts, not --with-rtsopts, so you should add -with-rtsopts=-N to the ghc-options field. GHC Flag Reference.

Note that this will also require you to link with runtime support by adding -rtsopts to the ghc-options.


If you happen to use hpack to generate foo.cabal from package.yaml, this is the YAML syntax to use:

executables:
  foobar:
    main: Main.hs
    source-dirs: app
    ghc-options:
      - -threaded
      - -rtsopts
      - '"-with-rtsopts=-N -T"'
      - -Wall

    dependencies:
      […]

The string "-with-rtsopts=-N␣-T" should become one single argv item of the eventual ghc process.

Since YAML has quoted string literals too — both layers of escaping are necessary.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜