Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chain configuration of ldProgram #9270

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
strategy:
matrix:
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
ghc: ["9.6.3", "9.4.7", "9.2.8", "9.0.2", "8.10.7", "8.8.4", "8.6.5", "8.4.4"]
ghc: ["9.6.3", "9.4.7", "9.2.7", "9.0.2", "8.10.7", "8.8.4", "8.6.5", "8.4.4"]
exclude:
# corrupts GHA cache or the fabric of reality itself, see https://github.com/haskell/cabal/issues/8356
- os: "windows-latest"
Expand Down Expand Up @@ -73,7 +73,7 @@ jobs:
key: ${{ runner.os }}-${{ matrix.ghc }}-${{ github.sha }}
restore-keys: ${{ runner.os }}-${{ matrix.ghc }}-

- uses: haskell/actions/setup@v2
- uses: haskell-actions/setup@v2
id: setup-haskell
with:
ghc-version: ${{ matrix.ghc }}
Expand Down Expand Up @@ -215,7 +215,7 @@ jobs:
apt-get update
apt-get install -y ghc-${{ matrix.extra-ghc }}-dyn

- uses: haskell/actions/setup@v2
- uses: haskell-actions/setup@v2
id: setup-haskell
with:
ghc-version: ${{ matrix.ghc }}
Expand Down Expand Up @@ -268,7 +268,7 @@ jobs:
sudo chown -R $USER /usr/local/.ghcup
sudo chmod -R 777 /usr/local/.ghcup
fi
- uses: haskell/actions/setup@v2
- uses: haskell-actions/setup@v2
id: setup-haskell
with:
ghc-version: ${{ matrix.ghc }}
Expand Down
27 changes: 1 addition & 26 deletions Cabal/src/Distribution/Simple/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -767,22 +767,6 @@ 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 ghciLibByDefault =
case compilerId comp of
CompilerId GHC _ ->
Expand All @@ -799,15 +783,6 @@ configure (pkg_descr0, pbi) cfg = do
not (GHCJS.isDynamic comp)
_ -> False

withGHCiLib_ <-
case fromFlagOrDefault ghciLibByDefault (configGHCiLib cfg) of
True | not compilerSupportsGhciLibs -> do
warn verbosity $
"--enable-library-for-ghci is no longer supported on Windows with"
++ " GHC 9.4 and later; ignoring..."
return False
v -> return v

let sharedLibsByDefault
| fromFlag (configDynExe cfg) =
-- build a shared library if dynamically-linked
Expand Down Expand Up @@ -912,7 +887,7 @@ configure (pkg_descr0, pbi) cfg = do
, withProfExeDetail = ProfDetailNone
, withOptimization = fromFlag $ configOptimization cfg
, withDebugInfo = fromFlag $ configDebugInfo cfg
, withGHCiLib = withGHCiLib_
, withGHCiLib = fromFlagOrDefault ghciLibByDefault $ configGHCiLib cfg
, splitSections = split_sections
, splitObjs = split_objs
, stripExes = strip_exe
Expand Down
5 changes: 5 additions & 0 deletions Cabal/src/Distribution/Simple/Errors.hs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ data CabalException
| NoProgramFound String VersionRange
| BadVersionDb String Version VersionRange FilePath
| UnknownVersionDb String VersionRange FilePath
| CombineObjectFilesRelocatableUnsupported
deriving (Show, Typeable)

exceptionCode :: CabalException -> Int
Expand Down Expand Up @@ -301,6 +302,7 @@ exceptionCode e = case e of
NoProgramFound{} -> 7620
BadVersionDb{} -> 8038
UnknownVersionDb{} -> 1008
CombineObjectFilesRelocatableUnsupported -> 4346
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could not find any information about how this number is chosen. Found another relocation based exception and chose an unused number nearby.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SuganyaAK, @sclv, indeed we should make sure that this gets documented somehow. Would one of you be willing to do so?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the relevant discussion is #8543


