Sven Tennie pushed to branch wip/romes/hadrian-cross-stage2-rebase_SVEN_FINAL at Glasgow Haskell Compiler / GHC

Commits:

3 changed files:

Changes:

  • hadrian/src/Rules/Generate.hs
    ... ... @@ -491,7 +491,7 @@ generateSettings settingsFile = do
    491 491
     
    
    492 492
         settings <- traverse sequence $
    
    493 493
             [ ("unlit command", ("$topdir/../bin/" <>) <$> expr (programName (ctx { Context.package = unlit, Context.stage = predStage stage })))
    
    494
    -        , ("Use interpreter", expr $ yesNo <$> ghcWithInterpreter (predStage stage))
    
    494
    +        , ("Use interpreter", expr $ yesNo <$> ghcWithInterpreter stage)
    
    495 495
             -- Hard-coded as Cabal queries these to determine way support and we
    
    496 496
             -- need to always advertise all ways when bootstrapping.
    
    497 497
             -- The settings file is generated at install time when installing a bindist.
    

  • hadrian/src/Settings/Packages.hs
    ... ... @@ -8,7 +8,7 @@ import Oracles.Flag
    8 8
     import Packages
    
    9 9
     import Settings
    
    10 10
     import Settings.Builders.Common (wayCcArgs)
    
    11
    -import Settings.Program (ghcWithInterpreter)
    
    11
    +import Settings.Program (ghcWithInterpreter, ghcWithInternalInterpreter)
    
    12 12
     
    
    13 13
     import qualified GHC.Toolchain.Library as Lib
    
    14 14
     import GHC.Toolchain.Target
    
    ... ... @@ -27,9 +27,12 @@ packageArgs = do
    27 27
             cross = flag CrossCompiling
    
    28 28
             haveCurses = any (/= "") <$> traverse (`buildSetting` stage) [ CursesIncludeDir, CursesLibDir ]
    
    29 29
     
    
    30
    +        -- Check if the bootstrap compiler has the same version as the one we
    
    31
    +        -- are building. This is used to build cross-compilers
    
    32
    +        bootCross = (==) <$> ghcVersionStage (stage0InTree) <*> ghcVersionStage Stage1
    
    33
    +
    
    30 34
             compilerStageOption f = buildingCompilerStage' . f =<< expr flavour
    
    31 35
     
    
    32
    -    isCrossStage <- staged crossStage
    
    33 36
         cursesIncludeDir <- staged (buildSetting CursesIncludeDir)
    
    34 37
         cursesLibraryDir <- staged (buildSetting CursesLibDir)
    
    35 38
         ffiIncludeDir  <- staged (buildSetting FfiIncludeDir)
    
    ... ... @@ -88,7 +91,7 @@ packageArgs = do
    88 91
                 --    on the host and must rely on external interpreter to load
    
    89 92
                 --    target code, otherwise enable for stage2 since that runs on
    
    90 93
                 --    the target and can use target's own ghci object linker
    
    91
    -            [ expr (ghcWithInterpreter stage) `cabalFlag` "internal-interpreter"
    
    94
    +            [ ghcWithInterpreter stage `cabalFlag` "internal-interpreter"
    
    92 95
                 , orM [ notM cross, haveCurses ]  `cabalFlag` "terminfo"
    
    93 96
                 , arg "-build-tool-depends"
    
    94 97
                 , staged (buildFlag UseLibzstd) `cabalFlag` "with-libzstd"
    
    ... ... @@ -110,8 +113,8 @@ packageArgs = do
    110 113
                  , compilerStageOption ghcDebugAssertions ? arg "-DDEBUG" ]
    
    111 114
     
    
    112 115
               , builder (Cabal Flags) ? mconcat
    
    113
    -            [ expr (ghcWithInterpreter stage) `cabalFlag` "interpreter"
    
    114
    -            , andM [expr (ghcWithInterpreter stage), notM (pure isCrossStage)] `cabalFlag` "internal-interpreter"
    
    116
    +            [ ghcWithInterpreter (succStage stage) `cabalFlag` "interpreter"
    
    117
    +            , ghcWithInternalInterpreter (succStage stage) `cabalFlag` "internal-interpreter"
    
    115 118
                 , ifM stage0
    
    116 119
                       -- We build a threaded stage 1 if the bootstrapping compiler
    
    117 120
                       -- supports it.
    
    ... ... @@ -162,10 +165,11 @@ packageArgs = do
    162 165
               --
    
    163 166
                 builder (Cabal Setup) ? cabalExtraDirs ffiIncludeDir ffiLibraryDir
    
    164 167
               , builder (Cabal Flags) ? mconcat
    
    165
    -            [ stage0 `cabalFlag` "bootstrap",
    
    166
    -              andM [expr (ghcWithInterpreter stage), notM (pure isCrossStage)] `cabalFlag` "internal-interpreter"
    
    168
    +            [ ifM stage0
    
    169
    +                (andM [cross, bootCross] `cabalFlag` "internal-interpreter")
    
    170
    +                (arg "internal-interpreter")
    
    171
    +            , stage0 `cabalFlag` "bootstrap"
    
    167 172
                 ]
    
    168
    -
    
    169 173
               ]
    
    170 174
     
    
    171 175
             , package unix ? builder (Cabal Flags) ? arg "+os-string"
    

  • hadrian/src/Settings/Program.hs
    1 1
     module Settings.Program
    
    2 2
       ( programContext
    
    3 3
       , ghcWithInterpreter
    
    4
    -  ) where
    
    4
    +  , archSupportsInternalInterpreter
    
    5
    +  , ghcWithInternalInterpreter
    
    6
    +) where
    
    5 7
     
    
    6 8
     import Base
    
    7 9
     import Context
    
    ... ... @@ -9,7 +11,7 @@ import Oracles.Flavour
    9 11
     import Packages
    
    10 12
     
    
    11 13
     import GHC.Platform.ArchOS
    
    12
    -import Settings.Builders.Common (anyTargetOs, anyTargetArch, isArmTarget)
    
    14
    +import Settings.Builders.Common (anyTargetOs, anyTargetArch, isArmTarget, crossStage)
    
    13 15
     
    
    14 16
     -- TODO: there is duplication and inconsistency between this and
    
    15 17
     -- Rules.Program.getProgramContexts. There should only be one way to
    
    ... ... @@ -39,6 +41,18 @@ programContext stage pkg = do
    39 41
     -- Also checks whether the target supports GHCi.
    
    40 42
     ghcWithInterpreter :: Stage -> Action Bool
    
    41 43
     ghcWithInterpreter stage = do
    
    44
    +    hasInternalInterpreter <- ghcWithInternalInterpreter stage
    
    45
    +    isCross <- crossStage stage
    
    46
    +    return $ (hasInternalInterpreter || isCross) && (stage >= Stage1)
    
    47
    +
    
    48
    +ghcWithInternalInterpreter :: Stage -> Action Bool
    
    49
    +ghcWithInternalInterpreter stage = do
    
    50
    +    hasInternalInterpreter <- archSupportsInternalInterpreter stage
    
    51
    +    isCross <- crossStage stage
    
    52
    +    return $ hasInternalInterpreter && not isCross && (stage >= Stage1)
    
    53
    +
    
    54
    +archSupportsInternalInterpreter :: Stage -> Action Bool
    
    55
    +archSupportsInternalInterpreter stage = do
    
    42 56
         goodOs <- anyTargetOs stage [ OSMinGW32, OSLinux, OSSolaris2
    
    43 57
                               , OSFreeBSD, OSDragonFly, OSNetBSD, OSOpenBSD
    
    44 58
                               , OSDarwin, OSKFreeBSD
    
    ... ... @@ -56,4 +70,4 @@ ghcWithInterpreter stage = do
    56 70
         -- fall back on dynamic linking:
    
    57 71
         dynamicGhcProgs <- askDynGhcPrograms stage
    
    58 72
     
    
    59
    -    return $ ((goodOs && goodArch) || dynamicGhcProgs) && (stage >= Stage2)
    73
    +    return $ (goodOs && goodArch) || dynamicGhcProgs