Skip to content

Commit d424287

Browse files
committed
Use linker capability detection to improve linker use
The function `comperSupportsGhciLibs` has been renamed to `linkerSupportsGhciLibs` because its about the linker not the compiler. The function `comperSupportsGhciLibs` was used the compiler version as a proxy for whether the linker supports relocatable objects. Now support for relocatable objects is detected by running it.
1 parent 8b5e665 commit d424287

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

Cabal/src/Distribution/Simple/Configure.hs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ import Distribution.Simple.PackageIndex (InstalledPackageIndex)
8282
import qualified Distribution.Simple.PackageIndex as PackageIndex
8383
import Distribution.Simple.PreProcess
8484
import Distribution.Simple.Program
85+
import Distribution.Simple.Program.Db (lookupProgramByName)
8586
import Distribution.Simple.Setup.Common as Setup
8687
import Distribution.Simple.Setup.Config as Setup
8788
import Distribution.Simple.Utils
@@ -767,22 +768,15 @@ configure (pkg_descr0, pbi) cfg = do
767768
)
768769
return False
769770

770-
let compilerSupportsGhciLibs :: Bool
771-
compilerSupportsGhciLibs =
772-
case compilerId comp of
773-
CompilerId GHC version
774-
| version > mkVersion [9, 3] && windows ->
775-
False
776-
CompilerId GHC _ ->
777-
True
778-
CompilerId GHCJS _ ->
779-
True
780-
_ -> False
781-
where
782-
windows = case compPlatform of
783-
Platform _ Windows -> True
784-
Platform _ _ -> False
785-
771+
let linkerSupportsGhciLibs :: Bool
772+
linkerSupportsGhciLibs =
773+
case lookupProgramByName "ld" programDb'' of
774+
Nothing -> True -- NOTE: This may still fail if the linker does not support -r.
775+
Just ld ->
776+
case Map.lookup "Supports relocatable output" $ programProperties ld of
777+
Just "YES" -> True
778+
Just "NO" -> False
779+
_other -> True -- NOTE: This may still fail if the linker does not support -r.
786780
let ghciLibByDefault =
787781
case compilerId comp of
788782
CompilerId GHC _ ->
@@ -801,7 +795,7 @@ configure (pkg_descr0, pbi) cfg = do
801795

802796
withGHCiLib_ <-
803797
case fromFlagOrDefault ghciLibByDefault (configGHCiLib cfg) of
804-
True | not compilerSupportsGhciLibs -> do
798+
True | not linkerSupportsGhciLibs -> do
805799
warn verbosity $
806800
"--enable-library-for-ghci is no longer supported on Windows with"
807801
++ " GHC 9.4 and later; ignoring..."

Cabal/src/Distribution/Simple/Program/Db.hs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ module Distribution.Simple.Program.Db
4646
, userSpecifyArgss
4747
, userSpecifiedArgs
4848
, lookupProgram
49+
, lookupProgramByName
4950
, updateProgram
5051
, configuredPrograms
5152

@@ -299,7 +300,11 @@ userSpecifiedArgs prog =
299300

300301
-- | Try to find a configured program
301302
lookupProgram :: Program -> ProgramDb -> Maybe ConfiguredProgram
302-
lookupProgram prog = Map.lookup (programName prog) . configuredProgs
303+
lookupProgram = lookupProgramByName . programName
304+
305+
-- | Try to find a configured program
306+
lookupProgramByName :: String -> ProgramDb -> Maybe ConfiguredProgram
307+
lookupProgramByName name = Map.lookup name . configuredProgs
303308

304309
-- | Update a configured program in the database.
305310
updateProgram

0 commit comments

Comments
 (0)