Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cabal: Take into account compilerBuildWay when computing final library ways (backport #10419) #10423

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.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 @@
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 @@

(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 @@
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`.

}
Loading