[Git][ghc/ghc][master] 3 commits: packaging: correctly propagate build/host/target to bindist configure script
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 4a45a7da by Matthew Pickering at 2026-04-08T04:37:29-04:00 packaging: correctly propagate build/host/target to bindist configure script At the moment the host and target which we will produce a compiler for is fixed at the initial configure time. Therefore we need to persist the choice made at this time into the installation bindist as well so we look for the right tools, with the right prefixes at install time. In the future, we want to provide a bit more control about what kind of bindist we produce so the logic about what the host/target will have to be written by hadrian rather than persisted by the configure script. In particular with cross compilers we want to either build a normal stage 2 cross bindist or a stage 3 bindist, which creates a bindist which has a native compiler for the target platform. Fixes #21970 Co-authored-by: Sven Tennie <sven.tennie@gmail.com> - - - - - b0950df6 by Sven Tennie at 2026-04-08T04:37:29-04:00 Cross --host and --target no longer required for cross (#21970) We set sane defaults in the configure script. Thus, these paramenters aren't required any longer. - - - - - fef35216 by Sven Tennie at 2026-04-08T04:37:30-04:00 ci: Define USER_CONF_CC_OPTS_STAGE2 for aarch64/mingw ghc-toolchain doesn't see $CONF_CC_OPTS_STAGE2 when the bindist gets configured. So, the hack to override the compiler gets lost. - - - - - 11 changed files: - .gitlab/ci.sh - .gitlab/generate-ci/gen_ci.hs - .gitlab/jobs.yaml - configure.ac - distrib/configure.ac.in - hadrian/cfg/system.config.in - hadrian/src/Oracles/Setting.hs - hadrian/src/Rules/Generate.hs - hadrian/src/Settings/Default.hs - m4/fptools_set_platform_vars.m4 - m4/ghc_toolchain.m4 Changes: ===================================== .gitlab/ci.sh ===================================== @@ -628,20 +628,6 @@ function install_bindist() { *) read -r -a args <<< "${INSTALL_CONFIGURE_ARGS:-}" - if [[ "${CROSS_TARGET:-no_cross_target}" =~ "mingw" ]]; then - # We suppose that host target = build target. - # By the fact above it is clearly turning out which host value is - # for currently built compiler. - # The fix for #21970 will probably remove this if-branch. - local -r CROSS_HOST_GUESS=$($SHELL ./config.guess) - args+=( "--target=$CROSS_TARGET" "--host=$CROSS_HOST_GUESS" ) - - # FIXME: The bindist configure script shouldn't need to be reminded of - # the target platform. See #21970. - elif [ -n "${CROSS_TARGET:-}" ]; then - args+=( "--target=$CROSS_TARGET" "--host=$CROSS_TARGET" ) - fi - run ${CONFIGURE_WRAPPER:-} ./configure \ --prefix="$instdir" \ "${args[@]+"${args[@]}"}" || fail "bindist configure failed" ===================================== .gitlab/generate-ci/gen_ci.hs ===================================== @@ -1316,6 +1316,13 @@ cross_jobs = [ -- unexpected triple. . setVariable "CFLAGS" cflags . setVariable "CONF_CC_OPTS_STAGE2" cflags + -- For bindists `$USER_CONF_CC_OPTS_STAGE2` is not automatically set + -- to `$CONF_CC_OPTS_STAGE2`. But, we still have to deal with the hack + -- mentioned in the previous comment. + -- + -- TODO: It would be nice to get rid of this hack. This would probably + -- involve setting the toolchain up in a different way. + . setVariable "USER_CONF_CC_OPTS_STAGE2" cflags ) where llvm_prefix = "/opt/llvm-mingw-linux/bin/aarch64-w64-mingw32-" cflags = "-fuse-ld=" ++ llvm_prefix ++ "ld --rtlib=compiler-rt" ===================================== .gitlab/jobs.yaml ===================================== @@ -331,6 +331,7 @@ "STRINGS": "/opt/llvm-mingw-linux/bin/aarch64-w64-mingw32-strings", "STRIP": "/opt/llvm-mingw-linux/bin/aarch64-w64-mingw32-strip", "TEST_ENV": "aarch64-linux-deb12-wine-int_native-cross_aarch64-unknown-mingw32-validate", + "USER_CONF_CC_OPTS_STAGE2": "-fuse-ld=/opt/llvm-mingw-linux/bin/aarch64-w64-mingw32-ld --rtlib=compiler-rt", "WindresCmd": "/opt/llvm-mingw-linux/bin/aarch64-w64-mingw32-windres" } }, @@ -412,6 +413,7 @@ "STRINGS": "/opt/llvm-mingw-linux/bin/aarch64-w64-mingw32-strings", "STRIP": "/opt/llvm-mingw-linux/bin/aarch64-w64-mingw32-strip", "TEST_ENV": "aarch64-linux-deb12-wine-int_native-cross_aarch64-unknown-mingw32-validate+llvm", + "USER_CONF_CC_OPTS_STAGE2": "-fuse-ld=/opt/llvm-mingw-linux/bin/aarch64-w64-mingw32-ld --rtlib=compiler-rt", "WindresCmd": "/opt/llvm-mingw-linux/bin/aarch64-w64-mingw32-windres" } }, @@ -1123,6 +1125,7 @@ "STRINGS": "/opt/llvm-mingw-linux/bin/aarch64-w64-mingw32-strings", "STRIP": "/opt/llvm-mingw-linux/bin/aarch64-w64-mingw32-strip", "TEST_ENV": "aarch64-linux-deb12-wine-int_native-cross_aarch64-unknown-mingw32-validate", + "USER_CONF_CC_OPTS_STAGE2": "-fuse-ld=/opt/llvm-mingw-linux/bin/aarch64-w64-mingw32-ld --rtlib=compiler-rt", "WindresCmd": "/opt/llvm-mingw-linux/bin/aarch64-w64-mingw32-windres", "XZ_OPT": "-9" } @@ -1205,6 +1208,7 @@ "STRINGS": "/opt/llvm-mingw-linux/bin/aarch64-w64-mingw32-strings", "STRIP": "/opt/llvm-mingw-linux/bin/aarch64-w64-mingw32-strip", "TEST_ENV": "aarch64-linux-deb12-wine-int_native-cross_aarch64-unknown-mingw32-validate+llvm", + "USER_CONF_CC_OPTS_STAGE2": "-fuse-ld=/opt/llvm-mingw-linux/bin/aarch64-w64-mingw32-ld --rtlib=compiler-rt", "WindresCmd": "/opt/llvm-mingw-linux/bin/aarch64-w64-mingw32-windres", "XZ_OPT": "-9" } ===================================== configure.ac ===================================== @@ -255,6 +255,7 @@ if test "${WithGhc}" != "" then bootstrap_host=`"${WithGhc}" --info | grep '^ ,("Host platform"' | sed -e 's/.*,"//' -e 's/")//' | tr -d '\r'` bootstrap_target=`"${WithGhc}" --info | grep '^ ,("Target platform"' | sed -e 's/.*,"//' -e 's/")//' | tr -d '\r'` + bootstrap_build="$bootstrap_host" if test "$bootstrap_host" != "$bootstrap_target" then echo "Bootstrapping GHC is a cross compiler. This probably isn't going to work" @@ -394,8 +395,33 @@ then else TargetPlatformFull="${target_alias}" fi + +if test -z "${build_alias}" +then + # --target wasn't given; use result from AC_CANONICAL_TARGET + BuildPlatformFull="${build}" +else + BuildPlatformFull="${build_alias}" +fi +if test -z "${host_alias}" +then + # --target wasn't given; use result from AC_CANONICAL_TARGET + HostPlatformFull="${host}" +else + HostPlatformFull="${host_alias}" +fi +if test "$CrossCompiling" = "YES" +then + # Use value passed by user from --target= + CrossCompilePrefix="${TargetPlatformFull}-" +else + CrossCompilePrefix="" +fi + AC_SUBST(CrossCompiling) AC_SUBST(TargetPlatformFull) +AC_SUBST(BuildPlatformFull) +AC_SUBST(HostPlatformFull) dnl ** Which gcc to use? dnl -------------------------------------------------------------- ===================================== distrib/configure.ac.in ===================================== @@ -15,7 +15,18 @@ dnl-------------------------------------------------------------------- dnl * Deal with arguments telling us gmp is somewhere odd dnl-------------------------------------------------------------------- +build_alias=@BuildPlatformFull@ +host_alias=@HostPlatformFull@ +target_alias=@TargetPlatformFull@ + +dnl this makes sure `./configure --target=<cross-compile-target>` +dnl works as expected, since we're slightly modifying how Autoconf +dnl interprets build/host/target and how this interacts with $CC tests +test -n "$target_alias" && ac_tool_prefix=$target_alias- + dnl Various things from the source distribution configure +bootstrap_build=@BuildPlatform@ +bootstrap_host=@HostPlatform@ bootstrap_target=@TargetPlatform@ bootstrap_llvm_target=@LlvmTarget@ ===================================== hadrian/cfg/system.config.in ===================================== @@ -50,6 +50,9 @@ use-ghc-toolchain = @EnableGhcToolchain@ # And we can reconstruct the platform info using targetPlatformTriple # Q: What is TargetPlatformFull? target-platform-full = @TargetPlatformFull@ +build-platform-full = @BuildPlatformFull@ +host-platform-full = @HostPlatformFull@ + cross-compiling = @CrossCompiling@ ===================================== hadrian/src/Oracles/Setting.hs ===================================== @@ -69,6 +69,8 @@ data Setting = CursesIncludeDir | ProjectPatchLevel2 | SystemGhc | TargetPlatformFull + | BuildPlatformFull + | HostPlatformFull | BourneShell | EmsdkVersion @@ -107,6 +109,8 @@ setting key = lookupSystemConfig $ case key of ProjectPatchLevel2 -> "project-patch-level2" SystemGhc -> "system-ghc" TargetPlatformFull -> "target-platform-full" + BuildPlatformFull -> "build-platform-full" + HostPlatformFull -> "host-platform-full" BourneShell -> "bourne-shell" EmsdkVersion -> "emsdk-version" ===================================== hadrian/src/Rules/Generate.hs ===================================== @@ -424,6 +424,8 @@ bindistRules = do , interpolateVar "TablesNextToCode" $ yesNo <$> getTarget tgtTablesNextToCode , interpolateVar "TargetHasLibm" $ yesNo <$> getTarget tgtHasLibm , interpolateVar "TargetPlatform" $ getTarget targetPlatformTriple + , interpolateVar "BuildPlatform" $ interp $ queryBuild targetPlatformTriple + , interpolateVar "HostPlatform" $ interp $ queryHost targetPlatformTriple , interpolateVar "TargetWordBigEndian" $ getTarget isBigEndian , interpolateVar "TargetWordSize" $ getTarget wordSize , interpolateVar "Unregisterised" $ yesNo <$> getTarget tgtUnregisterised @@ -431,6 +433,9 @@ bindistRules = do , interpolateVar "UseLibffiForAdjustors" $ yesNo <$> getTarget tgtUseLibffiForAdjustors , interpolateVar "GhcWithSMP" $ yesNo <$> targetSupportsSMP , interpolateVar "BaseUnitId" $ pkgUnitId Stage1 base + , interpolateVar "TargetPlatformFull" (setting TargetPlatformFull) + , interpolateVar "BuildPlatformFull" (setting BuildPlatformFull) + , interpolateVar "HostPlatformFull" (setting HostPlatformFull) ] where interp = interpretInContext (semiEmptyTarget Stage2) ===================================== hadrian/src/Settings/Default.hs ===================================== @@ -122,7 +122,11 @@ stage0Packages = do -- for upper stages. As we only use stage0 to build upper stages, -- this should be fine. ++ [ terminfo | not windowsHost, not cross ] - ++ [ timeout | windowsHost ] + ++ [ timeout | windowsHost ] + -- Due to some weird logic, we need ghcToolchainBin in Stage0 and + -- Stage1 packages if we're cross compiling. "Stage2 cross-compilers" + -- will solve this. + ++ [ ghcToolchainBin | cross ] -- | Packages built in 'Stage1' by default. You can change this in "UserSettings". stage1Packages :: Action [Package] @@ -181,12 +185,12 @@ stage1Packages = do , transformers , unlit , xhtml + , ghcToolchainBin , if winTarget then win32 else unix ] , when (not cross) [ hpcBin , runGhc - , ghcToolchainBin ] , when (winTarget && not cross) [ -- See Note [Hadrian's ghci-wrapper package] ===================================== m4/fptools_set_platform_vars.m4 ===================================== @@ -77,9 +77,9 @@ dnl fi # compiler's target platform. AC_DEFUN([FPTOOLS_OVERRIDE_PLATFORM_FROM_BOOTSTRAP], [ - if test "$bootstrap_target" != "" + if test "$bootstrap_$1" != "" then - $1=$bootstrap_target + $1=$bootstrap_$1 echo "$1 platform inferred as: [$]$1" else echo "Can't work out $1 platform" ===================================== m4/ghc_toolchain.m4 ===================================== @@ -136,8 +136,10 @@ dnl and that we must compile ghc-toolchain before invoking it AC_DEFUN([FIND_GHC_TOOLCHAIN_BIN],[ case "$1" in YES) - # We're configuring the bindist, and the binary is already available - GHC_TOOLCHAIN_BIN="bin/ghc-toolchain-bin" + # We're configuring the bindist, and the binary is already available. + # For cross-compilation bindists, Hadrian names the binary with the + # cross-compile prefix (e.g. riscv64-linux-gnu-ghc-toolchain-bin). + GHC_TOOLCHAIN_BIN="bin/${CrossCompilePrefix}ghc-toolchain-bin" ;; NO) # We're in the source tree, so compile ghc-toolchain View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/7fe84ea5c2159204bf845ff3f7fd1e6... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/7fe84ea5c2159204bf845ff3f7fd1e6... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Marge Bot (@marge-bot)