Skip to content

Commit 83b607c

Browse files
authored
Merge pull request #5568 from parsonsmatt/matt/ghc-rts-options
Allow passing RTS options to GHC in stack.yaml
2 parents 18634d2 + a42fb51 commit 83b607c

File tree

6 files changed

+68
-2
lines changed

6 files changed

+68
-2
lines changed

ChangeLog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Bug fixes:
2929
[pantry#33](https://github.com/commercialhaskell/pantry/issues/33)
3030
* When building the sanity check for a new GHC install, make sure to clear
3131
`GHC_PACKAGE_PATH`.
32-
32+
* Specifying GHC RTS flags in the `stack.yaml` no longer fails with an error. [#5568](https://github.com/commercialhaskell/stack/pull/5568)
3333

3434
## v2.7.1
3535

src/Stack/Types/Build.hs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,14 +629,53 @@ configureOptsNoDir econfig bco deps isLocal package = concat
629629
flagNameString name)
630630
(Map.toList flags)
631631
, map T.unpack $ packageCabalConfigOpts package
632-
, concatMap (\x -> [compilerOptionsCabalFlag wc, T.unpack x]) (packageGhcOptions package)
632+
, processGhcOptions (packageGhcOptions package)
633633
, map ("--extra-include-dirs=" ++) (configExtraIncludeDirs config)
634634
, map ("--extra-lib-dirs=" ++) (configExtraLibDirs config)
635635
, maybe [] (\customGcc -> ["--with-gcc=" ++ toFilePath customGcc]) (configOverrideGccPath config)
636636
, ["--exact-configuration"]
637637
, ["--ghc-option=-fhide-source-paths" | hideSourcePaths cv]
638638
]
639639
where
640+
-- This function parses the GHC options that are providing in the
641+
-- stack.yaml file. In order to handle RTS arguments correctly, we need
642+
-- to provide the RTS arguments as a single argument.
643+
processGhcOptions :: [Text] -> [String]
644+
processGhcOptions args =
645+
let
646+
(preRtsArgs, mid) =
647+
break ("+RTS" ==) args
648+
(rtsArgs, end) =
649+
break ("-RTS" ==) mid
650+
fullRtsArgs =
651+
case rtsArgs of
652+
[] ->
653+
-- This means that we didn't have any RTS args - no
654+
-- `+RTS` - and therefore no need for a `-RTS`.
655+
[]
656+
_ ->
657+
-- In this case, we have some RTS args. `break`
658+
-- puts the `"-RTS"` string in the `snd` list, so
659+
-- we want to append it on the end of `rtsArgs`
660+
-- here.
661+
--
662+
-- We're not checking that `-RTS` is the first
663+
-- element of `end`. This is because the GHC RTS
664+
-- allows you to omit a trailing -RTS if that's the
665+
-- last of the arguments. This permits a GHC
666+
-- options in stack.yaml that matches what you
667+
-- might pass directly to GHC.
668+
[T.unwords $ rtsArgs ++ ["-RTS"]]
669+
-- We drop the first element from `end`, because it is always
670+
-- either `"-RTS"` (and we don't want that as a separate
671+
-- argument) or the list is empty (and `drop _ [] = []`).
672+
postRtsArgs =
673+
drop 1 end
674+
newArgs =
675+
concat [preRtsArgs, fullRtsArgs, postRtsArgs]
676+
in
677+
concatMap (\x -> [compilerOptionsCabalFlag wc, T.unpack x]) newArgs
678+
640679
wc = view (actualCompilerVersionL.to whichCompiler) econfig
641680
cv = view (actualCompilerVersionL.to getGhcVersion) econfig
642681

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import StackTest
2+
3+
main :: IO ()
4+
main = do
5+
stack ["clean"]
6+
stack ["build"]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: files
2+
version: 0.1.0.0
3+
build-type: Simple
4+
cabal-version: >=1.10
5+
6+
library
7+
hs-source-dirs: src
8+
exposed-modules: Lib
9+
build-depends: base >= 4.7 && < 5, mtl
10+
default-language: Haskell2010
11+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Lib where
2+
3+
main :: IO ()
4+
main = putStrLn "hello world"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
resolver: lts-14.27
2+
packages:
3+
- .
4+
5+
ghc-options:
6+
"$locals": -j8 +RTS -s -A128M

0 commit comments

Comments
 (0)