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

Commits:

5 changed files:

Changes:

  • hadrian/src/Builder.hs
    ... ... @@ -415,8 +415,7 @@ isOptional target = \case
    415 415
         Alex     -> True
    
    416 416
         -- Most ar implemententions no longer need ranlib, but some still do
    
    417 417
         Ranlib {}   -> not $ Toolchain.arNeedsRanlib (tgtAr target)
    
    418
    -    -- TODO: Use stage argument
    
    419
    -    JsCpp  {}    -> not $ (archOS_arch . tgtArchOs) target == ArchJavaScript -- ArchWasm32 too?
    
    418
    +    JsCpp  {}   -> (archOS_arch . tgtArchOs) target /= ArchJavaScript -- ArchWasm32 too?
    
    420 419
         _        -> False
    
    421 420
     
    
    422 421
     -- | Determine the location of a system 'Builder'.
    

  • hadrian/src/Oracles/Setting.hs
    ... ... @@ -7,7 +7,6 @@ module Oracles.Setting (
    7 7
         -- * Helpers
    
    8 8
         ghcCanonVersion, cmdLineLengthLimit, targetSupportsRPaths, topDirectory,
    
    9 9
         libsuf, ghcVersionStage, bashPath, targetStage, crossStage, queryTarget, queryTargetTarget,
    
    10
    -    isHostStage,
    
    11 10
     
    
    12 11
         -- ** Target platform things
    
    13 12
         anyTargetOs, anyTargetArch, anyHostOs,
    
    ... ... @@ -233,15 +232,19 @@ libsuf st way
    233 232
     
    
    234 233
     -- | Build libraries for this `Stage` targetting this `Target`
    
    235 234
     --
    
    236
    --- For example, we want to build RTS with stage1 for the host target as we
    
    237
    --- produce a host executable with stage1 (which cross-compiles to stage2).
    
    235
    +-- For example, for cross-compilers we want to build RTS with Stage1 for the
    
    236
    +-- host target as we produce a host executable with Stage1 (which
    
    237
    +-- cross-compiles to Stage2).
    
    238
    +--
    
    239
    +-- For non-cross-compilers we can directly use the final target for Stage1.
    
    240
    +--
    
    241
    +-- The algorithm is:
    
    242
    +--  Stage0    -> Host
    
    243
    +--  Stage1    -> Target, if not cross, Host otherwise
    
    244
    +--  >= Stage2 -> Target
    
    238 245
     targetStage :: Stage -> Action Target
    
    239 246
     targetStage Stage0 {} = getHostTarget
    
    240
    -targetStage stage | isHostStage stage = do
    
    241
    -  -- MP: If we are not cross compiling then we should use the target file in order to
    
    242
    -  -- build things for the host, in particular we want to use the configured values for the
    
    243
    -  -- target for building the RTS (ie are we using Libffi for adjustors, and the wordsize)
    
    244
    -  -- TODO: Use "flag CrossCompiling"
    
    247
    +targetStage Stage1 = do
    
    245 248
        ht <- getHostTarget
    
    246 249
        tt <- getTargetTarget
    
    247 250
        if targetPlatformTriple ht == targetPlatformTriple tt
    
    ... ... @@ -249,11 +252,7 @@ targetStage stage | isHostStage stage = do
    249 252
          else return ht
    
    250 253
     targetStage _ = getTargetTarget
    
    251 254
     
    
    252
    -isHostStage :: Stage -> Bool
    
    253
    -isHostStage stage | stage <= Stage1 = True
    
    254
    -isHostStage _ = False
    
    255
    -
    
    256
    -queryTarget :: Stage -> (Target -> a) -> (Expr c b a)
    
    255
    +queryTarget :: Stage -> (Target -> a) -> Expr c b a
    
    257 256
     queryTarget s f = expr (f <$> targetStage s)
    
    258 257
     
    
    259 258
     queryTargetTarget :: Stage -> (Target -> a) -> Action a
    

  • hadrian/src/Rules/Test.hs
    ... ... @@ -217,7 +217,6 @@ testEnv stg = do
    217 217
     
    
    218 218
         top             <- topDirectory
    
    219 219
         pythonPath      <- builderPath Python
    
    220
    -    -- MP: TODO wrong, should use the ccPath and ccFlags from the bindist we are testing.
    
    221 220
         ccPath          <- queryTargetTarget stg (Toolchain.prgPath . Toolchain.ccProgram . Toolchain.tgtCCompiler)
    
    222 221
         ccFlags         <- queryTargetTarget stg (unwords . Toolchain.prgFlags . Toolchain.ccProgram . Toolchain.tgtCCompiler)
    
    223 222
         ghcFlags        <- runTestGhcFlags stg
    

  • hadrian/src/Settings/Builders/Cabal.hs
    ... ... @@ -90,8 +90,7 @@ commonCabalArgs stage = do
    90 90
                 -- we might have issues with stripping on Windows, as I can't see a
    
    91 91
                 -- consumer of 'stripCmdPath'.
    
    92 92
                 -- TODO: See https://github.com/snowleopard/hadrian/issues/549.
    
    93
    -            -- TODO: MP should check per-stage rather than a global CrossCompiling, but not going to cause bugs
    
    94
    -              flag CrossCompiling ? pure [ "--disable-executable-stripping"
    
    93
    +              crossStage stage ? pure [ "--disable-executable-stripping"
    
    95 94
                                              , "--disable-library-stripping" ]
    
    96 95
                 -- We don't want to strip the debug RTS
    
    97 96
                 , S.package rts ? pure [ "--disable-executable-stripping"
    

  • hadrian/src/Settings/Builders/RunTest.hs
    ... ... @@ -105,50 +105,49 @@ allowHaveLLVM = not . (`elem` ["wasm32", "javascript"])
    105 105
     --
    
    106 106
     inTreeCompilerArgs :: Stage -> Action TestCompilerArgs
    
    107 107
     inTreeCompilerArgs stg = do
    
    108
    -    -- TODO: executable and library stage would be clearer
    
    109 108
         cross <- crossStage stg
    
    110
    -    let ghcStage = succStage stg
    
    111
    -        pkgCacheStage = if cross then ghcStage else stg
    
    109
    +    let executableStage = succStage stg
    
    110
    +        libraryStage = if cross then executableStage else stg
    
    112 111
         (hasDynamicRts, hasThreadedRts) <- do
    
    113
    -      ways <- interpretInContext (vanillaContext ghcStage rts) getRtsWays
    
    112
    +      ways <- interpretInContext (vanillaContext executableStage rts) getRtsWays
    
    114 113
           return (dynamic `elem` ways, threaded `elem` ways)
    
    115
    -    hasDynamic          <- (wayUnit Dynamic) . Context.Type.way <$> (programContext stg ghc)
    
    116
    -    leadingUnderscore   <- queryTargetTarget ghcStage tgtSymbolsHaveLeadingUnderscore
    
    117
    -    withInterpreter     <- ghcWithInterpreter ghcStage
    
    118
    -    unregisterised      <- queryTargetTarget ghcStage tgtUnregisterised
    
    119
    -    tables_next_to_code <- queryTargetTarget ghcStage tgtTablesNextToCode
    
    120
    -    targetWithSMP       <- targetSupportsSMP ghcStage
    
    121
    -    interpForceDyn      <- targetRTSLinkerOnlySupportsSharedLibs ghcStage
    
    122
    -
    
    123
    -    debugAssertions     <- ghcDebugAssertions <$> flavour <*> pure ghcStage
    
    124
    -    debugged            <- ghcDebugged        <$> flavour <*> pure ghcStage
    
    125
    -    profiled            <- ghcProfiled        <$> flavour <*> pure ghcStage
    
    114
    +    hasDynamic          <- wayUnit Dynamic . Context.Type.way <$> programContext stg ghc
    
    115
    +    leadingUnderscore   <- queryTargetTarget executableStage tgtSymbolsHaveLeadingUnderscore
    
    116
    +    withInterpreter     <- ghcWithInterpreter executableStage
    
    117
    +    unregisterised      <- queryTargetTarget executableStage tgtUnregisterised
    
    118
    +    tables_next_to_code <- queryTargetTarget executableStage tgtTablesNextToCode
    
    119
    +    targetWithSMP       <- targetSupportsSMP executableStage
    
    120
    +    interpForceDyn      <- targetRTSLinkerOnlySupportsSharedLibs executableStage
    
    121
    +
    
    122
    +    debugAssertions     <- ghcDebugAssertions <$> flavour <*> pure executableStage
    
    123
    +    debugged            <- ghcDebugged        <$> flavour <*> pure executableStage
    
    124
    +    profiled            <- ghcProfiled        <$> flavour <*> pure executableStage
    
    126 125
     
    
    127 126
         os          <- queryHostTarget queryOS
    
    128
    -    arch        <- queryTargetTarget ghcStage queryArch
    
    127
    +    arch        <- queryTargetTarget executableStage queryArch
    
    129 128
         let codegen_arches = ["x86_64", "i386", "powerpc", "powerpc64", "powerpc64le", "aarch64", "wasm32", "riscv64", "loongarch64"]
    
    130 129
         let withNativeCodeGen
    
    131 130
               | unregisterised = False
    
    132 131
               | arch `elem` codegen_arches = True
    
    133 132
               | otherwise = False
    
    134
    -    platform    <- queryTargetTarget ghcStage targetPlatformTriple
    
    135
    -    wordsize    <- show @Int . (*8) <$> queryTargetTarget ghcStage (wordSize2Bytes . tgtWordSize)
    
    133
    +    platform    <- queryTargetTarget executableStage targetPlatformTriple
    
    134
    +    wordsize    <- show @Int . (*8) <$> queryTargetTarget executableStage (wordSize2Bytes . tgtWordSize)
    
    136 135
     
    
    137
    -    llc_cmd   <- queryTargetTarget ghcStage tgtLlc
    
    138
    -    llvm_as_cmd <- queryTargetTarget ghcStage tgtLlvmAs
    
    136
    +    llc_cmd   <- queryTargetTarget executableStage tgtLlc
    
    137
    +    llvm_as_cmd <- queryTargetTarget executableStage tgtLlvmAs
    
    139 138
         let have_llvm = allowHaveLLVM arch && all isJust [llc_cmd, llvm_as_cmd]
    
    140 139
     
    
    141 140
         top         <- topDirectory
    
    142 141
     
    
    143 142
         pkgConfCacheFile <- System.FilePath.normalise . (top -/-)
    
    144
    -                    <$> (packageDbPath (PackageDbLoc pkgCacheStage Final) <&> (-/- "package.cache"))
    
    143
    +                    <$> (packageDbPath (PackageDbLoc libraryStage Final) <&> (-/- "package.cache"))
    
    145 144
         libdir           <- System.FilePath.normalise . (top -/-)
    
    146
    -                    <$> stageLibPath pkgCacheStage
    
    145
    +                    <$> stageLibPath libraryStage
    
    147 146
     
    
    148 147
         -- For this information, we need to query ghc --info, however, that would
    
    149 148
         -- require building ghc, which we don't want to do here. Therefore, the
    
    150 149
         -- logic from `platformHasRTSLinker` is duplicated here.
    
    151
    -    let rtsLinker = not $ arch `elem` ["powerpc", "powerpc64", "powerpc64le", "s390x", "loongarch64", "javascript"]
    
    150
    +    let rtsLinker = arch `notElem` ["powerpc", "powerpc64", "powerpc64le", "s390x", "loongarch64", "javascript"]
    
    152 151
     
    
    153 152
         return TestCompilerArgs{..}
    
    154 153