versionRequirement :: VersionRange -> String
versionRequirement range
Expand Down Expand Up @@ -791,3 +793,6 @@ exceptionMessage e = case e of
++ " is required but the version of "
++ locationPath
++ " could not be determined."
CombineObjectFilesRelocatableUnsupported ->
"combineObjectFiles: Have been asked to combine object "
++ "files but the configured linker does not support relocations."
erikd marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 3 additions & 1 deletion Cabal/src/Distribution/Simple/GHC/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ configureToolchain _implInfo ghcProg ghcInfo =
. addKnownProgram
ldProgram
{ programFindLocation = findProg ldProgramName extraLdPath
, programPostConf = configureLd
, programPostConf = \v cp ->
-- Call any existing configuration first and then add any new configuration
configureLd v =<< programPostConf ldProgram v cp
}
. addKnownProgram
arProgram
Expand Down
14 changes: 13 additions & 1 deletion Cabal/src/Distribution/Simple/Program/Builtin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,19 @@ ldProgram =
-- `lld` only accepts `-help`.
`catchIO` (\_ -> return "")
let k = "Supports relocatable output"
v = if "--relocatable" `isInfixOf` ldHelpOutput then "YES" else "NO"
-- Standard GNU `ld` ues `--relocatable` while `ld.gold` uses
-- `-relocatable` (single `-`).
v
| "-relocatable" `isInfixOf` ldHelpOutput = "YES"
-- ld64 on macOS has this lovely response for "--help"
--
-- ld64: For information on command line options please use 'man ld'.
--
-- it does however support -r, if you read the manpage
-- (e.g. https://www.manpagez.com/man/1/ld64/)
| "ld64:" `isPrefixOf` ldHelpOutput = "YES"
| otherwise = "NO"

m = Map.insert k v (programProperties ldProg)
return $ ldProg{programProperties = m}
}
Expand Down
12 changes: 11 additions & 1 deletion Cabal/src/Distribution/Simple/Program/Ld.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@ module Distribution.Simple.Program.Ld
( combineObjectFiles
) where

import qualified Data.Map.Strict as Map

import Distribution.Compat.Prelude
import Prelude ()

import Distribution.Simple.Compiler (arResponseFilesSupported)
import Distribution.Simple.Errors
( CabalException (CombineObjectFilesRelocatableUnsupported)
)
import Distribution.Simple.Flag
( fromFlagOrDefault
)
Expand All @@ -40,11 +45,11 @@ import Distribution.Simple.Setup.Config
)
import Distribution.Simple.Utils
( defaultTempFileOptions
, dieWithException
)
import Distribution.Verbosity
( Verbosity
)

import System.Directory
( renameFile
)
Expand All @@ -67,6 +72,11 @@ combineObjectFiles verbosity lbi ld target files = do
-- have a slight problem. What we have to do is link files in batches into
-- a temp object file and then include that one in the next batch.

case Map.lookup "Supports relocatable output" $ programProperties ld of
Just "YES" -> pure ()
Just "NO" ->
dieWithException verbosity $ CombineObjectFilesRelocatableUnsupported
_other -> pure () -- NOTE: This may still fail if the compiler does not support -r.
let simpleArgs = ["-r", "-o", target]

