Skip to content

Commit ce977c6

Browse files
committed
add more comments and change changelog.d/pr-10969.md
1 parent 0fcb121 commit ce977c6

File tree

10 files changed

+98
-48
lines changed

10 files changed

+98
-48
lines changed

Cabal/src/Distribution/Simple/GHC/Build/ExtraSources.hs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,15 @@ buildCSources mbMainFile =
7878
(Internal.sourcesGhcOptions verbosity lbi bi clbi odir filename)
7979
{ -- C++ compiler options: GHC >= 8.10 requires -optcxx, older requires -optc
8080
-- we want to be able to support cxx-options and cc-options separately
81-
ghcOptCxxOptions = Internal.separateGhcOptions (mkVersion [8, 10]) (compiler lbi) (Internal.defaultGhcOptCxxOptions lbi bi)
82-
, -- there are problems with linking with versions lower than 9.4, that's why we need this duplication
81+
-- see example in cabal-testsuite/PackageTests/FFI/ForeignOptsC
82+
ghcOptCxxOptions =
83+
Internal.separateGhcOptions
84+
(mkVersion [8, 10])
85+
(compiler lbi)
86+
(Internal.defaultGhcOptCxxOptions lbi bi)
87+
, -- there are problems with linking with versions below 9.4,
88+
-- that's why we need this replacement for linkGhcOptions
89+
-- see example in cabal-testsuite/PackageTests/ShowBuildInfo/Complex
8390
ghcOptCcProgram = Internal.defaultGhcOptCcProgram lbi
8491
}
8592
)
@@ -99,8 +106,15 @@ buildCxxSources mbMainFile =
99106
(Internal.sourcesGhcOptions verbosity lbi bi clbi odir filename)
100107
{ -- C++ compiler options: GHC >= 8.10 requires -optcxx, older requires -optc
101108
-- we want to be able to support cxx-options and cc-options separately
102-
ghcOptCcOptions = Internal.separateGhcOptions (mkVersion [8, 10]) (compiler lbi) (Internal.defaultGhcOptCcOptions lbi bi)
103-
, -- there are problems with linking with versions lower than 9.4, that's why we need this duplication
109+
-- see example in cabal-testsuite/PackageTests/FFI/ForeignOptsCxx
110+
ghcOptCcOptions =
111+
Internal.separateGhcOptions
112+
(mkVersion [8, 10])
113+
(compiler lbi)
114+
(Internal.defaultGhcOptCcOptions lbi bi)
115+
, -- there are problems with linking with versions below 9.4,
116+
-- that's why we need this replacement for linkGhcOptions
117+
-- see example in cabal-testsuite/PackageTests/ShowBuildInfo/Complex
104118
ghcOptCcProgram = Internal.defaultGhcOptCcProgram lbi
105119
}
106120
)

