Skip to content

Commit 851772e

Browse files
mpickeringmergify[bot]
authored andcommitted
Cabal: Take into account compilerBuildWay when computing final library ways
In the profiling dynamic patch I made a mistake when computing the needed ways for a build. When building an executable, the Haskell modules need to be built * For the final link way * For the build way of the compiler if TH is enabled Before this patch, the modules were being built for all the configured library ways, which built modules in more configurations than the previous version of Cabal. Fixes haskell#10418 (cherry picked from commit 27c2668)
1 parent 3ade64c commit 851772e

File tree

9 files changed

+98
-3
lines changed

9 files changed

+98
-3
lines changed

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Distribution.Simple.Flag (Flag)
1212
import Distribution.Simple.GHC.Build.ExtraSources
1313
import Distribution.Simple.GHC.Build.Link
1414
import Distribution.Simple.GHC.Build.Modules
15-
import Distribution.Simple.GHC.Build.Utils (isHaskell)
15+
import Distribution.Simple.GHC.Build.Utils (compilerBuildWay, isHaskell)
1616
import Distribution.Simple.LocalBuildInfo
1717
import Distribution.Simple.Program.Builtin (ghcProgram)
1818
import Distribution.Simple.Program.Db (requireProgram)
@@ -73,6 +73,7 @@ build numJobs pkg_descr pbci = do
7373
verbosity = buildVerbosity pbci
7474
isLib = buildIsLib pbci
7575
lbi = localBuildInfo pbci
76+
bi = buildBI pbci
7677
clbi = buildCLBI pbci
7778
isIndef = componentIsIndefinite clbi
7879
mbWorkDir = mbWorkDirLBI lbi
@@ -111,9 +112,22 @@ build numJobs pkg_descr pbci = do
111112

112113
(ghcProg, _) <- liftIO $ requireProgram verbosity ghcProgram (withPrograms lbi)
113114

115+
-- Ways which are wanted from configuration flags
114116
let wantedWays@(wantedLibWays, _, wantedExeWay) = buildWays lbi
115117

116-
liftIO $ info verbosity ("Wanted build ways(" ++ show isLib ++ "): " ++ show (if isLib then wantedLibWays isIndef else [wantedExeWay]))
118+
-- Ways which are needed due to the compiler configuration
119+
let doingTH = usesTemplateHaskellOrQQ bi
120+
defaultGhcWay = compilerBuildWay (buildCompiler pbci)
121+
wantedLibBuildWays =
122+
if isLib
123+
then wantedLibWays isIndef
124+
else [wantedExeWay]
125+
finalLibBuildWays =
126+
wantedLibBuildWays
127+
++ [defaultGhcWay | doingTH && defaultGhcWay `notElem` wantedLibBuildWays]
128+
129+
liftIO $ info verbosity ("Wanted build ways(" ++ show isLib ++ "): " ++ show wantedLibBuildWays)
130+
liftIO $ info verbosity ("Final lib build ways(" ++ show isLib ++ "): " ++ show finalLibBuildWays)
117131
-- We need a separate build and link phase, and C sources must be compiled
118132
-- after Haskell modules, because C sources may depend on stub headers
119133
-- generated from compiling Haskell modules (#842, #3294).
@@ -127,7 +141,7 @@ build numJobs pkg_descr pbci = do
127141
| otherwise ->
128142
(Nothing, Just mainFile)
129143
Nothing -> (Nothing, Nothing)
130-
buildOpts <- buildHaskellModules numJobs ghcProg hsMainFile inputModules buildTargetDir (wantedLibWays isIndef) pbci
144+
buildOpts <- buildHaskellModules numJobs ghcProg hsMainFile inputModules buildTargetDir finalLibBuildWays pbci
131145
extraSources <- buildAllExtraSources nonHsMainFile ghcProg buildTargetDir wantedWays pbci
132146
linkOrLoadComponent
133147
ghcProg
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Revision history for p
2+
3+
## 0.1.0.0 -- YYYY-mm-dd
4+
5+
* First version. Released on an unsuspecting world.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
cabal-version: 3.12
2+
name: p
3+
version: 0.1.0.0
4+
license: NONE
5+
author: Matthew Pickering
6+
maintainer: [email protected]
7+
build-type: Simple
8+
extra-doc-files: CHANGELOG.md
9+
10+
common warnings
11+
ghc-options: -Wall
12+
13+
library
14+
import: warnings
15+
exposed-modules: MyLib
16+
build-depends: base
17+
hs-source-dirs: src
18+
default-language: Haskell2010
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module MyLib (someFunc) where
2+
3+
someFunc :: IO ()
4+
someFunc = putStrLn "someFunc"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Revision history for q
2+
3+
## 0.1.0.0 -- YYYY-mm-dd
4+
5+
* First version. Released on an unsuspecting world.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{-# LANGUAGE TemplateHaskell #-}
2+
module Main where
3+
4+
import MyLib
5+
6+
main :: IO ()
7+
main = someFunc
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
cabal-version: 3.12
2+
name: q
3+
version: 0.1.0.0
4+
license: NONE
5+
author: Matthew Pickering
6+
maintainer: [email protected]
7+
build-type: Simple
8+
extra-doc-files: CHANGELOG.md
9+
10+
common warnings
11+
ghc-options: -Wall
12+
13+
executable q
14+
import: warnings
15+
main-is: Main.hs
16+
build-depends: p, base
17+
hs-source-dirs: app
18+
ghc-options: -dynamic-too
19+
default-language: Haskell2010
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import Test.Cabal.Prelude
2+
3+
opts = ["--enable-shared", "--enable-library-vanilla", "--enable-library-profiling"]
4+
5+
-- See #10418
6+
main = setupTest $ recordMode DoNotRecord $ withPackageDb $ do
7+
skipIfNoSharedLibraries
8+
skipIfNoProfiledLibraries
9+
withDirectory "p" $ setup_install opts
10+
withDirectory "q" $ setup_install opts

changelog.d/i10418

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
synopsis: Fix build ways for modules in executables
2+
packages: Cabal
3+
prs: #10419
4+
issues: #10418
5+
significance: significant
6+
7+
description: {
8+
9+
- Modules belonging to executables were being built in too many ways. For instance, if you
10+
had configured to build profiled library files then your executable modules would also
11+
be built profiled. Which was a regression in behaviour since `Cabal-3.12`.
12+
13+
}

0 commit comments

Comments
 (0)