initialArgs = ["-r", "-o", target]
Expand Down
7 changes: 1 addition & 6 deletions Cabal/src/Distribution/Simple/Setup/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,7 @@ defaultConfigFlags progDb =
, configCabalFilePath = NoFlag
, configVerbosity = Flag normal
, configUserInstall = Flag False -- TODO: reverse this
#if defined(mingw32_HOST_OS)
-- See #8062 and GHC #21019.
, configGHCiLib = Flag False
#else
, configGHCiLib = NoFlag
#endif
, configGHCiLib = Flag True
, configSplitSections = Flag False
, configSplitObjs = Flag False -- takes longer, so turn off by default
, configStripExes = NoFlag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import Test.Cabal.Prelude
-- qualified imports. (Paper Backpack doesn't natively support
-- this but we must!)
main = setupAndCabalTest $ do
isWin <- isWindows
ghc94 <- isGhcVersion "== 9.4.*"
expectBrokenIf (isWin && ghc94) 9414 $
withPackageDb $ do
withDirectory "p" $ setup_install []
withDirectory "q" $ setup_install []
Expand Down
7 changes: 5 additions & 2 deletions cabal-testsuite/PackageTests/Ambiguity/setup-reexport.test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import Test.Cabal.Prelude
-- Test that we can resolve a module name ambiguity when reexporting
-- by explicitly specifying what package we want.
main = setupAndCabalTest $ do
skipUnlessGhcVersion ">= 7.9"
withPackageDb $ do
isWin <- isWindows
ghc94 <- isGhcVersion "== 9.4.*"
expectBrokenIf (isWin && ghc94) 9414 $ do
skipUnlessGhcVersion ">= 7.9"
withPackageDb $ do
withDirectory "p" $ setup_install []
withDirectory "q" $ setup_install []
withDirectory "reexport" $ setup_install []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import Test.Cabal.Prelude
main = setupAndCabalTest $ do
isWin <- isWindows
ghc94 <- isGhcVersion "== 9.4.*"
expectBrokenIf (isWin && ghc94) 9414 $ do
skipUnlessGhcVersion ">= 8.1"
withPackageDb $ do
setup_install ["--cabal-file", "Includes2.cabal"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import Test.Cabal.Prelude
main = setupAndCabalTest $ do
isWin <- isWindows
ghc94 <- isGhcVersion "== 9.4.*"
expectBrokenIf (isWin && ghc94) 9414 $ do
skipUnlessGhcVersion ">= 8.1"
withPackageDb $ do
setup_install []
Expand Down
3 changes: 3 additions & 0 deletions cabal-testsuite/PackageTests/Backpack/Includes4/setup.test.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import Test.Cabal.Prelude
main = setupAndCabalTest $ do
isWin <- isWindows
ghc94 <- isGhcVersion "== 9.4.*"
expectBrokenIf (isWin && ghc94) 9414 $ do
skipUnlessGhcVersion ">= 8.1"
withPackageDb $ do
setup_install []
Expand Down
3 changes: 3 additions & 0 deletions cabal-testsuite/PackageTests/Backpack/Includes5/setup.test.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import Test.Cabal.Prelude
main = setupAndCabalTest $ do
isWin <- isWindows
ghc94 <- isGhcVersion "== 9.4.*"
expectBrokenIf (isWin && ghc94) 9414 $ do
skipUnlessGhcVersion ">= 8.1"
setup "configure" []
r <- fails $ setup' "build" []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import Test.Cabal.Prelude
main = setupAndCabalTest $ do
skipUnlessGhcVersion ">= 8.1"
skipUnlessGhcVersion ">= 8.1"
isWin <- isWindows
ghc94 <- isGhcVersion "== 9.4.*"
expectBrokenIf (isWin && ghc94) 9414 $
withPackageDb $ do
withDirectory "p" $ setup_install_with_docs []
withDirectory "q" $ do
Expand Down
5 changes: 4 additions & 1 deletion cabal-testsuite/PackageTests/Backpack/T4754/setup.test.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import Test.Cabal.Prelude
main = setupAndCabalTest $ do
skipUnlessGhcVersion ">= 8.1"
skipUnlessGhcVersion ">= 8.1"
isWin <- isWindows
ghc94 <- isGhcVersion "== 9.4.*"
expectBrokenIf (isWin && ghc94) 9414 $ do
skipUnless "no profiling libs" =<< hasProfiledLibraries
setup "configure" ["--enable-profiling"]
setup "build" []
5 changes: 4 additions & 1 deletion cabal-testsuite/PackageTests/Backpack/T5634/setup.test.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import Test.Cabal.Prelude
main = setupAndCabalTest $ do
skipUnlessGhcVersion ">= 8.1"
skipUnlessGhcVersion ">= 8.1"
isWin <- isWindows
ghc94 <- isGhcVersion "== 9.4.*"
expectBrokenIf (isWin && ghc94) 9414 $ do
setup "configure" []
setup "build" []
6 changes: 5 additions & 1 deletion cabal-testsuite/PackageTests/BenchmarkExeV10/setup.test.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import Test.Cabal.Prelude
-- Test if exitcode-stdio-1.0 benchmark builds correctly
main = setupAndCabalTest $ setup_build ["--enable-benchmarks"]
main = setupAndCabalTest $ do
isWin <- isWindows
ghc94 <- isGhcVersion "== 9.4.*"
expectBrokenIf (isWin && ghc94) 9414 $
setup_build ["--enable-benchmarks"]
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import Test.Cabal.Prelude
-- Test executable depends on internal library.
main = setupAndCabalTest $ setup_build []
main = setupAndCabalTest $ do
isWin <- isWindows
ghc94 <- isGhcVersion "== 9.4.*"
expectBrokenIf (isWin && ghc94) 9414 $
setup_build []

Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import Test.Cabal.Prelude
main = setupAndCabalTest . withPackageDb $ do
withDirectory "to-install" $ setup_install []
setup_build []
r <- runExe' "lemon" []
assertEqual
main = setupAndCabalTest $ do
isWin <- isWindows
ghc94 <- isGhcVersion "== 9.4.*"
expectBrokenIf (isWin && ghc94) 9414 $
withPackageDb $ do
withDirectory "to-install" $ setup_install []
setup_build []
r <- runExe' "lemon" []
assertEqual
("executable should have linked with the internal library")
("foo foo myLibFunc internal")
(concatOutput (resultOutput r))
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import Test.Cabal.Prelude
-- Test that internal library is preferred to an installed on
-- with the same name and LATER version
main = setupAndCabalTest . withPackageDb $ do
withDirectory "to-install" $ setup_install []
setup_build []
r <- runExe' "lemon" []
assertEqual
("executable should have linked with the internal library")
("foo foo myLibFunc internal")
(concatOutput (resultOutput r))
main = setupAndCabalTest $ do
isWin <- isWindows
ghc94 <- isGhcVersion "== 9.4.*"
expectBrokenIf (isWin && ghc94) 9414 $
withPackageDb $ do
withDirectory "to-install" $ setup_install []
setup_build []
r <- runExe' "lemon" []
assertEqual
("executable should have linked with the internal library")
("foo foo myLibFunc internal")
(concatOutput (resultOutput r))
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@ import Test.Cabal.Prelude
-- Test "old build-dep behavior", where we should get the
-- same package dependencies on all targets if setup-version
-- is sufficiently old.
main = setupAndCabalTest $ setup_build []
main = setupAndCabalTest $ do
isWin <- isWindows
ghc94 <- isGhcVersion "== 9.4.*"
expectBrokenIf (isWin && ghc94) 9414 $
setup_build []

Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import Test.Cabal.Prelude
-- This is a control on ../TargetSpecificDeps1/setup.test.hs; it should
-- succeed.
main = setupAndCabalTest $ setup_build []
main = setupAndCabalTest $ do
isWin <- isWindows
ghc94 <- isGhcVersion "== 9.4.*"
expectBrokenIf (isWin && ghc94) 9414 $
setup_build []
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import Test.Cabal.Prelude
-- Test PATH-munging
main = setupAndCabalTest $ do
isWin <- isWindows
ghc94 <- isGhcVersion "== 9.4.*"
expectBrokenIf (isWin && ghc94) 9414 $ do
setup_build []
runExe' "hello-world" []
>>= assertOutputContains "1111"
3 changes: 3 additions & 0 deletions cabal-testsuite/PackageTests/CabalMacros/setup.test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import Test.Cabal.Prelude
import qualified Data.ByteString.Char8 as BS8

main = setupAndCabalTest $ do
isWin <- isWindows
ghc94 <- isGhcVersion "== 9.4.*"
expectBrokenIf (isWin && ghc94) 9414 $ do
env <- getTestEnv
let mode = testRecordMode env

Expand Down
Loading
Loading