Sven Tennie pushed to branch wip/supersven/hadrian-cross-stage3 at Glasgow Haskell Compiler / GHC

Commits:

2 changed files:

Changes:

  • hadrian/src/Rules/BinaryDist.hs
    ... ... @@ -267,12 +267,8 @@ buildBinDistDir root conf@BindistConfig{..} = do
    267 267
         --
    
    268 268
         -- N.B. the ghc-pkg executable may be prefixed with a target triple
    
    269 269
         -- (c.f. #20267).
    
    270
    -    -- Recache using the stage1 ghc-pkg executable. This is the unprefixed
    
    271
    -    -- host ghc-pkg for native bindists and the target-triple-prefixed cross
    
    272
    -    -- ghc-pkg for cross bindists; both run on the build host and can handle
    
    273
    -    -- the target package database. The stage3 bindist's package DB is also
    
    274
    -    -- built by the stage1 cross compiler, so stage1 ghc-pkg is correct there
    
    275
    -    -- too.
    
    270
    +    -- Stage1 is also correct for cross-compiler scenarios, because it runs on
    
    271
    +    -- the build host.
    
    276 272
         ghcPkgPath <- programPath =<< programContext Stage1 ghcPkg
    
    277 273
         cmd_ ghcPkgPath ["recache", "--package-db", bindistFilesDir -/- "lib" -/- "package.conf.d" ]
    
    278 274
     
    
    ... ... @@ -370,6 +366,7 @@ bindistRules = do
    370 366
           buildBinDistDir root cfg
    
    371 367
     
    
    372 368
         phony "binary-dist-dir-cross" $ buildBinDistDir root crossBindist
    
    369
    +
    
    373 370
         phony "binary-dist-dir-stage3" $ buildBinDistDir root targetBindist
    
    374 371
     
    
    375 372
         let buildBinDist compressor = do
    
    ... ... @@ -411,7 +408,7 @@ bindistRules = do
    411 408
               need [distribConfigure]
    
    412 409
               copyFile distribConfigure configurePath
    
    413 410
     
    
    414
    -      -- Generate the Makefile that enables the "make install" part
    
    411
    +      -- Copy the Makefile that enables the "make install" part
    
    415 412
           root -/- bindistFolderName -/- "ghc-*" -/- "Makefile" %> \makefilePath -> do
    
    416 413
               top <- topDirectory
    
    417 414
               copyFile (top -/- "hadrian" -/- "bindist" -/- "Makefile") makefilePath
    

  • hadrian/src/Rules/Generate.hs
    ... ... @@ -25,7 +25,6 @@ import Utilities
    25 25
     import GHC.Toolchain as Toolchain hiding (HsCpp(HsCpp))
    
    26 26
     import GHC.Platform.ArchOS
    
    27 27
     import Settings.Program (ghcWithInterpreter)
    
    28
    -import UserSettings (finalStage)
    
    29 28
     
    
    30 29
     -- | Track this file to rebuild generated files whenever it changes.
    
    31 30
     trackGenerateHs :: Expr ()
    
    ... ... @@ -252,51 +251,30 @@ generateRules = do
    252 251
         (root -/- "ghc-stage2") <~+ ghcWrapper Stage2
    
    253 252
         (root -/- "ghc-stage3") <~+ ghcWrapper Stage3
    
    254 253
     
    
    255
    -    forM_ allStages $ \buildStage -> do
    
    256
    -        let -- Two stages are in play per rule iteration:
    
    257
    -            --
    
    258
    -            --   * @buildStage@    — loop variable; the settings file is written
    
    259
    -            --                      into @_build/<buildStage>/lib/settings@ and
    
    260
    -            --                      describes the compiler at @compilerStage@.
    
    261
    -            --   * @compilerStage@ — the stage whose @bin/@ holds the compiler
    
    262
    -            --                      the settings file describes; also the
    
    263
    -            --                      ambient 'Expr' stage passed to
    
    264
    -            --                      'generateSettings' (via 'semiEmptyTarget'),
    
    265
    -            --                      so it is the value of @executableStage@
    
    266
    -            --                      inside that function.
    
    267
    -            --
    
    268
    -            -- For a cross-compiler the libs it links against live in the
    
    269
    -            -- /successor/ stage's lib dir; @libraryStage@ (computed in the
    
    270
    -            -- rule body below) is that successor. @compilerStage@ normally
    
    271
    -            -- equals @buildStage@, but at @finalStage@ there is no successor
    
    272
    -            -- to hold its libs, so @compilerStage@ drops to the predecessor
    
    273
    -            -- (the final stage's lib dir merely hosts the predecessor
    
    274
    -            -- cross-compiler's target-arch libs).
    
    275
    -            compilerStage = if buildStage == finalStage
    
    276
    -                              then predStage buildStage
    
    277
    -                              else buildStage
    
    278
    -            prefix = root -/- stageString buildStage -/- "lib"
    
    254
    +    forM_ allStages $ \compilerStage -> do
    
    255
    +        let
    
    256
    +            prefix = root -/- stageString compilerStage -/- "lib"
    
    279 257
                 go gen file = generate file (semiEmptyTarget compilerStage) gen
    
    280 258
             (prefix -/- "settings") %> \out -> do
    
    281 259
                 -- Stage0 has no library or package DB of its own (the
    
    282 260
                 -- bootstrapping compiler uses Stage1's); for any other stage the
    
    283 261
                 -- package DB lives where the LibDir redirect points (this stage's
    
    284
    -            -- own lib dir, or the successor's when @buildStage@ is a cross
    
    262
    +            -- own lib dir, or the successor's when @compilerStage@ is a cross
    
    285 263
                 -- stage).
    
    286
    -            isCross <- crossStage buildStage
    
    287
    -            let libraryStage = case buildStage of
    
    264
    +            isCross <- crossStage compilerStage
    
    265
    +            let libraryStage = case compilerStage of
    
    288 266
                         Stage0 {} -> Stage1
    
    289
    -                    _         -> if isCross then succStage buildStage else buildStage
    
    267
    +                    _         -> if isCross then succStage compilerStage else compilerStage
    
    290 268
                 pkgDb <- packageDbPath (PackageDbLoc libraryStage Final)
    
    291 269
                 -- addTrailingPathSeparator needed: makeRelativeNoSysLink uses
    
    292 270
                 -- splitPath where "lib" and "lib/" are distinct components.
    
    293 271
                 let libTopDir = addTrailingPathSeparator $
    
    294
    -                    if isStage0 buildStage
    
    272
    +                    if isStage0 compilerStage
    
    295 273
                           then prefix
    
    296 274
                           else root -/- stageString libraryStage -/- "lib"
    
    297 275
                     relPkgDb = makeRelativeNoSysLink libTopDir pkgDb
    
    298 276
                 go (generateSettings out True relPkgDb libraryStage) out
    
    299
    -        (prefix -/- "targets" -/- "default.target") %> \out -> go (show <$> expr (targetStage (succStage buildStage))) out
    
    277
    +        (prefix -/- "targets" -/- "default.target") %> \out -> go (show <$> expr (targetStage (succStage compilerStage))) out
    
    300 278
     
    
    301 279
       where
    
    302 280
         file <~+ gen = file %> \out -> generate out emptyTarget gen >> makeExecutable out
    
    ... ... @@ -610,13 +588,10 @@ generateSettings settingsFile includeLibDir rel_pkg_db libraryStage = do
    610 588
               , ("Use interpreter", expr $ yesNo <$> ghcWithInterpreter executableStage)
    
    611 589
               -- Advertise the RTS ways that will actually ship with the compiler
    
    612 590
               -- described by this settings file, i.e. the ways the @libraryStage@
    
    613
    -          -- RTS is built with. Cabal queries this to decide which library ways
    
    614
    -          -- the compiler supports (see
    
    615
    -          -- 'Distribution.Simple.Compiler.waySupported'); under-advertising
    
    616
    -          -- causes Cabal to silently drop flags like
    
    617
    -          -- @--enable-profiling-shared@.
    
    591
    +          -- RTS is built with.
    
    618 592
               -- The settings file is regenerated at install time when installing a bindist.
    
    619
    -          , ("RTS ways", unwords . map show . Set.toList <$> expr (interpretInContext (vanillaContext libraryStage rts) getRtsWays))
    
    593
    +          , ("RTS ways", unwords . map show . Set.toList <$>
    
    594
    +              expr (interpretInContext (vanillaContext libraryStage rts) getRtsWays))
    
    620 595
               , ("Relative Global Package DB", pure rel_pkg_db)
    
    621 596
               , ("base unit-id", pure base_unit_id)
    
    622 597
               ]