Sven Tennie pushed to branch wip/supersven/hadrian-cross-stage3 at Glasgow Haskell Compiler / GHC Commits: b1e9280d by GHC GitLab CI at 2026-10-10T18:27:27+02:00 Fix intepreter settings for native target bindists Stage3 cross-compiled bindists wrongly assumed they cannot run the interpreter natively. Fix this by adjusting compile flags and choosing the correct libs/target/default.target files per compiler stage. - - - - - 4 changed files: - .gitlab/ci.sh - hadrian/src/Rules/BinaryDist.hs - hadrian/src/Rules/Generate.hs - hadrian/src/Settings/Packages.hs Changes: ===================================== .gitlab/ci.sh ===================================== @@ -701,7 +701,20 @@ function smoke_test() { info "Smoke-testing stage3 compiler..." file "$stage3_ghc" - run ${CROSS_EMULATOR} "$stage3_ghc" --info + run ${CROSS_EMULATOR} "$stage3_ghc" --info > stage3-info + cat stage3-info + + # The stage3 compiler is a native target compiler: it must not consider + # itself a cross-compiler, and GHCi support must be compiled in when the + # target supports it. + grep -q '"cross compiling","NO"' stage3-info \ + || fail "stage3 compiler reports itself as cross-compiling" + + if grep -q '"Use interpreter","YES"' stage3-info; then + echo 'ghci works' > ghci-expected + ${CROSS_EMULATOR:-} "$stage3_ghc" -e 'putStrLn "ghci works"' > ghci-actual + run diff -w ghci-expected ghci-actual + fi run ${CROSS_EMULATOR} "$stage3_ghc" -package ghc "$TOP/.gitlab/hello.hs" -o hello-stage3 ===================================== hadrian/src/Rules/BinaryDist.hs ===================================== @@ -70,6 +70,13 @@ These are the steps to build a bindist: to <build root>/<bindist-dir>/ghc-<X>.<Y>.<Z>-<arch>-<os>/lib +- for cross-compilers, overwrite the implicitly copied (previous step) + <build root>/<library-stage-dir>/lib/targets/default.target file with that of + the executable stage. I.e. copy: + <build root>/<executable-stage-dir>/lib/targets/default.target + to + <build root>/<bindist-dir>/ghc-<X>.<Y>.<Z>-<arch>-<os>/lib/targets/default.target + - copy the generated docs (user guide, haddocks, etc): <build root>/doc/ to @@ -248,6 +255,13 @@ buildBinDistDir root conf@BindistConfig{..} = do copyDirectory (ghcBuildDir -/- "lib") bindistFilesDir + -- For cross-compilers we need to override the `targets/default.target` + -- file that was implicitly copied from the library stage, because this + -- describes a target native compiler (stage3) and not a cross-compiler. + when (library_stage /= executable_stage) $ + copyFile (root -/- stageString executable_stage -/- "lib" -/- "targets" -/- "default.target") + (bindistFilesDir -/- "lib" -/- "targets" -/- "default.target") + -- Regenerate settings file without LibDir. For bindists, LibDir should -- be derived from topdir at runtime such that the GHC binary is -- relocatable. The package DB is always at "package.conf.d" relative to ===================================== hadrian/src/Rules/Generate.hs ===================================== @@ -276,11 +276,21 @@ generateRules = do else root -/- stageString libraryStage -/- "lib" relPkgDb = makeRelativeNoSysLink libTopDir pkgDb go (generateSettings out True relPkgDb libraryStage) out - (prefix -/- "targets" -/- "default.target") %> \out -> go (show <$> expr (targetStage (succStage compilerStage))) out + (prefix -/- "targets" -/- "default.target") %> \out -> + go (generateTargetFile compilerStage) out where file <~+ gen = file %> \out -> generate out emptyTarget gen >> makeExecutable out + generateTargetFile :: Stage -> Expr String + generateTargetFile compilerStage = do + isCrossStage <- if compilerStage < Stage3 + then expr (crossStage compilerStage) + else pure False + let libraryStage = if isCrossStage then succStage compilerStage else compilerStage + tgt <- expr (targetStage libraryStage) + pure $ show tgt { tgtLocallyExecutable = not isCrossStage } + -- TODO: Use the Types, Luke! (drop partial function) -- We sometimes need to evaluate expressions that do not require knowing all -- information about the context. In this case, we don't want to know anything. ===================================== hadrian/src/Settings/Packages.hs ===================================== @@ -112,8 +112,11 @@ packageArgs = do , compilerStageOption ghcDebugAssertions ? arg "-DDEBUG" ] , builder (Cabal Flags) ? mconcat - [ andM [expr (ghcWithInterpreter stage), orM [expr (notM cross), stage1]] `cabalFlag` "interpreter" - , andM [expr (ghcWithInterpreter stage), notM (expr cross)] `cabalFlag` "internal-interpreter" + -- In the context of cross-compilation, stage2 runs on the target + -- and thus can - if the architecture supports it - provide the + -- interpreter natively. + [ andM [expr (ghcWithInterpreter stage), orM [expr (notM cross), stage1, stage2]] `cabalFlag` "interpreter" + , andM [expr (ghcWithInterpreter stage), orM [expr (notM cross), stage2]] `cabalFlag` "internal-interpreter" , ifM stage0 -- We build a threaded stage 1 if the bootstrapping compiler -- supports it. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b1e9280d8a20203ee0d498cda2b81cea... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b1e9280d8a20203ee0d498cda2b81cea... You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
participants (1)
-
Sven Tennie (@supersven)