Magnus pushed to branch wip/mangoiv/ci-stages at Glasgow Haskell Compiler / GHC

Commits:

17 changed files:

Changes:

  • hadrian/hie-bios.bat

  • hadrian/src/Base.hs
    ... ... @@ -5,6 +5,7 @@
    5 5
     {-# LANGUAGE StandaloneDeriving #-}
    
    6 6
     {-# LANGUAGE StandaloneKindSignatures #-}
    
    7 7
     {-# LANGUAGE TypeOperators #-}
    
    8
    +{-# LANGUAGE MultiWayIf #-}
    
    8 9
     
    
    9 10
     module Base (
    
    10 11
         -- * General utilities
    
    ... ... @@ -22,6 +23,7 @@ module Base (
    22 23
         module Development.Shake.Util,
    
    23 24
     
    
    24 25
         Vec(..), (&%>),
    
    26
    +    exe,
    
    25 27
     
    
    26 28
         -- * Basic data types
    
    27 29
         module Hadrian.Package,
    
    ... ... @@ -57,7 +59,7 @@ import Development.Shake hiding (unit, (&%>), (*>), Normal)
    57 59
     #endif
    
    58 60
     import qualified Development.Shake as Shake
    
    59 61
     import Development.Shake.Classes
    
    60
    -import Development.Shake.FilePath
    
    62
    +import Development.Shake.FilePath hiding (exe)
    
    61 63
     import Development.Shake.Util
    
    62 64
     import Hadrian.Oracles.DirectoryContents
    
    63 65
     import Hadrian.Utilities
    
    ... ... @@ -67,6 +69,13 @@ import GHC.Stack ( HasCallStack )
    67 69
     
    
    68 70
     import Stage
    
    69 71
     import Way
    
    72
    +import GHC.Platform.ArchOS (ArchOS(..), Arch (..), OS (..))
    
    73
    +
    
    74
    +exe :: ArchOS -> FilePath
    
    75
    +exe arch
    
    76
    +  | ArchWasm32 <- archOS_arch arch = "wasm"
    
    77
    +  | OSMinGW32 <- archOS_OS arch = "exe"
    
    78
    +  | otherwise = ""
    
    70 79
     
    
    71 80
     -- | Hadrian lives in the 'hadrianPath' directory of the GHC tree.
    
    72 81
     hadrianPath :: FilePath
    

  • hadrian/src/Builder.hs
    ... ... @@ -15,7 +15,6 @@ import Control.Exception.Extra (Partial)
    15 15
     import qualified Data.ByteString.Lazy.Char8 as BSL
    
    16 16
     import Development.Shake.Classes
    
    17 17
     import Development.Shake.Command
    
    18
    -import Development.Shake.FilePath
    
    19 18
     import GHC.Generics
    
    20 19
     import GHC.Platform.ArchOS (ArchOS(..), Arch(..), OS(..))
    
    21 20
     import qualified Hadrian.Builder as H
    
    ... ... @@ -458,7 +457,7 @@ systemBuilderPath builder = case builder of
    458 457
     
    
    459 458
         -- Get program from a certain stage's target configuration
    
    460 459
         fromStageTC stage keyname key = do
    
    461
    -        path <- prgPath . key <$> targetStage stage
    
    460
    +        path <- prgPath . key <$> perStageTarget stage
    
    462 461
             validate keyname path
    
    463 462
     
    
    464 463
         validate keyname path = do
    
    ... ... @@ -479,7 +478,7 @@ systemBuilderPath builder = case builder of
    479 478
                 case (windowsHost, hasExtension fullPath) of
    
    480 479
                     (False, _    ) -> return path
    
    481 480
                     (True , True ) -> fixAbsolutePathOnWindows fullPath
    
    482
    -                (True , False) -> fixAbsolutePathOnWindows fullPath <&> (<.> exe)
    
    481
    +                (True , False) -> fixAbsolutePathOnWindows fullPath <&> (<.> exe (tgtArchOs target))
    
    483 482
     
    
    484 483
         -- Without this function, on Windows we can observe a bad builder path
    
    485 484
         -- for 'autoreconf'. If the relevant system.config field is set to
    

  • hadrian/src/Context.hs
    ... ... @@ -51,7 +51,7 @@ getWay = way <$> getContext
    51 51
     
    
    52 52
     -- | Get the 'Target' configuration of the current stage
    
    53 53
     getStagedTarget :: Expr Context b Target
    
    54
    -getStagedTarget = expr . targetStage =<< getStage
    
    54
    +getStagedTarget = expr . perStageTarget =<< getStage
    
    55 55
     
    
    56 56
     -- | Path to the directory containing the final artifact in a given 'Context'.
    
    57 57
     libPath :: Context -> Action FilePath
    

  • hadrian/src/Flavour.hs
    ... ... @@ -170,7 +170,7 @@ werror = addArgs $ do
    170 170
                 -- TODO: get rid of EFF_ altogether (#14647) and make sure
    
    171 171
                 -- unregisterised backend emits clean C without needing
    
    172 172
                 -- these hacks.
    
    173
    -          , queryTargetTarget stage tgtUnregisterised ? arg "-optc-Wno-error"
    
    173
    +          , queryPerStageTargetSpec stage tgtUnregisterised ? arg "-optc-Wno-error"
    
    174 174
               ]
    
    175 175
           -- N.B. We currently don't build the boot libraries' C sources with -Werror
    
    176 176
           -- as this tends to be a portability nightmare.
    

  • hadrian/src/Hadrian/Haskell/Hash.hs
    ... ... @@ -125,7 +125,7 @@ pkgHashOracle = void $ addOracleCache $ \(PkgHashKey (stag, pkg)) -> do
    125 125
       flav <- flavour
    
    126 126
       let flavourArgs = extraArgs flav
    
    127 127
     
    
    128
    -  targetOs       <- queryTargetTarget stag queryOS
    
    128
    +  targetOs       <- queryPerStageTargetSpec stag queryOS
    
    129 129
       projectVersion <- setting ProjectVersion
    
    130 130
       let pkgHashCompilerId = "ghc-" ++ projectVersion
    
    131 131
           pkgHashPlatform = targetOs
    

  • hadrian/src/Hadrian/Package.hs
    ... ... @@ -23,7 +23,7 @@ module Hadrian.Package (
    23 23
         ) where
    
    24 24
     
    
    25 25
     import Development.Shake.Classes
    
    26
    -import Development.Shake.FilePath
    
    26
    +import Development.Shake.FilePath ((<.>))
    
    27 27
     import GHC.Generics
    
    28 28
     
    
    29 29
     import Hadrian.Utilities
    

  • hadrian/src/Oracles/Flag.hs
    ... ... @@ -77,13 +77,13 @@ getFlag = expr . flag
    77 77
     
    
    78 78
     targetRTSLinkerOnlySupportsSharedLibs :: Stage -> Action Bool
    
    79 79
     targetRTSLinkerOnlySupportsSharedLibs s =
    
    80
    -  queryTargetTarget s Toolchain.tgtRTSLinkerOnlySupportsSharedLibs
    
    80
    +  queryPerStageTargetSpec s Toolchain.tgtRTSLinkerOnlySupportsSharedLibs
    
    81 81
     
    
    82 82
     arSupportsDashL :: Stage -> Action Bool
    
    83
    -arSupportsDashL stage = Toolchain.arSupportsDashL . tgtAr <$> targetStage stage
    
    83
    +arSupportsDashL stage = Toolchain.arSupportsDashL . tgtAr <$> perStageTarget stage
    
    84 84
     
    
    85 85
     arSupportsAtFile :: Stage -> Action Bool
    
    86
    -arSupportsAtFile stage = Toolchain.arSupportsAtFile . tgtAr <$> targetStage stage
    
    86
    +arSupportsAtFile stage = Toolchain.arSupportsAtFile . tgtAr <$> perStageTarget stage
    
    87 87
     
    
    88 88
     targetSupportsSharedLibs :: Stage -> Action Bool
    
    89 89
     targetSupportsSharedLibs stage = do
    
    ... ... @@ -101,10 +101,10 @@ targetSupportsThreadedRts stage = do
    101 101
     
    
    102 102
     -- | Does the target support the -N RTS flag?
    
    103 103
     targetSupportsSMP :: Stage -> Action Bool
    
    104
    -targetSupportsSMP stage = queryTargetTarget stage Toolchain.tgtSupportsSMP
    
    104
    +targetSupportsSMP stage = queryPerStageTargetSpec stage Toolchain.tgtSupportsSMP
    
    105 105
     
    
    106 106
     targetUseLibffiForAdjustors :: Stage -> Action Bool
    
    107
    -targetUseLibffiForAdjustors stage = queryTargetTarget stage tgtUseLibffiForAdjustors
    
    107
    +targetUseLibffiForAdjustors stage = queryPerStageTargetSpec stage tgtUseLibffiForAdjustors
    
    108 108
     
    
    109 109
     useLibdw :: Stage -> Action Bool
    
    110
    -useLibdw stage = queryTargetTarget stage (isJust . tgtRTSWithLibdw)
    110
    +useLibdw stage = queryPerStageTargetSpec stage (isJust . tgtRTSWithLibdw)

  • hadrian/src/Oracles/Setting.hs
    ... ... @@ -6,7 +6,7 @@ module Oracles.Setting (
    6 6
     
    
    7 7
         -- * Helpers
    
    8 8
         ghcCanonVersion, cmdLineLengthLimit, targetSupportsRPaths, topDirectory,
    
    9
    -    libsuf, ghcVersionStage, bashPath, targetStage, crossStage, queryTarget, queryTargetTarget,
    
    9
    +    libsuf, ghcVersionStage, bashPath, perStageTarget, crossStage, queryTarget, queryPerStageTargetSpec,
    
    10 10
         isHostStage,
    
    11 11
     
    
    12 12
         -- ** Target platform things
    
    ... ... @@ -153,7 +153,7 @@ isOsxTarget :: Stage -> Action Bool
    153 153
     isOsxTarget stage = anyTargetOs stage [OSDarwin]
    
    154 154
     
    
    155 155
     isArmTarget :: Stage -> Action Bool
    
    156
    -isArmTarget stage = queryTargetTarget stage (isARM . archOS_arch . tgtArchOs)
    
    156
    +isArmTarget stage = queryPerStageTargetSpec stage (isARM . archOS_arch . tgtArchOs)
    
    157 157
     
    
    158 158
     -- | Check whether the host OS setting matches one of the given strings.
    
    159 159
     anyHostOs :: [OS] -> Action Bool
    
    ... ... @@ -162,15 +162,15 @@ anyHostOs oss = (`elem` oss) <$> queryHostTarget (archOS_OS . tgtArchOs)
    162 162
     -- | Check whether the target architecture setting matches one of the given
    
    163 163
     -- strings.
    
    164 164
     anyTargetArch :: Stage -> [Arch] -> Action Bool
    
    165
    -anyTargetArch stage archs = (`elem` archs) <$> queryTargetTarget stage (archOS_arch . tgtArchOs)
    
    165
    +anyTargetArch stage archs = (`elem` archs) <$> queryPerStageTargetSpec stage (archOS_arch . tgtArchOs)
    
    166 166
     
    
    167 167
     -- | Check whether the target OS setting matches one of the given strings.
    
    168 168
     anyTargetOs :: Stage -> [OS] -> Action Bool
    
    169
    -anyTargetOs stage oss = (`elem` oss) <$> queryTargetTarget stage (archOS_OS . tgtArchOs)
    
    169
    +anyTargetOs stage oss = (`elem` oss) <$> queryPerStageTargetSpec stage (archOS_OS . tgtArchOs)
    
    170 170
     
    
    171 171
     -- | Check whether the target OS uses the ELF object format.
    
    172 172
     isElfTarget :: Stage -> Action Bool
    
    173
    -isElfTarget stage = queryTargetTarget stage (osElfTarget . archOS_OS . tgtArchOs)
    
    173
    +isElfTarget stage = queryPerStageTargetSpec stage (osElfTarget . archOS_OS . tgtArchOs)
    
    174 174
     
    
    175 175
     -- | Check whether the target OS supports the @-rpath@ linker option when
    
    176 176
     -- using dynamic linking.
    
    ... ... @@ -180,7 +180,7 @@ isElfTarget stage = queryTargetTarget stage (osElfTarget . archOS_OS . tgtArchOs
    180 180
     -- TODO: Windows supports lazy binding (but GHC doesn't currently support
    
    181 181
     --       dynamic way on Windows anyways).
    
    182 182
     targetSupportsRPaths :: Stage -> Action Bool
    
    183
    -targetSupportsRPaths stage = queryTargetTarget stage
    
    183
    +targetSupportsRPaths stage = queryPerStageTargetSpec stage
    
    184 184
                                     (\t -> let os = archOS_OS (tgtArchOs t)
    
    185 185
                                            in osElfTarget os || osMachOTarget os)
    
    186 186
     
    
    ... ... @@ -188,7 +188,7 @@ targetSupportsRPaths stage = queryTargetTarget stage
    188 188
     -- ARM)?
    
    189 189
     targetArmVersion :: Stage -> Action (Maybe ArmISA)
    
    190 190
     targetArmVersion stage = runMaybeT $ do
    
    191
    -    ArchARM isa _ _ <- lift $ queryTargetTarget stage (archOS_arch . tgtArchOs)
    
    191
    +    ArchARM isa _ _ <- lift $ queryPerStageTargetSpec stage (archOS_arch . tgtArchOs)
    
    192 192
         return isa
    
    193 193
     
    
    194 194
     -- | Canonicalised GHC version number, used for integer version comparisons. We
    
    ... ... @@ -231,33 +231,34 @@ libsuf st way
    231 231
             let suffix = waySuffix (removeWayUnit Dynamic way)
    
    232 232
             return (suffix ++ "-ghc" ++ version ++ extension)
    
    233 233
     
    
    234
    --- | Build libraries for this `Stage` targetting this `Target`
    
    234
    +-- | Determine the 'Target' that this 'Stage' is supposed to build libraries for.
    
    235 235
     --
    
    236
    --- For example, we want to build RTS with stage1 for the host target as we
    
    236
    +-- For example, we want to build RTS with stage1 for the host as we
    
    237 237
     -- produce a host executable with stage1 (which cross-compiles to stage2).
    
    238
    -targetStage :: Stage -> Action Target
    
    239
    -targetStage Stage0 {} = getHostTarget
    
    240
    -targetStage stage | isHostStage stage = do
    
    238
    +perStageTarget :: Stage -> Action Target
    
    239
    +perStageTarget Stage0 {} = getHostTarget
    
    240
    +perStageTarget stage | isHostStage stage = do
    
    241 241
        ht <- getHostTarget
    
    242 242
        tt <- getTargetTarget
    
    243 243
        if targetPlatformTriple ht == targetPlatformTriple tt
    
    244 244
          then return tt
    
    245 245
          else return ht
    
    246
    -targetStage _ = getTargetTarget
    
    246
    +perStageTarget _ = getTargetTarget
    
    247 247
     
    
    248 248
     isHostStage :: Stage -> Bool
    
    249 249
     isHostStage stage | stage <= Stage1 = True
    
    250 250
     isHostStage _ = False
    
    251 251
     
    
    252
    -queryTarget :: Stage -> (Target -> a) -> (Expr c b a)
    
    253
    -queryTarget s f = expr (f <$> targetStage s)
    
    252
    +queryTarget :: Stage -> (Target -> a) -> Expr c b a
    
    253
    +queryTarget s f = expr (f <$> perStageTarget s)
    
    254 254
     
    
    255
    -queryTargetTarget :: Stage -> (Target -> a) -> Action a
    
    256
    -queryTargetTarget s f = f <$> targetStage s
    
    255
    +-- | get the conentents of the .target file for the specified stage
    
    256
    +queryPerStageTargetSpec :: Stage -> (Target -> a) -> Action a
    
    257
    +queryPerStageTargetSpec s f = f <$> perStageTarget s
    
    257 258
     
    
    258 259
     -- | A 'Stage' is a cross-stage if the produced compiler is a cross-compiler.
    
    259 260
     crossStage :: Stage -> Action Bool
    
    260 261
     crossStage st = do
    
    261
    -  st_target <- targetStage (succStage st)
    
    262
    -  st_host   <- targetStage st
    
    262
    +  st_target <- perStageTarget (succStage st)
    
    263
    +  st_host   <- perStageTarget st
    
    263 264
       return (targetPlatformTriple st_target /= targetPlatformTriple st_host)

  • hadrian/src/Oracles/TestSettings.hs
    ... ... @@ -14,6 +14,7 @@ import Oracles.Setting (topDirectory, setting, ProjectSetting(..), crossStage)
    14 14
     import Packages
    
    15 15
     import Settings.Program (programContext)
    
    16 16
     import Hadrian.Oracles.Path
    
    17
    +import GHC.Toolchain (Target(tgtArchOs))
    
    17 18
     
    
    18 19
     testConfigFile :: Action FilePath
    
    19 20
     testConfigFile = buildRoot <&> (-/- "test/ghcconfig")
    
    ... ... @@ -154,10 +155,11 @@ getTestExePath testGhc pkg = do
    154 155
          bindir <- getBinaryDirectory testGhc
    
    155 156
          compiler_path <- getCompilerPath testGhc
    
    156 157
          cross <- getBooleanSetting TestCrossCompiling
    
    158
    +     tgt <- getTargetTarget -- FIXME: is this right -- ask rodrigo about the targettarget and query/get versions of this function
    
    157 159
          let cross_prefix = if cross then dropWhileEnd ((/=) '-') (takeFileName compiler_path) else ""
    
    158 160
          -- get relative path for the given program in the given stage
    
    159 161
          let make_absolute rel_path = do
    
    160 162
                abs_path <- liftIO (makeAbsolute rel_path)
    
    161 163
                fixAbsolutePathOnWindows abs_path
    
    162
    -     make_absolute (bindir </> (cross_prefix ++ programBasename pkg) <.> exe)
    
    164
    +     make_absolute (bindir </> (cross_prefix ++ programBasename pkg) <.> exe (tgtArchOs tgt))
    
    163 165
         -- get relative path for the given program in the given stage

  • hadrian/src/Packages.hs
    ... ... @@ -24,6 +24,8 @@ import Hadrian.Utilities
    24 24
     import Base
    
    25 25
     import Context.Type
    
    26 26
     import Oracles.Setting
    
    27
    +import GHC.Toolchain (tgtArchOs)
    
    28
    +import qualified Development.Shake.FilePath as Shake
    
    27 29
     
    
    28 30
     -- | These are all GHC packages we know about. Build rules will be generated for
    
    29 31
     -- all of them. However, not all of these packages will be built. For example,
    
    ... ... @@ -196,12 +198,13 @@ programPath :: Context -> Action FilePath
    196 198
     programPath context@Context {..} = do
    
    197 199
         name <- programName context
    
    198 200
         path <- stageBinPath stage
    
    199
    -    return $ path -/- name <.> exe
    
    201
    +    arch <- queryPerStageTargetSpec stage tgtArchOs
    
    202
    +    return $ path -/- name <.> exe arch
    
    200 203
     
    
    201 204
     -- TODO: Move @timeout@ to the @util@ directory and build in a more standard
    
    202 205
     -- location like other programs used only by the testsuite.
    
    203 206
     timeoutPath :: FilePath
    
    204
    -timeoutPath = "testsuite/timeout/install-inplace/bin/timeout" <.> exe
    
    207
    +timeoutPath = "testsuite/timeout/install-inplace/bin/timeout" <.> Shake.exe
    
    205 208
     
    
    206 209
     -- TODO: Can we extract this information from Cabal files?
    
    207 210
     -- | Some program packages should not be linked with Haskell main function.
    

  • hadrian/src/Rules/Generate.hs
    ... ... @@ -276,7 +276,7 @@ generateRules = do
    276 276
                           else prefix
    
    277 277
                     relPkgDb = makeRelativeNoSysLink libTopDir pkgDb
    
    278 278
                 go (generateSettings out True relPkgDb) out
    
    279
    -        (prefix -/- "targets" -/- "default.target") %> \out -> go (show <$> expr (targetStage (succStage stage))) out
    
    279
    +        (prefix -/- "targets" -/- "default.target") %> \out -> go (show <$> expr (perStageTarget (succStage stage))) out
    
    280 280
     
    
    281 281
       where
    
    282 282
         file <~+ gen = file %> \out -> generate out emptyTarget gen >> makeExecutable out
    
    ... ... @@ -447,7 +447,7 @@ bindistRules = do
    447 447
         , interpolateVar "TargetWordBigEndian" $ getTarget isBigEndian
    
    448 448
         , interpolateVar "TargetWordSize" $ getTarget wordSize
    
    449 449
         , interpolateVar "Unregisterised" $ yesNo <$> getTarget tgtUnregisterised
    
    450
    -    , interpolateVar "UseLibdw" $ fmap yesNo $ interp $ staged (fmap (isJust . tgtRTSWithLibdw) . targetStage)
    
    450
    +    , interpolateVar "UseLibdw" $ fmap yesNo $ interp $ staged (fmap (isJust . tgtRTSWithLibdw) . perStageTarget)
    
    451 451
         , interpolateVar "UseLibffiForAdjustors" $ yesNo <$> getTarget tgtUseLibffiForAdjustors
    
    452 452
         , interpolateVar "BaseUnitId" $ pkgUnitId Stage1 base
    
    453 453
         , interpolateVar "GhcWithSMP" $ yesNo <$> targetSupportsSMP Stage2
    
    ... ... @@ -536,7 +536,7 @@ generateConfigHs :: Expr String
    536 536
     generateConfigHs = do
    
    537 537
         stage <- getStage
    
    538 538
         let chooseSetting x y = case stage of { Stage0 {} -> x; _ -> y }
    
    539
    -    let queryTarget f = f <$> expr (targetStage stage)
    
    539
    +    let queryTarget f = f <$> expr (perStageTarget stage)
    
    540 540
         -- Not right for stage3
    
    541 541
         buildPlatform <- chooseSetting (queryBuild targetPlatformTriple) (queryHost targetPlatformTriple)
    
    542 542
         hostPlatform <- queryTarget targetPlatformTriple
    

  • hadrian/src/Rules/Program.hs
    ... ... @@ -9,7 +9,7 @@ import Base
    9 9
     import Context
    
    10 10
     import Expression hiding (stage, way)
    
    11 11
     import Oracles.ModuleFiles
    
    12
    -import Oracles.Setting (topDirectory)
    
    12
    +import Oracles.Setting (topDirectory, perStageTarget)
    
    13 13
     import Packages
    
    14 14
     import Settings
    
    15 15
     import Settings.Default
    
    ... ... @@ -18,6 +18,7 @@ import Target
    18 18
     import Utilities
    
    19 19
     import Rules.Library
    
    20 20
     import Rules.Register
    
    21
    +import GHC.Toolchain (Target(tgtArchOs))
    
    21 22
     
    
    22 23
     -- | TODO: Drop code duplication
    
    23 24
     buildProgramRules :: [(Resource, Int)] -> Rules ()
    
    ... ... @@ -49,13 +50,14 @@ getProgramContexts stage = do
    49 50
       -- 'Rules', because it is an 'Action' depending on an oracle.
    
    50 51
       sPackages <- filter isProgram <$> stagePackages stage
    
    51 52
       tPackages <- testsuitePackages
    
    53
    +  tgt <- perStageTarget stage
    
    52 54
       -- TODO: Shall we use Stage2 for testsuite packages instead?
    
    53 55
       let allPackages = sPackages
    
    54 56
                      ++ tPackages
    
    55 57
       forM allPackages $ \pkg -> do
    
    56 58
         ctx <- programContext stage pkg -- TODO: see todo on programContext.
    
    57 59
         name <- programName ctx
    
    58
    -    return (name <.> exe, ctx)
    
    60
    +    return (name <.> exe (tgtArchOs tgt), ctx)
    
    59 61
     
    
    60 62
     lookupProgramContext :: FilePath -> [(FilePath, Context)] -> Maybe Context
    
    61 63
     lookupProgramContext wholePath progs = lookup (takeFileName wholePath) progs
    

  • hadrian/src/Rules/Test.hs
    1
    +{-# LANGUAGE OverloadedRecordDot #-}
    
    1 2
     {-# OPTIONS_GHC -Wno-unused-top-binds #-}
    
    2 3
     module Rules.Test (testRules) where
    
    3 4
     
    
    ... ... @@ -22,58 +23,70 @@ import GHC.Toolchain as Toolchain
    22 23
     import GHC.Toolchain.Program as Toolchain
    
    23 24
     import Hadrian.Oracles.Path
    
    24 25
     import Hadrian.Oracles.TextFile (getHostTarget, getTargetTarget)
    
    26
    +import GHC.Platform.ArchOS (ArchOS (..), Arch (..), OS (..))
    
    25 27
     
    
    26
    -checkPprProgPath, checkPprSourcePath :: FilePath
    
    27
    -checkPprProgPath = "test/bin/check-ppr" <.> exe
    
    28
    +checkPprProgPath :: ArchOS -> FilePath
    
    29
    +checkPprProgPath archos = "test/bin/check-ppr" <.> exe archos
    
    30
    +checkPprSourcePath :: FilePath
    
    28 31
     checkPprSourcePath = "utils/check-ppr/Main.hs"
    
    29 32
     checkPprExtra :: [String]
    
    30 33
     checkPprExtra = []
    
    31 34
     
    
    32
    -checkExactProgPath, checkExactSourcePath :: FilePath
    
    33
    -checkExactProgPath = "test/bin/check-exact" <.> exe
    
    35
    +checkExactProgPath :: ArchOS -> FilePath
    
    36
    +checkExactProgPath archos = "test/bin/check-exact" <.> exe archos
    
    37
    +checkExactSourcePath :: FilePath
    
    34 38
     checkExactSourcePath = "utils/check-exact/Main.hs"
    
    35 39
     checkExactExtra :: [String]
    
    36 40
     checkExactExtra = ["-iutils/check-exact"]
    
    37 41
     
    
    38
    -countDepsProgPath, countDepsSourcePath :: FilePath
    
    39
    -countDepsProgPath = "test/bin/count-deps" <.> exe
    
    42
    +countDepsProgPath :: ArchOS -> FilePath
    
    43
    +countDepsProgPath archos = "test/bin/count-deps" <.> exe archos
    
    44
    +countDepsSourcePath :: FilePath
    
    40 45
     countDepsSourcePath = "utils/count-deps/Main.hs"
    
    41 46
     countDepsExtra :: [String]
    
    42 47
     countDepsExtra = ["-iutils/count-deps"]
    
    43 48
     
    
    44
    -dumpDeclsProgPath, dumpDeclsSourcePath :: FilePath
    
    45
    -dumpDeclsProgPath = "test/bin/dump-decls" <.> exe
    
    49
    +dumpDeclsProgPath :: ArchOS -> FilePath
    
    50
    +dumpDeclsProgPath archos = "test/bin/dump-decls" <.> exe archos
    
    51
    +dumpDeclsSourcePath :: FilePath
    
    46 52
     dumpDeclsSourcePath = "utils/dump-decls/Main.hs"
    
    47 53
     dumpDeclsExtra :: [String]
    
    48 54
     dumpDeclsExtra = []
    
    49 55
     
    
    50
    -noteLinterProgPath, noteLinterSourcePath :: FilePath
    
    51
    -noteLinterProgPath = "test/bin/lint-notes" <.> exe
    
    56
    +noteLinterProgPath :: ArchOS -> FilePath
    
    57
    +noteLinterProgPath archos = "test/bin/lint-notes" <.> exe archos
    
    58
    +noteLinterSourcePath :: FilePath
    
    52 59
     noteLinterSourcePath = "linters/lint-notes/Main.hs"
    
    53 60
     noteLinterExtra :: [String]
    
    54 61
     noteLinterExtra = ["-ilinters/lint-notes"]
    
    55 62
     
    
    56
    -codeLinterProgPath, codeLinterSourcePath :: FilePath
    
    57
    -codeLinterProgPath = "test/bin/lint-codes" <.> exe
    
    63
    +codeLinterProgPath :: ArchOS -> FilePath
    
    64
    +codeLinterProgPath archos = "test/bin/lint-codes" <.> exe archos
    
    65
    +codeLinterSourcePath :: FilePath
    
    58 66
     codeLinterSourcePath = "linters/lint-codes/Main.hs"
    
    59 67
     codeLinterExtra :: [String]
    
    60 68
     codeLinterExtra = ["-ilinters/lint-codes"]
    
    61 69
     
    
    62
    -whitespaceLinterProgPath, whitespaceLinterSourcePath :: FilePath
    
    63
    -whitespaceLinterProgPath = "test/bin/lint-whitespace" <.> exe
    
    70
    +whitespaceLinterProgPath :: ArchOS -> FilePath
    
    71
    +whitespaceLinterProgPath archos = "test/bin/lint-whitespace" <.> exe archos
    
    72
    +whitespaceLinterSourcePath :: FilePath
    
    64 73
     whitespaceLinterSourcePath = "linters/lint-whitespace/Main.hs"
    
    65 74
     whitespaceLinterExtra :: [String]
    
    66 75
     whitespaceLinterExtra = ["-ilinters/lint-whitespace", "-ilinters/linters-common"]
    
    67 76
     
    
    68
    -changelogDProgPath, changelogDSourcePath :: FilePath
    
    69
    -changelogDProgPath = "test/bin/changelog-d" <.> exe
    
    77
    +changelogDProgPath :: ArchOS -> FilePath
    
    78
    +changelogDProgPath archos = "test/bin/changelog-d" <.> exe archos
    
    79
    +changelogDSourcePath :: FilePath
    
    70 80
     changelogDSourcePath = "utils/changelog-d/ChangelogD.hs"
    
    71 81
     changelogDExtra :: [String]
    
    72 82
     changelogDExtra = ["-iutils/changelog-d"]
    
    73 83
     
    
    74 84
     data CheckProgram =
    
    75 85
             CheckProgram { cp_target :: String -- ^ Name for the hadrian target
    
    76
    -                     , cp_exe_path :: FilePath -- ^ Path to resulting executable
    
    86
    +                     , cp_exe_path :: ArchOS -> FilePattern
    
    87
    +                        -- ^ Path to resulting executable.
    
    88
    +                        -- This depends on the taret the program is built for,
    
    89
    +                        -- not the host that hadrian is built on
    
    77 90
                          , cp_src_path :: FilePath -- ^ Source to the Main.hs for the executable
    
    78 91
                          , cp_extra_args :: [String] -- ^ Any extra arguments to use when compiling Main.hs
    
    79 92
                          , cp_hadrian_pkg :: Package -- ^ How to build the executable when using in-tree compiler.
    
    ... ... @@ -83,16 +96,16 @@ data CheckProgram =
    83 96
     
    
    84 97
     checkPrograms :: [CheckProgram]
    
    85 98
     checkPrograms =
    
    86
    -    [ CheckProgram "test:check-ppr" checkPprProgPath checkPprSourcePath checkPprExtra checkPpr id id
    
    87
    -    , CheckProgram "test:check-exact" checkExactProgPath checkExactSourcePath checkExactExtra checkExact id id
    
    88
    -    , CheckProgram "test:count-deps" countDepsProgPath countDepsSourcePath countDepsExtra countDeps id id
    
    89
    -    , CheckProgram "test:dump-decls" dumpDeclsProgPath dumpDeclsSourcePath dumpDeclsExtra dumpDecls id id
    
    90
    -    , CheckProgram "lint:notes" noteLinterProgPath  noteLinterSourcePath  noteLinterExtra  lintNotes  (const stage0Boot)  id
    
    91
    -    , CheckProgram "lint:codes" codeLinterProgPath  codeLinterSourcePath  codeLinterExtra  lintCodes  id id
    
    92
    -    , CheckProgram "lint:whitespace"  whitespaceLinterProgPath  whitespaceLinterSourcePath  whitespaceLinterExtra  lintWhitespace  (const stage0Boot)  (filter (/= lintersCommon))
    
    99
    +    [ CheckProgram { cp_target = "test:check-ppr", cp_exe_path = checkPprProgPath, cp_src_path = checkPprSourcePath, cp_extra_args = checkPprExtra, cp_hadrian_pkg = checkPpr, cp_modify_stage = id, cp_modify_deps = id }
    
    100
    +    , CheckProgram { cp_target = "test:check-exact", cp_exe_path = checkExactProgPath, cp_src_path = checkExactSourcePath, cp_extra_args = checkExactExtra, cp_hadrian_pkg = checkExact, cp_modify_stage = id, cp_modify_deps = id }
    
    101
    +    , CheckProgram { cp_target = "test:count-deps", cp_exe_path = countDepsProgPath, cp_src_path = countDepsSourcePath, cp_extra_args = countDepsExtra, cp_hadrian_pkg = countDeps, cp_modify_stage = id, cp_modify_deps = id }
    
    102
    +    , CheckProgram { cp_target = "test:dump-decls", cp_exe_path = dumpDeclsProgPath, cp_src_path = dumpDeclsSourcePath, cp_extra_args = dumpDeclsExtra, cp_hadrian_pkg = dumpDecls, cp_modify_stage = id, cp_modify_deps = id }
    
    103
    +    , CheckProgram { cp_target = "lint:notes", cp_exe_path = noteLinterProgPath, cp_src_path = noteLinterSourcePath, cp_extra_args = noteLinterExtra, cp_hadrian_pkg = lintNotes, cp_modify_stage = (const stage0Boot), cp_modify_deps = id }
    
    104
    +    , CheckProgram { cp_target = "lint:codes", cp_exe_path = codeLinterProgPath, cp_src_path = codeLinterSourcePath, cp_extra_args = codeLinterExtra, cp_hadrian_pkg = lintCodes, cp_modify_stage = id, cp_modify_deps = id }
    
    105
    +    , CheckProgram { cp_target = "lint:whitespace", cp_exe_path = whitespaceLinterProgPath, cp_src_path = whitespaceLinterSourcePath, cp_extra_args = whitespaceLinterExtra, cp_hadrian_pkg = lintWhitespace, cp_modify_stage = (const stage0Boot), cp_modify_deps = (filter (/= lintersCommon)) }
    
    93 106
         -- N.B. The lint:changelog build is replicated by lint_changelog in
    
    94 107
         -- .gitlab/ci.sh. Keep its package dependencies in sync with this target.
    
    95
    -    , CheckProgram "lint:changelog"  changelogDProgPath  changelogDSourcePath  changelogDExtra  changelogD  (const stage0Boot)  id
    
    108
    +    , CheckProgram { cp_target = "lint:changelog", cp_exe_path = changelogDProgPath, cp_src_path = changelogDSourcePath, cp_extra_args = changelogDExtra, cp_hadrian_pkg = changelogD, cp_modify_stage = (const stage0Boot), cp_modify_deps = id }
    
    96 109
         ]
    
    97 110
     
    
    98 111
     inTreeOutTree :: (Stage -> Action b) -> Action b -> Action b
    
    ... ... @@ -136,12 +149,23 @@ testRules = do
    136 149
     
    
    137 150
         testsuiteDeps
    
    138 151
     
    
    152
    +    -- the test targets will all be compiled by the test comppiler which is going
    
    153
    +    -- to produce artifacts for its target
    
    154
    +
    
    139 155
         -- Rules for building check-ppr, check-exact and
    
    140 156
         -- check-ppr-annotations with the compiler we are going to test
    
    141 157
         -- (in-tree or out-of-tree).
    
    142
    -    forM_ checkPrograms $ \(CheckProgram name progPath sourcePath mextra progPkg mod_stage mod_pkgs) -> do
    
    143
    -        name ~> need [root -/- progPath]
    
    144
    -        root -/- progPath %> \path -> do
    
    158
    +    forM_ checkPrograms $ \(CheckProgram name progPathForArch sourcePath mextra progPkg mod_stage mod_pkgs) -> do
    
    159
    +        name ~> do
    
    160
    +          tt <- getTargetTarget
    
    161
    +          need [root -/- progPathForArch (tgtArchOs tt)]
    
    162
    +
    
    163
    +        -- HACK: we don't havea program path here and just a pattern
    
    164
    +        -- because we can't query the target before declaring the rule.
    
    165
    +        -- we specify target arch linux (no extension), then append a pattern
    
    166
    +        -- for any extension
    
    167
    +        let filePat = progPathForArch ArchOS { archOS_arch = ArchUnknown, archOS_OS = OSLinux } <> "*"
    
    168
    +        root -/- filePat %> \path -> do
    
    145 169
                 need [ sourcePath ]
    
    146 170
                 testGhc <- testCompiler <$> userSetting defaultTestArgs
    
    147 171
     
    
    ... ... @@ -167,7 +191,7 @@ testRules = do
    167 191
                          | targetPlatformTriple ht /= targetPlatformTriple tt = targetPlatform ++ "-" ++ prog
    
    168 192
                          | otherwise = prog
    
    169 193
                     let dynPrograms = hasDynamic test_args
    
    170
    -                cmd [bindir </> mkGhcProg "ghc" <.> exe] $ -- FIXME: needs proper prefix!
    
    194
    +                cmd [bindir </> mkGhcProg "ghc" <.> exe (tgtArchOs ht)] $
    
    171 195
                         concatMap (\p -> ["-package", pkgName p]) depsPkgs ++
    
    172 196
                         ["-o", top -/- path, top -/- sourcePath] ++
    
    173 197
                         mextra ++
    
    ... ... @@ -243,8 +267,12 @@ testEnv stg = do
    243 267
         top             <- topDirectory
    
    244 268
         pythonPath      <- builderPath Python
    
    245 269
         -- MP: TODO wrong, should use the ccPath and ccFlags from the bindist we are testing.
    
    246
    -    ccPath          <- queryTargetTarget stg (Toolchain.prgPath . Toolchain.ccProgram . Toolchain.tgtCCompiler)
    
    247
    -    ccFlags         <- queryTargetTarget stg (unwords . Toolchain.prgFlags . Toolchain.ccProgram . Toolchain.tgtCCompiler)
    
    270
    +    tgt <- queryPerStageTargetSpec stg id
    
    271
    +    let ccPath = tgt.tgtCCompiler.ccProgram.prgPath
    
    272
    +    let ccFlags = unwords tgt.tgtCCompiler.ccProgram.prgFlags
    
    273
    +    let archos = tgt.tgtArchOs
    
    274
    +    let mkProgPath k = top -/- root -/- k archos
    
    275
    +
    
    248 276
         ghcFlags        <- runTestGhcFlags stg
    
    249 277
         let ghciFlags = ghcFlags ++ unwords
    
    250 278
               [ "--interactive", "-v0", "-ignore-dot-ghci"
    
    ... ... @@ -262,14 +290,14 @@ testEnv stg = do
    262 290
           , "TEST_HC_OPTS_INTERACTIVE" .= ghciFlags
    
    263 291
           , "TEST_CC" .= ccPath
    
    264 292
           , "TEST_CC_OPTS" .= ccFlags
    
    265
    -      , "CHECK_PPR" .= (top -/- root -/- checkPprProgPath)
    
    266
    -      , "CHECK_EXACT" .= (top -/- root -/- checkExactProgPath)
    
    267
    -      , "DUMP_DECLS" .= (top -/- root -/- dumpDeclsProgPath)
    
    268
    -      , "COUNT_DEPS" .= (top -/- root -/- countDepsProgPath)
    
    269
    -      , "LINT_NOTES" .= (top -/- root -/- noteLinterProgPath)
    
    270
    -      , "LINT_CODES" .= (top -/- root -/- codeLinterProgPath)
    
    271
    -      , "LINT_WHITESPACE" .= (top -/- root -/- whitespaceLinterProgPath)
    
    272
    -      , "CHANGELOG_D" .= (top -/- root -/- changelogDProgPath)
    
    293
    +      , "CHECK_PPR" .= mkProgPath checkPprProgPath
    
    294
    +      , "CHECK_EXACT" .= mkProgPath checkExactProgPath
    
    295
    +      , "DUMP_DECLS" .= mkProgPath dumpDeclsProgPath
    
    296
    +      , "COUNT_DEPS" .= mkProgPath countDepsProgPath
    
    297
    +      , "LINT_NOTES" .= mkProgPath noteLinterProgPath
    
    298
    +      , "LINT_CODES" .= mkProgPath codeLinterProgPath
    
    299
    +      , "LINTstageWHITESPACE" .= mkProgPath whitespaceLinterProgPath
    
    300
    +      , "CHANGELOG_D" .= mkProgPath changelogDProgPath
    
    273 301
           -- This lets us bypass the need to generate a config
    
    274 302
           -- through Make, which happens in testsuite/mk/boilerplate.mk
    
    275 303
           -- which is in turn included by all test 'Makefile's.
    

  • hadrian/src/Settings/Builders/DeriveConstants.hs
    ... ... @@ -42,8 +42,8 @@ includeCcArgs = do
    42 42
         stage <- getStage
    
    43 43
         rtsPath <- expr $ rtsBuildPath stage
    
    44 44
         mconcat [ cWarnings
    
    45
    -            , prgFlags . ccProgram . tgtCCompiler <$> expr (targetStage stage)
    
    46
    -            , queryTargetTarget stage tgtUnregisterised ? arg "-DUSE_MINIINTERPRETER"
    
    45
    +            , prgFlags . ccProgram . tgtCCompiler <$> expr (perStageTarget stage)
    
    46
    +            , queryPerStageTargetSpec stage tgtUnregisterised ? arg "-DUSE_MINIINTERPRETER"
    
    47 47
                 , arg "-Irts"
    
    48 48
                 , arg "-Irts/include"
    
    49 49
                 , arg $ "-I" ++ rtsPath </> "include"
    

  • hadrian/src/Settings/Builders/RunTest.hs
    1 1
     {-# LANGUAGE TypeApplications #-}
    
    2
    +{-# LANGUAGE NamedFieldPuns #-}
    
    2 3
     module Settings.Builders.RunTest (runTestBuilderArgs
    
    3 4
                                      , runTestGhcFlags
    
    4 5
                                      , assertSameCompilerArgs
    
    ... ... @@ -27,7 +28,7 @@ import GHC.Toolchain.Target
    27 28
     -- | Extra flags to send to the Haskell compiler to run tests.
    
    28 29
     runTestGhcFlags :: Stage -> Action String
    
    29 30
     runTestGhcFlags stage = do
    
    30
    -    unregisterised <- queryTargetTarget stage tgtUnregisterised
    
    31
    +    unregisterised <- queryPerStageTargetSpec stage tgtUnregisterised
    
    31 32
     
    
    32 33
         let ifMinGhcVer ver opt = do v <- ghcCanonVersion
    
    33 34
                                      if ver <= v then pure opt
    
    ... ... @@ -112,10 +113,10 @@ inTreeCompilerArgs stg = do
    112 113
           ways <- interpretInContext (vanillaContext ghcStage rts) getRtsWays
    
    113 114
           return (dynamic `elem` ways, threaded `elem` ways)
    
    114 115
         hasDynamic          <- (wayUnit Dynamic) . Context.Type.way <$> (programContext stg ghc)
    
    115
    -    leadingUnderscore   <- queryTargetTarget ghcStage tgtSymbolsHaveLeadingUnderscore
    
    116
    +    leadingUnderscore   <- queryPerStageTargetSpec ghcStage tgtSymbolsHaveLeadingUnderscore
    
    116 117
         withInterpreter     <- ghcWithInterpreter ghcStage
    
    117
    -    unregisterised      <- queryTargetTarget ghcStage tgtUnregisterised
    
    118
    -    tables_next_to_code <- queryTargetTarget ghcStage tgtTablesNextToCode
    
    118
    +    unregisterised      <- queryPerStageTargetSpec ghcStage tgtUnregisterised
    
    119
    +    tables_next_to_code <- queryPerStageTargetSpec ghcStage tgtTablesNextToCode
    
    119 120
         targetWithSMP       <- targetSupportsSMP ghcStage
    
    120 121
         interpForceDyn      <- targetRTSLinkerOnlySupportsSharedLibs ghcStage
    
    121 122
     
    
    ... ... @@ -124,17 +125,17 @@ inTreeCompilerArgs stg = do
    124 125
         profiled            <- ghcProfiled        <$> flavour <*> pure ghcStage
    
    125 126
     
    
    126 127
         os          <- queryHostTarget queryOS
    
    127
    -    arch        <- queryTargetTarget ghcStage queryArch
    
    128
    +    arch        <- queryPerStageTargetSpec ghcStage queryArch
    
    128 129
         let codegen_arches = ["x86_64", "i386", "powerpc", "powerpc64", "powerpc64le", "aarch64", "wasm32", "riscv64", "loongarch64"]
    
    129 130
         let withNativeCodeGen
    
    130 131
               | unregisterised = False
    
    131 132
               | arch `elem` codegen_arches = True
    
    132 133
               | otherwise = False
    
    133
    -    platform    <- queryTargetTarget ghcStage targetPlatformTriple
    
    134
    -    wordsize    <- show @Int . (*8) <$> queryTargetTarget ghcStage (wordSize2Bytes . tgtWordSize)
    
    134
    +    platform    <- queryPerStageTargetSpec ghcStage targetPlatformTriple
    
    135
    +    wordsize    <- show @Int . (*8) <$> queryPerStageTargetSpec ghcStage (wordSize2Bytes . tgtWordSize)
    
    135 136
     
    
    136
    -    llc_cmd   <- queryTargetTarget ghcStage tgtLlc
    
    137
    -    llvm_as_cmd <- queryTargetTarget ghcStage tgtLlvmAs
    
    137
    +    llc_cmd   <- queryPerStageTargetSpec ghcStage tgtLlc
    
    138
    +    llvm_as_cmd <- queryPerStageTargetSpec ghcStage tgtLlvmAs
    
    138 139
         let have_llvm = allowHaveLLVM arch && all isJust [llc_cmd, llvm_as_cmd]
    
    139 140
     
    
    140 141
         top         <- topDirectory
    
    ... ... @@ -231,6 +232,8 @@ runTestBuilderArgs = builder Testsuite ? do
    231 232
     
    
    232 233
         keepFiles <- expr (testKeepFiles <$> userSetting defaultTestArgs)
    
    233 234
     
    
    235
    +    tgtArchOs <- expr $ queryPerStageTargetSpec stage tgtArchOs
    
    236
    +
    
    234 237
         accept <- expr (testAccept <$> userSetting defaultTestArgs)
    
    235 238
         (acceptPlatform, acceptOS) <- expr . liftIO $
    
    236 239
             (,) <$> (maybe False (=="YES") <$> lookupEnv "PLATFORM")
    
    ... ... @@ -266,7 +269,7 @@ runTestBuilderArgs = builder Testsuite ? do
    266 269
                 , arg "-e", arg $ "config.accept=" ++ show accept
    
    267 270
                 , arg "-e", arg $ "config.accept_platform=" ++ show acceptPlatform
    
    268 271
                 , arg "-e", arg $ "config.accept_os=" ++ show acceptOS
    
    269
    -            , arg "-e", arg $ "config.exeext=" ++ quote (if null exe then "" else "."<>exe)
    
    272
    +            , arg "-e", arg $ "config.exeext=" ++ quote ("" <.> exe tgtArchOs)
    
    270 273
                 , arg "-e", arg $ "config.compiler_debugged=" ++ show debugAssertions
    
    271 274
                 , arg "-e", arg $ "config.debug_rts=" ++ show debugged
    
    272 275
     
    

  • hadrian/src/Settings/Packages.hs
    ... ... @@ -295,8 +295,8 @@ rtsPackageArgs = package rts ? do
    295 295
         path           <- getBuildPath
    
    296 296
         top            <- expr topDirectory
    
    297 297
         useSystemFfi   <- succStaged (buildFlag UseSystemFfi)
    
    298
    -    libdwIncludeDir   <- staged (\s -> queryTargetTarget s (Lib.includePath <=< tgtRTSWithLibdw))
    
    299
    -    libdwLibraryDir   <- staged (\s -> queryTargetTarget s (Lib.libraryPath <=< tgtRTSWithLibdw))
    
    298
    +    libdwIncludeDir   <- staged (\s -> queryPerStageTargetSpec s (Lib.includePath <=< tgtRTSWithLibdw))
    
    299
    +    libdwLibraryDir   <- staged (\s -> queryPerStageTargetSpec s (Lib.libraryPath <=< tgtRTSWithLibdw))
    
    300 300
         libnumaIncludeDir <- staged (buildSetting LibnumaIncludeDir)
    
    301 301
         libnumaLibraryDir <- staged (buildSetting LibnumaLibDir)
    
    302 302
         libzstdIncludeDir <- staged (buildSetting LibZstdIncludeDir)
    
    ... ... @@ -412,7 +412,7 @@ rtsPackageArgs = package rts ? do
    412 412
               , buildFlag UseLibnuma stage        `cabalFlag` "libnuma"
    
    413 413
               , buildFlag UseLibzstd stage        `cabalFlag` "libzstd"
    
    414 414
               , buildFlag StaticLibzstd stage     `cabalFlag` "static-libzstd"
    
    415
    -          , queryTargetTarget stage tgtSymbolsHaveLeadingUnderscore `cabalFlag` "leading-underscore"
    
    415
    +          , queryPerStageTargetSpec stage tgtSymbolsHaveLeadingUnderscore `cabalFlag` "leading-underscore"
    
    416 416
               , ghcUnreg                          `cabalFlag` "unregisterised"
    
    417 417
               , ghcEnableTNC                      `cabalFlag` "tables-next-to-code"
    
    418 418
               ]