From d424287eeb42eda2bb2e97dccc05797ce900cf7c Mon Sep 17 00:00:00 2001 From: Erik de Castro Lopo Date: Tue, 14 Nov 2023 14:41:24 +1100 Subject: [PATCH] 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. --- Cabal/src/Distribution/Simple/Configure.hs | 28 ++++++++------------- Cabal/src/Distribution/Simple/Program/Db.hs | 7 +++++- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/Cabal/src/Distribution/Simple/Configure.hs b/Cabal/src/Distribution/Simple/Configure.hs index 1c9188a2a6b..5289dc64652 100644 --- a/Cabal/src/Distribution/Simple/Configure.hs +++ b/Cabal/src/Distribution/Simple/Configure.hs @@ -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 @@ -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 _ -> @@ -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..." diff --git a/Cabal/src/Distribution/Simple/Program/Db.hs b/Cabal/src/Distribution/Simple/Program/Db.hs index 5bef94e4b5f..1407230b93b 100644 --- a/Cabal/src/Distribution/Simple/Program/Db.hs +++ b/Cabal/src/Distribution/Simple/Program/Db.hs @@ -46,6 +46,7 @@ module Distribution.Simple.Program.Db , userSpecifyArgss , userSpecifiedArgs , lookupProgram + , lookupProgramByName , updateProgram , configuredPrograms @@ -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