Skip to content

Commit

Permalink
Cabal: Take into account compilerBuildWay when computing final librar…
Browse files Browse the repository at this point in the history
…y 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 #10418

(cherry picked from commit 27c2668)

# Conflicts:
#	Cabal/src/Distribution/Simple/GHC/Build.hs
  • Loading branch information
mpickering authored and mergify[bot] committed Oct 4, 2024
1 parent 45ba6dc commit 8c0a876
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 0 deletions.
46 changes: 46 additions & 0 deletions Cabal/src/Distribution/Simple/GHC/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import Distribution.Simple.Flag (Flag)
import Distribution.Simple.GHC.Build.ExtraSources
import Distribution.Simple.GHC.Build.Link
import Distribution.Simple.GHC.Build.Modules
<<<<<<< HEAD

Check failure on line 14 in Cabal/src/Distribution/Simple/GHC/Build.hs

View workflow job for this annotation

GitHub Actions / hlint

Error: Parse error: on input `<<<<<<<' ▫︎ Found: " import Distribution.Simple.GHC.Build.Link\n import Distribution.Simple.GHC.Build.Modules\n> <<<<<<< HEAD\n import Distribution.Simple.GHC.Build.Utils (withDynFLib)\n =======\n"

Check failure on line 14 in Cabal/src/Distribution/Simple/GHC/Build.hs

View workflow job for this annotation

GitHub Actions / hlint

Error: Parse error: on input `<<<<<<<' ▫︎ Found: " import Distribution.Simple.GHC.Build.Link\n import Distribution.Simple.GHC.Build.Modules\n> <<<<<<< HEAD\n import Distribution.Simple.GHC.Build.Utils (withDynFLib)\n =======\n"
import Distribution.Simple.GHC.Build.Utils (withDynFLib)
=======
import Distribution.Simple.GHC.Build.Utils (compilerBuildWay, isHaskell)
>>>>>>> 27c266884 (Cabal: Take into account compilerBuildWay when computing final library ways)
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.Program
import Distribution.Simple.Utils
Expand Down Expand Up @@ -71,6 +75,7 @@ build numJobs pkg_descr pbci = do
component = buildComponent pbci
isLib = buildIsLib pbci
lbi = localBuildInfo pbci
bi = buildBI pbci
clbi = buildCLBI pbci

-- Create a few directories for building the component
Expand Down Expand Up @@ -102,6 +107,7 @@ build numJobs pkg_descr pbci = do

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

<<<<<<< HEAD
-- Determine in which ways we want to build the component
let
wantVanilla = if isLib then withVanillaLib lbi else False
Expand Down Expand Up @@ -138,3 +144,43 @@ build numJobs pkg_descr pbci = do
buildOpts <- buildHaskellModules numJobs ghcProg pkg_descr buildTargetDir_absolute wantedWays pbci
extraSources <- buildAllExtraSources ghcProg buildTargetDir pbci
linkOrLoadComponent ghcProg pkg_descr (fromNubListR extraSources) (buildTargetDir, targetDir_absolute) (wantedWays, buildOpts) pbci
=======
-- Ways which are wanted from configuration flags
let wantedWays@(wantedLibWays, _, wantedExeWay) = buildWays lbi

-- Ways which are needed due to the compiler configuration
let doingTH = usesTemplateHaskellOrQQ bi
defaultGhcWay = compilerBuildWay (buildCompiler pbci)
wantedLibBuildWays =
if isLib
then wantedLibWays isIndef
else [wantedExeWay]
finalLibBuildWays =
wantedLibBuildWays
++ [defaultGhcWay | doingTH && defaultGhcWay `notElem` wantedLibBuildWays]

