Skip to content

Commit

Permalink
fixup! Refactor the linking invocations from gbuild/buildOrReplLib
Browse files Browse the repository at this point in the history
  • Loading branch information
alt-romes committed Jan 22, 2024
1 parent 419bf51 commit 76f71eb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 4 additions & 4 deletions Cabal/src/Distribution/Simple/GHC/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,18 @@ build numJobs pkg_descr = do
createDirectoryIfMissingVerbose verbosity True buildTargetDir_absolute

-- See Note [Build Target Dir vs Target Dir] as well
_targetDir <- makeRelativeToCurrentDirectory targetDir_absolute & liftIO
_targetDir <- liftIO $ makeRelativeToCurrentDirectory targetDir_absolute
buildTargetDir <-
-- ROMES:TODO: To preserve the previous behaviour, we don't use relative
-- dirs for executables. Historically, this isn't needed to reduce the CLI
-- limit (unlike for libraries) because we link executables with the module
-- names instead of passing the path to object file -- that's something
-- else we can now fix after the refactor lands.
if isLib
then makeRelativeToCurrentDirectory buildTargetDir_absolute & liftIO
then liftIO $ makeRelativeToCurrentDirectory buildTargetDir_absolute
else return buildTargetDir_absolute

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

-- Determine in which ways we want to build the component
let
Expand Down Expand Up @@ -127,7 +127,7 @@ build numJobs pkg_descr = do
<> [DynWay | wantDynamic && not (componentIsIndefinite clbi)]
<> [StaticWay | wantStatic || wantVanilla || not (wantDynamic || wantProf)]

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

-- 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
Expand Down
10 changes: 6 additions & 4 deletions Cabal/src/Distribution/Simple/GHC/Build/Link.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ linkOrLoadComponent ghcProg pkg_descr extraSources (buildTargetDir, targetDir) (
clbi <- buildCLBI

-- ensure extra lib dirs exist before passing to ghc
cleanedExtraLibDirs <- filterM doesDirectoryExist (extraLibDirs bi) & liftIO
cleanedExtraLibDirsStatic <- filterM doesDirectoryExist (extraLibDirsStatic bi) & liftIO
cleanedExtraLibDirs <- liftIO $ filterM doesDirectoryExist (extraLibDirs bi)
cleanedExtraLibDirsStatic <- liftIO $ filterM doesDirectoryExist (extraLibDirsStatic bi)

let
-- ROMES:TODO: If we fix the order to C++ then C, then we cannot keep this matching the
Expand All @@ -90,7 +90,7 @@ linkOrLoadComponent ghcProg pkg_descr extraSources (buildTargetDir, targetDir) (
{ ghcOptLinkOptions =
PD.ldOptions bi
++ [ "-static"
| withFullyStaticExe lbi -- ROMES:TODO: wb withStaticLib??
| withFullyStaticExe lbi -- ROMES:TODO: wb withStaticLib and flibs??
]
-- Pass extra `ld-options` given
-- through to GHC's linker.
Expand All @@ -107,7 +107,7 @@ linkOrLoadComponent ghcProg pkg_descr extraSources (buildTargetDir, targetDir) (
else extraLibs bi
, ghcOptLinkLibPath =
toNubListR $
-- ROMES:TODO: what about withStaticLib??
-- ROMES:TODO: what about withStaticLib and flibs??
if withFullyStaticExe lbi
then cleanedExtraLibDirsStatic
else cleanedExtraLibDirs
Expand Down Expand Up @@ -476,6 +476,8 @@ linkFLib flib bi lbi linkerOpts (wantedWays, buildOpts) targetDir runGhcProg = d
let buildName = flibBuildName lbi flib
-- There should not be more than one wanted way when building an flib
assert (Set.size wantedWays == 1) $
-- ROMES:TODO: Using the "wantedWay" is a bit senseless here, we likely
-- just want to use the Way of each ForeignLib type.
forM_ wantedWays $ \way -> do
runGhcProg (linkOpts way){ghcOptOutputFile = toFlag (targetDir </> buildName)}
renameFile (targetDir </> buildName) (targetDir </> flibTargetName lbi flib)
Expand Down

0 comments on commit 76f71eb

Please sign in to comment.