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

Commits:

3 changed files:

Changes:

  • distrib/configure.ac.in
    ... ... @@ -9,7 +9,7 @@ AC_INIT([The Glorious Glasgow Haskell Compilation System], [@ProjectVersion@], [
    9 9
     dnl See /configure.ac for rationale.
    
    10 10
     AC_PREREQ([2.69])
    
    11 11
     
    
    12
    -AC_CONFIG_MACRO_DIRS([m4])
    
    12
    +AC_CONFIG_MACRO_DIRS([../m4])
    
    13 13
     
    
    14 14
     dnl--------------------------------------------------------------------
    
    15 15
     dnl * Deal with arguments telling us gmp is somewhere odd
    

  • 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, shPath, targetStage, crossStage, queryTarget, queryTargetTarget,
    
    9
    +    libsuf, ghcVersionStage, shPath, targetStage, crossStage, libraryStageFor, queryTarget, queryTargetTarget,
    
    10 10
         isHostStage,
    
    11 11
     
    
    12 12
         -- ** Target platform things
    
    ... ... @@ -261,3 +261,22 @@ crossStage st = do
    261 261
       st_target <- targetStage (succStage st)
    
    262 262
       st_host   <- targetStage st
    
    263 263
       return (targetPlatformTriple st_target /= targetPlatformTriple st_host)
    
    264
    +
    
    265
    +-- | The 'Stage' whose libraries and package database are used by a compiler
    
    266
    +-- built at (or running from) @compilerStage@.
    
    267
    +--
    
    268
    +-- Usually @compilerStage@ itself, but differs in two cases:
    
    269
    +--
    
    270
    +--  * 'Stage0' has no library or package database of its own; it uses 'Stage1'\'s.
    
    271
    +--  * A cross compiler uses the successor compilerStage's libraries (built for the
    
    272
    +--    target, not the host).
    
    273
    +libraryStageFor :: Stage -> Action Stage
    
    274
    +libraryStageFor compilerStage = do
    
    275
    +  isCross <-
    
    276
    +    if compilerStage < Stage3
    
    277
    +      then
    
    278
    +        crossStage compilerStage
    
    279
    +      else return False
    
    280
    +  return $ case compilerStage of
    
    281
    +    Stage0 {} -> Stage1
    
    282
    +    _ -> if isCross then succStage compilerStage else compilerStage

  • hadrian/src/Rules/Generate.hs
    ... ... @@ -256,18 +256,7 @@ generateRules = do
    256 256
                 prefix = root -/- stageString compilerStage -/- "lib"
    
    257 257
                 go gen file = generate file (semiEmptyTarget compilerStage) gen
    
    258 258
             (prefix -/- "settings") %> \out -> do
    
    259
    -            -- @compilerStage@ is the stage that builds the compiler, i.e. the
    
    260
    -            -- binary whose settings these are; @libraryStage@ is the stage
    
    261
    -            -- whose libraries and package DB that compiler uses. The two
    
    262
    -            -- differ in two cases: Stage0 has no library or package DB of its
    
    263
    -            -- own (the bootstrapping compiler uses Stage1's), and cross
    
    264
    -            -- stages use the successor stage's libraries (a cross compiler
    
    265
    -            -- requires libs from the successor stage, otherwise they are
    
    266
    -            -- compiled for the host and not the target).
    
    267
    -            isCross <- crossStage compilerStage
    
    268
    -            let libraryStage = case compilerStage of
    
    269
    -                    Stage0 {} -> Stage1
    
    270
    -                    _         -> if isCross then succStage compilerStage else compilerStage
    
    259
    +            libraryStage <- libraryStageFor compilerStage
    
    271 260
                 pkgDb <- packageDbPath (PackageDbLoc libraryStage Final)
    
    272 261
                 -- addTrailingPathSeparator needed: makeRelativeNoSysLink uses
    
    273 262
                 -- splitPath where "lib" and "lib/" are distinct components.
    
    ... ... @@ -288,9 +277,7 @@ generateRules = do
    288 277
             isCrossStage <- if compilerStage < Stage3
    
    289 278
                               then expr (crossStage compilerStage)
    
    290 279
                               else pure False
    
    291
    -        let libraryStage = case compilerStage of
    
    292
    -                Stage0 {} -> Stage1
    
    293
    -                _         -> if isCrossStage then succStage compilerStage else compilerStage
    
    280
    +        libraryStage <- expr (libraryStageFor compilerStage)
    
    294 281
             tgt <- expr (targetStage libraryStage)
    
    295 282
             pure $ show tgt { tgtLocallyExecutable = not isCrossStage }
    
    296 283
     
    
    ... ... @@ -505,24 +492,36 @@ bindistRules = do
    505 492
           , crossStageInterps
    
    506 493
           ]
    
    507 494
     
    
    508
    -  -- We can build two kinds of bindists: Regular Stage2 (including
    
    509
    -  -- cross-compilers) and fully cross-compiled Stage3. To avoid
    
    510
    -  -- race-conditions, stale files, etc. build the `configure` scripts as part
    
    511
    -  -- of the stage's _build files. This requires copying several files such that
    
    512
    -  -- they are available to the autoconf run.
    
    495
    +  -- Note [Bindist configure autoconf srcdir]
    
    496
    +  -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    497
    +  -- We can build binary distributions for several stages. These may need
    
    498
    +  -- different `configure` scripts. To avoid race-conditions on temporary
    
    499
    +  -- autoconf files (including `configure`), we generate those in the stages'
    
    500
    +  -- dedicated build folders (`_build/<stage>`).
    
    501
    +  --
    
    502
    +  -- The generated `configure.ac` lives in `_build/<stage>/distrib`, while the
    
    503
    +  -- m4 macros are one level up in _build/<stage>/m4. This mirrors the
    
    504
    +  -- repository layout, where `distrib/configure.ac.in` refers to the macros
    
    505
    +  -- via AC_CONFIG_MACRO_DIRS([../m4]) (i.e. the repository's top-level `m4/`).
    
    506
    +  -- Keeping the same relative layout means the template needs no change.
    
    507
    +  --
    
    508
    +  -- We deliberately do *not* copy the top-level `aclocal.m4`: its m4_include
    
    509
    +  -- directives are relative to the directory aclocal first ran in. Instead we
    
    510
    +  -- run autoreconf next to the staged `configure.ac` and let aclocal pick the
    
    511
    +  -- macro directory up from its AC_CONFIG_MACRO_DIRS([../m4]), regenerating
    
    512
    +  -- `aclocal.m4` with `../m4/...` includes that resolve from there.
    
    513
    +  --
    
    514
    +  -- The other copied files need to be present for autoconf and/or autoreconf.
    
    513 515
       forM_ [Stage1, Stage2] $ \stage -> do
    
    514
    -    let distribDir = root -/- stageString stage -/- "distrib"
    
    515
    -
    
    516
    -    distribDir -/- "aclocal.m4" %> \out -> do
    
    517
    -      top <- topDirectory
    
    518
    -      copyFile (top -/- "aclocal.m4") out
    
    516
    +    let stageDir   = root -/- stageString stage
    
    517
    +        distribDir = stageDir -/- "distrib"
    
    519 518
     
    
    520 519
         forM_ ["config.sub", "config.guess", "install-sh"] $ \f ->
    
    521 520
           distribDir -/- f %> \out -> do
    
    522 521
             top <- topDirectory
    
    523 522
             copyFile (top -/- f) out
    
    524 523
     
    
    525
    -    distribDir -/- "m4/*.m4" %> \out -> do
    
    524
    +    stageDir -/- "m4/*.m4" %> \out -> do
    
    526 525
           top <- topDirectory
    
    527 526
           copyFile (top -/- "m4" -/- takeFileName out) out
    
    528 527
     
    
    ... ... @@ -533,9 +532,8 @@ bindistRules = do
    533 532
                  , distribDir -/- "config.sub"
    
    534 533
                  , distribDir -/- "config.guess"
    
    535 534
                  , distribDir -/- "install-sh"
    
    536
    -             , distribDir -/- "aclocal.m4"
    
    537 535
                  ]
    
    538
    -           ++ [ distribDir -/- "m4" -/- takeFileName f | f <- m4Files ]
    
    536
    +           ++ [ stageDir -/- "m4" -/- takeFileName f | f <- m4Files ]
    
    539 537
     
    
    540 538
           -- Note [Autoreconf unix paths from ACLOCAL_PATH]
    
    541 539
           -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    ... ... @@ -556,12 +554,12 @@ bindistRules = do
    556 554
         interp = interpretInContext (semiEmptyTarget Stage2)
    
    557 555
         getTarget stage = interp . queryTarget stage
    
    558 556
         getLibTarget executableStage f = do
    
    559
    -      isCross <- crossStage executableStage
    
    560
    -      getTarget (if isCross then succStage executableStage else executableStage) f
    
    557
    +      libStage <- libraryStageFor executableStage
    
    558
    +      getTarget libStage f
    
    561 559
         -- | 'targetSupportsSMP' lifted to the library stage (see 'getLibTarget').
    
    562 560
         libStageSupportsSMP stage = do
    
    563
    -      isCross <- crossStage stage
    
    564
    -      targetSupportsSMP (if isCross then succStage stage else stage)
    
    561
    +      libStage <- libraryStageFor stage
    
    562
    +      targetSupportsSMP libStage
    
    565 563
         -- | The unit id of @pkg@ in the stage whose libraries ship with the
    
    566 564
         -- bindist, i.e. the library stage of the implicit bindist config. For
    
    567 565
         -- cross compilers these are the target-architecture unit ids, as