liftIO $ info verbosity ("Wanted build ways(" ++ show isLib ++ "): " ++ show wantedLibBuildWays)
liftIO $ info verbosity ("Final lib build ways(" ++ show isLib ++ "): " ++ show finalLibBuildWays)
-- We need a separate build and link phase, and C sources must be compiled
-- after Haskell modules, because C sources may depend on stub headers
-- generated from compiling Haskell modules (#842, #3294).
(mbMainFile, inputModules) <- componentInputs buildTargetDir pkg_descr pbci
let (hsMainFile, nonHsMainFile) =
case mbMainFile of
Just mainFile
| PD.package pkg_descr == fakePackageId
|| isHaskell (getSymbolicPath mainFile) ->
(Just mainFile, Nothing)
| otherwise ->
(Nothing, Just mainFile)
Nothing -> (Nothing, Nothing)
buildOpts <- buildHaskellModules numJobs ghcProg hsMainFile inputModules buildTargetDir finalLibBuildWays pbci
extraSources <- buildAllExtraSources nonHsMainFile ghcProg buildTargetDir wantedWays pbci
linkOrLoadComponent
ghcProg
pkg_descr
(fromNubListR extraSources)
(buildTargetDir, targetDir)
(wantedWays, buildOpts)
pbci
>>>>>>> 27c266884 (Cabal: Take into account compilerBuildWay when computing final library ways)
5 changes: 5 additions & 0 deletions cabal-testsuite/PackageTests/BuildWays/p/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Revision history for p

## 0.1.0.0 -- YYYY-mm-dd

* First version. Released on an unsuspecting world.
18 changes: 18 additions & 0 deletions cabal-testsuite/PackageTests/BuildWays/p/p.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cabal-version: 3.12
name: p
version: 0.1.0.0
license: NONE
author: Matthew Pickering
maintainer: [email protected]
build-type: Simple
extra-doc-files: CHANGELOG.md

common warnings
ghc-options: -Wall

library
import: warnings
exposed-modules: MyLib
build-depends: base
hs-source-dirs: src
default-language: Haskell2010
4 changes: 4 additions & 0 deletions cabal-testsuite/PackageTests/BuildWays/p/src/MyLib.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module MyLib (someFunc) where

someFunc :: IO ()
someFunc = putStrLn "someFunc"
5 changes: 5 additions & 0 deletions cabal-testsuite/PackageTests/BuildWays/q/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Revision history for q

## 0.1.0.0 -- YYYY-mm-dd

* First version. Released on an unsuspecting world.
7 changes: 7 additions & 0 deletions cabal-testsuite/PackageTests/BuildWays/q/app/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{-# LANGUAGE TemplateHaskell #-}
module Main where

import MyLib

main :: IO ()
main = someFunc
19 changes: 19 additions & 0 deletions cabal-testsuite/PackageTests/BuildWays/q/q.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cabal-version: 3.12
name: q
version: 0.1.0.0
license: NONE
author: Matthew Pickering
maintainer: [email protected]
build-type: Simple
extra-doc-files: CHANGELOG.md

common warnings
ghc-options: -Wall

executable q
import: warnings
main-is: Main.hs
build-depends: p, base
hs-source-dirs: app
ghc-options: -dynamic-too
default-language: Haskell2010
10 changes: 10 additions & 0 deletions cabal-testsuite/PackageTests/BuildWays/setup.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Test.Cabal.Prelude

opts = ["--enable-shared", "--enable-library-vanilla", "--enable-library-profiling"]

-- See #10418
main = setupTest $ recordMode DoNotRecord $ withPackageDb $ do
skipIfNoSharedLibraries
skipIfNoProfiledLibraries
withDirectory "p" $ setup_install opts
withDirectory "q" $ setup_install opts
13 changes: 13 additions & 0 deletions changelog.d/i10418
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
synopsis: Fix build ways for modules in executables
packages: Cabal
prs: #10419
issues: #10418
significance: significant

description: {

- Modules belonging to executables were being built in too many ways. For instance, if you
had configured to build profiled library files then your executable modules would also
be built profiled. Which was a regression in behaviour since `Cabal-3.12`.

}

0 comments on commit 8c0a876

Please sign in to comment.