Skip to content

Commit

Permalink
Fix build ways for foreign libs
Browse files Browse the repository at this point in the history
Patches the component build ways for foreign library components.
  • Loading branch information
alt-romes committed Oct 7, 2024
1 parent 27c2668 commit 31009ed
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
29 changes: 16 additions & 13 deletions Cabal/src/Distribution/Simple/GHC/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Distribution.Simple.Flag (Flag)
import Distribution.Simple.GHC.Build.ExtraSources
import Distribution.Simple.GHC.Build.Link
import Distribution.Simple.GHC.Build.Modules
import Distribution.Simple.GHC.Build.Utils (compilerBuildWay, isHaskell)
import Distribution.Simple.GHC.Build.Utils (compilerBuildWay, isHaskell, withDynFLib)
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.Program.Builtin (ghcProgram)
import Distribution.Simple.Program.Db (requireProgram)
Expand Down Expand Up @@ -113,21 +113,24 @@ build numJobs pkg_descr pbci = do
(ghcProg, _) <- liftIO $ requireProgram verbosity ghcProgram (withPrograms lbi)

-- Ways which are wanted from configuration flags
let wantedWays@(wantedLibWays, _, wantedExeWay) = buildWays lbi
let wantedWays@(wantedLibWays, wantedFLibWay, 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)
wantedModBuildWays = case buildComponent pbci of
CLib _ -> wantedLibWays isIndef
CFLib fl -> [wantedFLibWay (withDynFLib fl)]
CExe _ -> [wantedExeWay]
CTest _ -> [wantedExeWay]
CBench _ -> [wantedExeWay]
finalModBuildWays =
wantedModBuildWays
++ [defaultGhcWay | doingTH && defaultGhcWay `notElem` wantedModBuildWays]
compNameStr = showComponentName $ componentName $ buildComponent pbci

liftIO $ info verbosity ("Wanted module build ways(" ++ compNameStr ++ "): " ++ show wantedModBuildWays)
liftIO $ info verbosity ("Final module build ways(" ++ compNameStr ++ "): " ++ show finalModBuildWays)
-- 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).
Expand All @@ -141,7 +144,7 @@ build numJobs pkg_descr pbci = do
| otherwise ->
(Nothing, Just mainFile)
Nothing -> (Nothing, Nothing)
buildOpts <- buildHaskellModules numJobs ghcProg hsMainFile inputModules buildTargetDir finalLibBuildWays pbci
buildOpts <- buildHaskellModules numJobs ghcProg hsMainFile inputModules buildTargetDir finalModBuildWays pbci
extraSources <- buildAllExtraSources nonHsMainFile ghcProg buildTargetDir wantedWays pbci
linkOrLoadComponent
ghcProg
Expand Down
4 changes: 2 additions & 2 deletions cabal-testsuite/PackageTests/ProfShared/setup.test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ main = do

let ls = lines (resultOutput r)

library_prefix = "Wanted build ways(True): "
executable_prefix = "Wanted build ways(False): "
library_prefix = "Wanted module build ways(library): "
executable_prefix = "Wanted module build ways(executable 'Prof'): "

get_ways prefix = map (drop (length prefix)) (filter (prefix `isPrefixOf`) ls)
library_ways = read_ways (get_ways library_prefix)
Expand Down

0 comments on commit 31009ed

Please sign in to comment.