Skip to content

Commit

Permalink
Regress and fix some things to preserve behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
alt-romes committed Jan 18, 2024
1 parent 9e342c5 commit 1f3ff0a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
23 changes: 12 additions & 11 deletions Cabal/src/Distribution/Simple/GHC/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ build numJobs pkg_descr = do
(ghcProg, _) <- requireProgram verbosity ghcProgram (withPrograms lbi) & liftIO

-- Determine in which ways we want to build the component
-- For executables and foreign libraries, there should only be one wanted way
let
wantVanilla = if isLib then withVanillaLib lbi else False
-- ROMES:TODO: Arguably, wantStatic should be "withFullyStaticExe lbi" for
Expand All @@ -114,16 +113,18 @@ build numJobs pkg_descr = do
wantProf = if isLib then withProfLib lbi else withProfExe lbi

-- See also Note [Building Haskell Modules accounting for TH] in Distribution.Simple.GHC.Build.Modules
-- We build static by default if no other way is wanted
wantedWays =
Set.fromList $
[ StaticWay
| wantStatic
|| wantVanilla
|| not (wantDynamic || wantProf)
]
<> [DynWay | wantDynamic]
<> [ProfWay | wantProf]
-- We build static by default if no other way is wanted.
-- For executables and foreign libraries, there should only be one wanted way.
wantedWays = Set.fromList $
[ProfWay | wantProf]
`combine'` [DynWay | wantDynamic]
`combine'` [StaticWay | wantStatic || wantVanilla || not (wantDynamic || wantProf)]
where
combine' l r
-- If building a library, we accumulate all the ways we want to build in.
| isLib = l <> r
-- Otherwise, we have to pick the first wanted way
| otherwise = case l of [] -> r; _ -> l

info verbosity ("Wanted build ways: " ++ show (Set.toList wantedWays)) & liftIO

Expand Down
4 changes: 2 additions & 2 deletions Cabal/src/Distribution/Simple/GHC/Build/ExtraSources.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ buildAllExtraSources ghcProg buildTargetDir =
concat
<$> traverse
(($ buildTargetDir) . ($ ghcProg))
[ buildCSources
, buildCxxSources
[ buildCxxSources
, buildCSources
, buildJsSources
, buildAsmSources
, buildCmmSources
Expand Down
8 changes: 5 additions & 3 deletions Cabal/src/Distribution/Simple/GHC/Build/Modules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ buildHaskellModules numJobs ghcProg pkg_descr buildTargetDir wantedWays = do
{ ghcOptMode = toFlag GhcModeMake
, -- romes:TODO previously we didn't pass -no-link when building libs,
-- but I also think that could result in a bug (e.g. if a lib module
-- is called Main and exports main). Delete this comment in follow up PR to refactor.
ghcOptNoLink = toFlag True
-- is called Main and exports main). So we really want nolink when building libs too.
ghcOptNoLink = if isLib then NoFlag else toFlag True
, ghcOptNumJobs = numJobs
, ghcOptInputModules = toNubListR inputModules
, ghcOptInputFiles =
Expand All @@ -173,7 +173,9 @@ buildHaskellModules numJobs ghcProg pkg_descr buildTargetDir wantedWays = do
optSuffixFlag "" _ = NoFlag
optSuffixFlag pre x = toFlag (pre ++ x)

staticOpts = (baseOpts StaticWay){ghcOptDynLinkMode = toFlag GhcStaticOnly}
-- ROMES:TODO: For libs we don't pass -static when building static, leaving it implicit.
-- We should just always pass -static, but we don't want to change behaviour when doing the refactor.
staticOpts = (baseOpts StaticWay){ghcOptDynLinkMode = if isLib then NoFlag else toFlag GhcStaticOnly}
dynOpts =
(baseOpts DynWay)
{ ghcOptDynLinkMode = toFlag GhcDynamicOnly -- use -dynamic
Expand Down

0 comments on commit 1f3ff0a

Please sign in to comment.