[Git][ghc/ghc][master] 3 commits: Hadrian: fix detection of ghc-pkg for cross-compilers

Marge Bot gitlab at gitlab.haskell.org
Sat Nov 28 20:40:31 UTC 2020



 Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
75fc1ed5 by Sylvain Henry at 2020-11-28T15:40:23-05:00
Hadrian: fix detection of ghc-pkg for cross-compilers

- - - - -
7cb5df96 by Sylvain Henry at 2020-11-28T15:40:23-05:00
hadrian: fix ghc-pkg uses (#17601)

Make sure ghc-pkg doesn't read the compiler "settings" file by passing
--no-user-package-db.

- - - - -
e3fd4226 by Ben Gamari at 2020-11-28T15:40:23-05:00
gitlab-ci: Introduce a nightly cross-compilation job

This adds a job to test cross-compilation from x86-64 to AArch64 with
Hadrian.

Fixes #18234

- - - - -


4 changed files:

- .gitlab-ci.yml
- .gitlab/ci.sh
- hadrian/src/Hadrian/Oracles/Cabal/Rules.hs
- hadrian/src/Settings/Builders/GhcPkg.hs


Changes:

=====================================
.gitlab-ci.yml
=====================================
@@ -257,6 +257,33 @@ validate-x86_64-linux-deb9-unreg-hadrian:
     CONFIGURE_ARGS: --enable-unregisterised
     TEST_ENV: "x86_64-linux-deb9-unreg-hadrian"
 
+validate-x86_64-linux-deb10-hadrian-cross-aarch64:
+  <<: *nightly
+  extends: .validate-linux-hadrian
+  stage: full-build
+  image: "registry.gitlab.haskell.org/ghc/ci-images/x86_64-linux-deb10:$DOCKER_REV"
+  variables:
+    BIN_DIST_NAME: "ghc-x86_64-deb9-linux"
+  rules:
+    - if: '$CI_MERGE_REQUEST_LABELS =~ /.*cross-compilation.*/'
+  variables:
+    CONFIGURE_ARGS: --with-intree-gmp
+    CROSS_TARGET: "aarch64-linux-gnu"
+
+nightly-x86_64-linux-deb10-hadrian-cross-aarch64:
+  <<: *nightly
+  extends: .validate-linux-hadrian
+  stage: full-build
+  variables:
+    CONFIGURE_ARGS: --with-intree-gmp
+    CROSS_TARGET: "aarch64-linux-gnu"
+
+
+
+############################################################
+# GHC-in-GHCi (Hadrian)
+############################################################
+
 hadrian-ghc-in-ghci:
   stage: quick-build
   needs: [lint-linters, lint-submods]


=====================================
.gitlab/ci.sh
=====================================
@@ -40,9 +40,9 @@ Hadrian build system
   build_hadrian Build GHC via the Hadrian build system
   test_hadrian  Test GHC via the Hadrian build system
 
-
 Environment variables affecting both build systems:
 
+  CROSS_TARGET      Triple of cross-compilation target.
   VERBOSE           Set to non-empty for verbose build output
   MSYSTEM           (Windows-only) Which platform to build form (MINGW64 or MINGW32).
 
@@ -111,11 +111,11 @@ function setup_locale() {
 function mingw_init() {
   case "$MSYSTEM" in
     MINGW32)
-      triple="i386-unknown-mingw32"
+      target_triple="i386-unknown-mingw32"
       boot_triple="i386-unknown-mingw32" # triple of bootstrap GHC
       ;;
     MINGW64)
-      triple="x86_64-unknown-mingw32"
+      target_triple="x86_64-unknown-mingw32"
       boot_triple="x86_64-unknown-mingw32" # triple of bootstrap GHC
       ;;
     *)
