Skip to content

Commit

Permalink
Use linker capability detection to improve linker use
Browse files Browse the repository at this point in the history
The function `comperSupportsGhciLibs` has been renamed to
`linkerSupportsGhciLibs` because its about the linker not the compiler.

The function `comperSupportsGhciLibs` was using the compiler version
as a proxy for whether the linker supports relocatable objects. Now
support for relocatable objects is detected by running the linker.
  • Loading branch information
erikd committed Nov 14, 2023
1 parent 8b5e665 commit 1180003
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
28 changes: 11 additions & 17 deletions Cabal/src/Distribution/Simple/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import Distribution.Simple.PackageIndex (InstalledPackageIndex)
import qualified Distribution.Simple.PackageIndex as PackageIndex
import Distribution.Simple.PreProcess
import Distribution.Simple.Program
import Distribution.Simple.Program.Db (lookupProgramByName)
import Distribution.Simple.Setup.Common as Setup
import Distribution.Simple.Setup.Config as Setup
import Distribution.Simple.Utils
Expand Down Expand Up @@ -767,22 +768,15 @@ configure (pkg_descr0, pbi) cfg = do
)
return False

let compilerSupportsGhciLibs :: Bool
compilerSupportsGhciLibs =
case compilerId comp of
CompilerId GHC version
| version > mkVersion [9, 3] && windows ->
False
CompilerId GHC _ ->
True
CompilerId GHCJS _ ->
True
_ -> False
where
windows = case compPlatform of
Platform _ Windows -> True
Platform _ _ -> False

let linkerSupportsGhciLibs :: Bool
linkerSupportsGhciLibs =
case lookupProgramByName "ld" programDb'' of
Nothing -> True -- NOTE: This may still fail if the linker does not support -r.
Just ld ->
case Map.lookup "Supports relocatable output" $ programProperties ld of
Just "YES" -> True
Just "NO" -> False
_other -> True -- NOTE: This may still fail if the linker does not support -r.
let ghciLibByDefault =
case compilerId comp of
CompilerId GHC _ ->
Expand All @@ -801,7 +795,7 @@ configure (pkg_descr0, pbi) cfg = do

withGHCiLib_ <-
case fromFlagOrDefault ghciLibByDefault (configGHCiLib cfg) of
True | not compilerSupportsGhciLibs -> do
True | not linkerSupportsGhciLibs -> do
warn verbosity $
"--enable-library-for-ghci is no longer supported on Windows with"
++ " GHC 9.4 and later; ignoring..."
Expand Down
7 changes: 6 additions & 1 deletion Cabal/src/Distribution/Simple/Program/Db.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ module Distribution.Simple.Program.Db
, userSpecifyArgss
, userSpecifiedArgs
, lookupProgram
, lookupProgramByName
, updateProgram
, configuredPrograms

Expand Down Expand Up @@ -299,7 +300,11 @@ userSpecifiedArgs prog =

-- | Try to find a configured program
lookupProgram :: Program -> ProgramDb -> Maybe ConfiguredProgram
lookupProgram prog = Map.lookup (programName prog) . configuredProgs
lookupProgram = lookupProgramByName . programName

-- | Try to find a configured program
lookupProgramByName :: String -> ProgramDb -> Maybe ConfiguredProgram
lookupProgramByName name = Map.lookup name . configuredProgs

-- | Update a configured program in the database.
updateProgram
Expand Down

0 comments on commit 1180003

Please sign in to comment.