Cabal/src/Distribution/Simple/GHC/Internal.hs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,14 @@ sourcesGhcOptions verbosity lbi bi clbi odir filename =
399399
optimizationCFlags :: LocalBuildInfo -> [String]
400400
optimizationCFlags lbi =
401401
( case withOptimization lbi of
402+
-- see --disable-optimization
402403
NoOptimisation -> []
403-
NormalOptimisation -> ["-O1"]
404+
-- '*-options: -O[n]' is generally not needed. When building with
405+
-- optimisations Cabal automatically adds '-O2' for * code. Setting it
406+
-- yourself interferes with the --disable-optimization flag.
407+
-- see https://github.com/haskell/cabal/pull/8250
408+
NormalOptimisation -> ["-O2"]
409+
-- see --enable-optimization
404410
MaximumOptimisation -> ["-O2"]
405411
)
406412
++ ( case withDebugInfo lbi of
@@ -420,6 +426,7 @@ defaultGhcOptCcProgram :: LocalBuildInfo -> Flag FilePath
420426
defaultGhcOptCcProgram lbi =
421427
maybeToFlag $ programPath <$> lookupProgram gccProgram (withPrograms lbi)
422428

429+
-- we want to be able to support C++ and C separately in older ghc
423430
separateGhcOptions :: Monoid a => Version -> Compiler -> a -> a
424431
separateGhcOptions ver comp defaultOptions =
425432
case compilerCompatVersion GHC comp of
@@ -473,7 +480,10 @@ linkGhcOptions verbosity lbi bi clbi =
473480
, ghcOptExtra = hcOptions GHC bi <> cmmOptions bi
474481
, ghcOptCabal = toFlag True
475482
, ghcOptCcProgram =
476-
separateGhcOptions (mkVersion [9, 4]) (compiler lbi) (defaultGhcOptCcProgram lbi)
483+
separateGhcOptions
484+
(mkVersion [9, 4])
485+
(compiler lbi)
486+
(defaultGhcOptCcProgram lbi)
477487
, ghcOptThisUnitId = case clbi of
478488
LibComponentLocalBuildInfo{componentCompatPackageKey = pk} ->
479489
toFlag pk

Cabal/src/Distribution/Simple/GHCJS.hs

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,17 +1435,20 @@ gbuild verbosity numJobs pkg_descr lbi bm clbi = do
14351435
sequence_
14361436
[ do
14371437
let baseCxxOpts =
1438-
( Internal.sourcesGhcOptions verbosity lbi bnfo clbi tmpDir filename
1439-
<> mempty
1440-
{ ghcOptCcOptions =
1441-
( case compilerCompatVersion GHC comp of
1442-
Just v
1443-
| v >= mkVersion [8, 10] -> Internal.defaultGhcOptCcOptions lbi bnfo
1444-
Just _ -> []
1445-
Nothing -> []
1446-
)
1447-
}
1448-
)
1438+
(Internal.sourcesGhcOptions verbosity lbi bnfo clbi odir filename)
1439+
{ -- C++ compiler options: GHC >= 8.10 requires -optcxx, older requires -optc
1440+
-- we want to be able to support cxx-options and cc-options separately
1441+
-- see example in cabal-testsuite/PackageTests/FFI/ForeignOptsCxx
1442+
ghcOptCcOptions =
1443+
Internal.separateGhcOptions
1444+
(mkVersion [8, 10])
1445+
(compiler lbi)
1446+
(Internal.defaultGhcOptCcOptions lbi bnfo)
1447+
, -- there are problems with linking with versions below 9.4,
1448+
-- that's why we need this replacement for linkGhcOptions
1449+
-- see example in cabal-testsuite/PackageTests/ShowBuildInfo/Complex
1450+
ghcOptCcProgram = Internal.defaultGhcOptCcProgram lbi
1451+
}
14491452
vanillaCxxOpts =
14501453
if isGhcDynamic
14511454
then -- Dynamic GHC requires C++ sources to be built
@@ -1484,7 +1487,21 @@ gbuild verbosity numJobs pkg_descr lbi bm clbi = do
14841487
info verbosity "Building C Sources..."
14851488
sequence_
14861489
[ do
1487-
let baseCcOpts = Internal.sourcesGhcOptions verbosity lbi bnfo clbi tmpDir filename
1490+
let baseCcOpts =
1491+
(Internal.sourcesGhcOptions verbosity lbi bnfo clbi tmpDir filename)
1492+
{ -- C++ compiler options: GHC >= 8.10 requires -optcxx, older requires -optc
1493+
-- we want to be able to support cxx-options and cc-options separately
1494+
-- see example in cabal-testsuite/PackageTests/FFI/ForeignOptsC
1495+
ghcOptCxxOptions =
1496+
Internal.separateGhcOptions
1497+
(mkVersion [8, 10])
1498+
(compiler lbi)
1499+
(Internal.defaultGhcOptCxxOptions lbi bnfo)
1500+
, -- there are problems with linking with versions below 9.4,
1501+
-- that's why we need this replacement for linkGhcOptions
1502+
-- see example in cabal-testsuite/PackageTests/ShowBuildInfo/Complex
1503+
ghcOptCcProgram = Internal.defaultGhcOptCcProgram lbi
1504+
}
14881505
vanillaCcOpts =
14891506
if isGhcDynamic
14901507
then -- Dynamic GHC requires C sources to be built
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# JSPPOptions
2+
3+
This asserts that cabal passes `jspp-options` to the JavaScript-preprocessor.

0 commit comments

Comments
 (0)