Skip to content

Commit f4d696d

Browse files
authored
Merge pull request #10422 from haskell/mergify/bp/3.14/pr-10419
Cabal: Take into account compilerBuildWay when computing final library ways (backport #10419)
2 parents 3ade64c + 7c25fcb commit f4d696d

File tree

10 files changed

+105
-7
lines changed

10 files changed

+105
-7
lines changed

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

Lines changed: 22 additions & 5 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, withDynFLib)
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,25 @@ build numJobs pkg_descr pbci = do
111112

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

114-
let wantedWays@(wantedLibWays, _, wantedExeWay) = buildWays lbi
115-
116-
liftIO $ info verbosity ("Wanted build ways(" ++ show isLib ++ "): " ++ show (if isLib then wantedLibWays isIndef else [wantedExeWay]))
115+
-- Ways which are wanted from configuration flags
116+
let wantedWays@(wantedLibWays, wantedFLibWay, wantedExeWay) = buildWays lbi
117+
118+
-- Ways which are needed due to the compiler configuration
119+
let doingTH = usesTemplateHaskellOrQQ bi
120+
defaultGhcWay = compilerBuildWay (buildCompiler pbci)
121+
wantedModBuildWays = case buildComponent pbci of
122+
CLib _ -> wantedLibWays isIndef
123+
CFLib fl -> [wantedFLibWay (withDynFLib fl)]
124+
CExe _ -> [wantedExeWay]
125+
CTest _ -> [wantedExeWay]
126+
CBench _ -> [wantedExeWay]
127+
finalModBuildWays =
128+
wantedModBuildWays
129+
++ [defaultGhcWay | doingTH && defaultGhcWay `notElem` wantedModBuildWays]
130+
compNameStr = showComponentName $ componentName $ buildComponent pbci
131+
132+
liftIO $ info verbosity ("Wanted module build ways(" ++ compNameStr ++ "): " ++ show wantedModBuildWays)
133+
liftIO $ info verbosity ("Final module build ways(" ++ compNameStr ++ "): " ++ show finalModBuildWays)
117134
-- We need a separate build and link phase, and C sources must be compiled
118135
-- after Haskell modules, because C sources may depend on stub headers
119136
-- generated from compiling Haskell modules (#842, #3294).
@@ -127,7 +144,7 @@ build numJobs pkg_descr pbci = do
127144
| otherwise ->
128145
(Nothing, Just mainFile)
129146
Nothing -> (Nothing, Nothing)
130-
buildOpts <- buildHaskellModules numJobs ghcProg hsMainFile inputModules buildTargetDir (wantedLibWays isIndef) pbci
147+
buildOpts <- buildHaskellModules numJobs ghcProg hsMainFile inputModules buildTargetDir finalModBuildWays pbci
131148
extraSources <- buildAllExtraSources nonHsMainFile ghcProg buildTargetDir wantedWays pbci
132149
linkOrLoadComponent
133150
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

cabal-testsuite/PackageTests/ProfShared/setup.test.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ main = do
1616

1717
let ls = lines (resultOutput r)
1818

19-
library_prefix = "Wanted build ways(True): "
20-
executable_prefix = "Wanted build ways(False): "
19+
library_prefix = "Wanted module build ways(library): "
20+
executable_prefix = "Wanted module build ways(executable 'Prof'): "
2121

2222
get_ways prefix = map (drop (length prefix)) (filter (prefix `isPrefixOf`) ls)
2323
library_ways = read_ways (get_ways library_prefix)

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)