@@ -378,8 +378,8 @@ function configure() {
   end_section "booting"
 
   local target_args=""
-  if [[ -n "$triple" ]]; then
-    target_args="--target=$triple"
+  if [[ -n "$target_triple" ]]; then
+    target_args="--target=$target_triple"
   fi
 
   start_section "configuring"
@@ -430,6 +430,11 @@ function determine_metric_baseline() {
 }
 
 function test_make() {
+  if [ -n "$CROSS_TARGET" ]; then
+    info "Can't test cross-compiled build."
+    return
+  fi
+
   run "$MAKE" test_bindist TEST_PREP=YES
   run "$MAKE" V=0 test \
     THREADS="$cores" \
@@ -450,6 +455,11 @@ function build_hadrian() {
 }
 
 function test_hadrian() {
+  if [ -n "$CROSS_TARGET" ]; then
+    info "Can't test cross-compiled build."
+    return
+  fi
+
   cd _build/bindist/ghc-*/
   run ./configure --prefix="$TOP"/_build/install
   run "$MAKE" install
@@ -537,6 +547,11 @@ case "$(uname)" in
   *) fail "uname $(uname) is not supported" ;;
 esac
 
+if [ -n "$CROSS_TARGET" ]; then
+  info "Cross-compiling for $CROSS_TARGET..."
+  target_triple="$CROSS_TARGET"
+fi
+
 set_toolchain_paths
 
 case $1 in


=====================================
hadrian/src/Hadrian/Oracles/Cabal/Rules.hs
=====================================
@@ -59,12 +59,20 @@ cabalOracle = do
                ++ quote (pkgName pkg) ++ " (" ++ show stage ++ ")..."
         -- Configure the package with the GHC corresponding to the given stage
         hcPath <- builderPath (Ghc CompileHs stage)
+        hcPkgPath <- builderPath (GhcPkg undefined stage)
+        -- N.B. the hcPath parameter of `configure` is broken when given an
+        -- empty ProgramDb. To work around this we manually construct an
+        -- appropriate ProgramDb.
+        --
+        -- We also need to pass the path to ghc-pkg, because Cabal cannot
+        -- guess it (from ghc's path) when it's for a cross-compiler (e.g.,
+        -- _build/stage0/bin/aarch64-linux-gnu-ghc-pkg).
         let progDb = userSpecifyPath "ghc" hcPath
-                     $ addKnownProgram ghcProgram emptyProgramDb
+                     $ addKnownProgram ghcProgram
+                     $ userSpecifyPath "ghc-pkg" hcPkgPath
+                     $ addKnownProgram ghcPkgProgram
+                     $ emptyProgramDb
         (compiler, maybePlatform, _pkgdb) <- liftIO $
-            -- N.B. the hcPath parameter of `configure` is broken when given an
-            -- empty ProgramDb. To work around this we manually construct an
-            -- appropriate ProgramDb.
             configure silent Nothing Nothing progDb
         let platform = fromMaybe (error msg) maybePlatform
             msg      = "PackageConfiguration oracle: cannot detect platform"


=====================================
hadrian/src/Settings/Builders/GhcPkg.hs
=====================================
@@ -8,8 +8,7 @@ ghcPkgBuilderArgs = mconcat
         verbosity <- expr getVerbosity
         stage     <- getStage
         pkgDb     <- expr $ packageDbPath stage
-        mconcat [ arg "--global-package-db"
-                , arg pkgDb
+        mconcat [ use_db pkgDb
                 , arg "register"
                 , verbosity < Chatty ? arg "-v0"
                 ]
@@ -17,8 +16,7 @@ ghcPkgBuilderArgs = mconcat
         verbosity <- expr getVerbosity
         stage     <- getStage
         pkgDb     <- expr $ packageDbPath stage
-        mconcat [ arg "--global-package-db"
-                , arg pkgDb
+        mconcat [ use_db pkgDb
                 , arg "unregister"
                 , arg "--force"
                 , verbosity < Chatty ? arg "-v0"
@@ -29,10 +27,30 @@ ghcPkgBuilderArgs = mconcat
         config    <- expr $ pkgInplaceConfig context
         stage     <- getStage
         pkgDb     <- expr $ packageDbPath stage
-        mconcat [ notStage0 ? arg "--global-package-db"
-                , notStage0 ? arg pkgDb
+        mconcat [ notStage0 ? use_db pkgDb
                 , arg "update"
                 , arg "--force"
                 , verbosity < Chatty ? arg "-v0"
                 , bootPackageDatabaseArgs
                 , arg config ] ]
+    where
+        use_db db = mconcat
+            -- We use ghc-pkg's --global-package-db to manipulate our databases.
+            -- We can't use --package-db (at least with stage0's ghc-pkg)
+            -- because units in stage0's global package db would be in scope and
+            -- ghc-pkg would disallow us the register a second "rts" unit in our
+            -- database.
+            --
+            -- However ghc-pkg uses the path to the global package db to find
+            -- the compiler "settings" file... So when it finds our newly
+            -- generated settings file in _build/stageN, it may crash if it
+            -- isn't the format it expects (#17601).
+            --
+            -- By chance, ghc-pkg only needs the "settings" file to query the
+            -- arch/os to generate the path to the user package db, which we
+            -- don't need.  So we disable it below to avoid failures.
+            [ arg "--no-user-package-db"
+            , arg "--global-package-db"
+            , arg db
+            ]
+



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/a1a75aa9be2c133dd1372a08eeb6a92c31688df7...e3fd4226a08ac6cd4abe9f25f764e518de66834a

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/a1a75aa9be2c133dd1372a08eeb6a92c31688df7...e3fd4226a08ac6cd4abe9f25f764e518de66834a
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20201128/1e1db54c/attachment-0001.html>


More information about the ghc-commits mailing list