Serge S. Gulin pushed to branch wip/T25974 at Glasgow Haskell Compiler / GHC
Commits:
-
4631de44
by Serge S. Gulin at 2025-05-06T11:26:23+03:00
8 changed files:
- .gitlab/ci.sh
- .gitlab/generate-ci/gen_ci.hs
- boot
- configure.ac
- hadrian/src/Builder.hs
- hadrian/src/Rules/BinaryDist.hs
- libraries/ghc-internal/src/GHC/Internal/Event/Windows.hsc
- m4/find_merge_objects.m4
Changes:
| ... | ... | @@ -75,6 +75,15 @@ Environment variables affecting both build systems: |
| 75 | 75 | NIX_SYSTEM On Darwin, the target platform of the desired toolchain
|
| 76 | 76 | (either "x86-64-darwin" or "aarch-darwin")
|
| 77 | 77 | NO_BOOT Whether to run ./boot or not, used when testing the source dist
|
| 78 | + TOOLCHAIN_SOURCE Select a source of toolchain. Possible values:
|
|
| 79 | + - "env": Toolchains are included in the Docker image via environment
|
|
| 80 | + variables. Default for Linux.
|
|
| 81 | + - "nix": Toolchains are provided via .gitlab/darwin/toolchain.nix.
|
|
| 82 | + Default for Darwin.
|
|
| 83 | + - "extracted":
|
|
| 84 | + Toolchains will be downloaded and extracted through the
|
|
| 85 | + CI process. Default for other systems. Windows and FreeBSD
|
|
| 86 | + are included.
|
|
| 78 | 87 | |
| 79 | 88 | Environment variables determining build configuration of Hadrian system:
|
| 80 | 89 | |
| ... | ... | @@ -83,14 +92,14 @@ Environment variables determining build configuration of Hadrian system: |
| 83 | 92 | This tests the "reinstall" configuration
|
| 84 | 93 | CROSS_EMULATOR The emulator to use for testing of cross-compilers.
|
| 85 | 94 | |
| 86 | -Environment variables determining bootstrap toolchain (Linux):
|
|
| 95 | +Environment variables determining bootstrap toolchain (TOOLCHAIN_SOURCE=env):
|
|
| 87 | 96 | |
| 88 | 97 | GHC Path of GHC executable to use for bootstrapping.
|
| 89 | 98 | CABAL Path of cabal-install executable to use for bootstrapping.
|
| 90 | 99 | ALEX Path of alex executable to use for bootstrapping.
|
| 91 | 100 | HAPPY Path of alex executable to use for bootstrapping.
|
| 92 | 101 | |
| 93 | -Environment variables determining bootstrap toolchain (non-Linux):
|
|
| 102 | +Environment variables determining bootstrap toolchain (TOOLCHAIN_SOURCE=extracted):
|
|
| 94 | 103 | |
| 95 | 104 | GHC_VERSION Which GHC version to fetch for bootstrapping.
|
| 96 | 105 | CABAL_INSTALL_VERSION
|
| ... | ... | @@ -132,10 +141,33 @@ function setup_locale() { |
| 132 | 141 | }
|
| 133 | 142 | |
| 134 | 143 | function mingw_init() {
|
| 144 | + if [[ "${TOOLCHAIN_SOURCE:-}" =~ "env" ]]; then
|
|
| 145 | + # We assume that passed GHC will be used as a bootstrap ghc compiler
|
|
| 146 | + if [ -n "${GHC:-}" ]; then
|
|
| 147 | + boot_triple=$($GHC --info | awk -F'"' '/Target platform/ {print $4}')
|
|
| 148 | + else
|
|
| 149 | + boot_triple=$(ghc --info | awk -F'"' '/Target platform/ {print $4}')
|
|
| 150 | + fi
|
|
| 151 | + else
|
|
| 152 | + case "$MSYSTEM" in
|
|
| 153 | + CLANG64)
|
|
| 154 | + boot_triple="x86_64-unknown-mingw32" # triple of bootstrap GHC
|
|
| 155 | + ;;
|
|
| 156 | + CLANGARM64)
|
|
| 157 | + boot_triple="aarch64-unknown-mingw32" # triple of bootstrap GHC
|
|
| 158 | + ;;
|
|
| 159 | + *)
|
|
| 160 | + fail "win32-init: Unknown MSYSTEM $MSYSTEM"
|
|
| 161 | + ;;
|
|
| 162 | + esac
|
|
| 163 | + fi
|
|
| 164 | + |
|
| 135 | 165 | case "$MSYSTEM" in
|
| 136 | 166 | CLANG64)
|
| 137 | 167 | target_triple="x86_64-unknown-mingw32"
|
| 138 | - boot_triple="x86_64-unknown-mingw32" # triple of bootstrap GHC
|
|
| 168 | + ;;
|
|
| 169 | + CLANGARM64)
|
|
| 170 | + target_triple="aarch64-unknown-mingw32"
|
|
| 139 | 171 | ;;
|
| 140 | 172 | *)
|
| 141 | 173 | fail "win32-init: Unknown MSYSTEM $MSYSTEM"
|
| ... | ... | @@ -150,10 +182,19 @@ function mingw_init() { |
| 150 | 182 | MINGW_MOUNT_POINT="${MINGW_PREFIX}"
|
| 151 | 183 | PATH="$MINGW_MOUNT_POINT/bin:$PATH"
|
| 152 | 184 | |
| 153 | - # We always use mingw64 Python to avoid path length issues like #17483.
|
|
| 154 | - export PYTHON="/mingw64/bin/python3"
|
|
| 155 | - # And need to use sphinx-build from the environment
|
|
| 156 | - export SPHINXBUILD="/mingw64/bin/sphinx-build.exe"
|
|
| 185 | + case "$MSYSTEM" in
|
|
| 186 | + CLANGARM64)
|
|
| 187 | + # At MSYS for ARM64 we force to use their special versions to speedup the compiler step
|
|
| 188 | + export PYTHON="/clangarm64/bin/python3"
|
|
| 189 | + export SPHINXBUILD="/clangarm64/bin/sphinx-build.exe"
|
|
| 190 | + ;;
|
|
| 191 | + *)
|
|
| 192 | + # We always use mingw64 Python to avoid path length issues like #17483.
|
|
| 193 | + export PYTHON="/mingw64/bin/python3"
|
|
| 194 | + # And need to use sphinx-build from the environment
|
|
| 195 | + export SPHINXBUILD="/mingw64/bin/sphinx-build.exe"
|
|
| 196 | + ;;
|
|
| 197 | + esac
|
|
| 157 | 198 | }
|
| 158 | 199 | |
| 159 | 200 | # This will contain GHC's local native toolchain
|
| ... | ... | @@ -178,15 +219,21 @@ function show_tool() { |
| 178 | 219 | }
|
| 179 | 220 | |
| 180 | 221 | function set_toolchain_paths() {
|
| 181 | - case "$(uname -m)-$(uname)" in
|
|
| 182 | - # Linux toolchains are included in the Docker image
|
|
| 183 | - *-Linux) toolchain_source="env" ;;
|
|
| 184 | - # Darwin toolchains are provided via .gitlab/darwin/toolchain.nix
|
|
| 185 | - *-Darwin) toolchain_source="nix" ;;
|
|
| 186 | - *) toolchain_source="extracted" ;;
|
|
| 187 | - esac
|
|
| 222 | + if [ -z "${TOOLCHAIN_SOURCE:-}" ]
|
|
| 223 | + then
|
|
| 224 | + # Fallback to automatic detection which could not work for cases
|
|
| 225 | + # when cross compiler will be build at Windows environment
|
|
| 226 | + # and requires a special mingw compiler (not bundled)
|
|
| 227 | + case "$(uname -m)-$(uname)" in
|
|
| 228 | + # Linux toolchains are included in the Docker image
|
|
| 229 | + *-Linux) TOOLCHAIN_SOURCE="env" ;;
|
|
| 230 | + # Darwin toolchains are provided via .gitlab/darwin/toolchain.nix
|
|
| 231 | + *-Darwin) TOOLCHAIN_SOURCE="nix" ;;
|
|
| 232 | + *) TOOLCHAIN_SOURCE="extracted" ;;
|
|
| 233 | + esac
|
|
| 234 | + fi
|
|
| 188 | 235 | |
| 189 | - case "$toolchain_source" in
|
|
| 236 | + case "$TOOLCHAIN_SOURCE" in
|
|
| 190 | 237 | extracted)
|
| 191 | 238 | # These are populated by setup_toolchain
|
| 192 | 239 | GHC="$toolchain/bin/ghc$exe"
|
| ... | ... | @@ -217,7 +264,7 @@ function set_toolchain_paths() { |
| 217 | 264 | : ${HAPPY:=$(which happy)}
|
| 218 | 265 | : ${ALEX:=$(which alex)}
|
| 219 | 266 | ;;
|
| 220 | - *) fail "bad toolchain_source"
|
|
| 267 | + *) fail "bad TOOLCHAIN_SOURCE"
|
|
| 221 | 268 | esac
|
| 222 | 269 | |
| 223 | 270 | export GHC
|
| ... | ... | @@ -247,7 +294,7 @@ function setup() { |
| 247 | 294 | cp -Rf "$CABAL_CACHE"/* "$CABAL_DIR"
|
| 248 | 295 | fi
|
| 249 | 296 | |
| 250 | - case $toolchain_source in
|
|
| 297 | + case $TOOLCHAIN_SOURCE in
|
|
| 251 | 298 | extracted) time_it "setup" setup_toolchain ;;
|
| 252 | 299 | *) ;;
|
| 253 | 300 | esac
|
| ... | ... | @@ -405,6 +452,17 @@ function configure() { |
| 405 | 452 | if [[ -n "${target_triple:-}" ]]; then
|
| 406 | 453 | args+=("--target=$target_triple")
|
| 407 | 454 | fi
|
| 455 | + if [[ "${TOOLCHAIN_SOURCE:-}" =~ "extracted" ]]; then
|
|
| 456 | + # To extract something need download something first.
|
|
| 457 | + args+=("--enable-tarballs-autodownload")
|
|
| 458 | + else
|
|
| 459 | + # For Windows we should explicitly --enable-distro-toolchain
|
|
| 460 | + # if i.e. we decided to use TOOLCHAIN_SOURCE = env
|
|
| 461 | + case "$(uname)" in
|
|
| 462 | + MSYS_*|MINGW*) args+=("--enable-distro-toolchain") ;;
|
|
| 463 | + *) ;;
|
|
| 464 | + esac
|
|
| 465 | + fi
|
|
| 408 | 466 | if [[ -n "${ENABLE_NUMA:-}" ]]; then
|
| 409 | 467 | args+=("--enable-numa")
|
| 410 | 468 | else
|
| ... | ... | @@ -421,7 +479,6 @@ function configure() { |
| 421 | 479 | # See https://stackoverflow.com/questions/7577052 for a rationale for the
|
| 422 | 480 | # args[@] symbol-soup below.
|
| 423 | 481 | run ${CONFIGURE_WRAPPER:-} ./configure \
|
| 424 | - --enable-tarballs-autodownload \
|
|
| 425 | 482 | "${args[@]+"${args[@]}"}" \
|
| 426 | 483 | GHC="$GHC" \
|
| 427 | 484 | || ( cat config.log; fail "configure failed" )
|
| ... | ... | @@ -562,12 +619,14 @@ function install_bindist() { |
| 562 | 619 | read -r -a args <<< "${INSTALL_CONFIGURE_ARGS:-}"
|
| 563 | 620 | |
| 564 | 621 | if [[ "${CROSS_TARGET:-no_cross_target}" =~ "mingw" ]]; then
|
| 565 | - # We suppose that host target = build target.
|
|
| 622 | + # We assume that BUILD=HOST.
|
|
| 566 | 623 | # By the fact above it is clearly turning out which host value is
|
| 567 | 624 | # for currently built compiler.
|
| 568 | 625 | # The fix for #21970 will probably remove this if-branch.
|
| 569 | - local -r CROSS_HOST_GUESS=$($SHELL ./config.guess)
|
|
| 570 | - args+=( "--target=$CROSS_TARGET" "--host=$CROSS_HOST_GUESS" )
|
|
| 626 | + # Cut is needed due of See Note [Wide Triple Windows].
|
|
| 627 | + # By default it guesses "(x86_64|aarch64)-w64-mingw32"
|
|
| 628 | + local -r CROSS_HOST_ARCH_GUESS=$($SHELL ./config.guess | cut -d'-' -f1)
|
|
| 629 | + args+=( "--target=$CROSS_TARGET" "--host=$CROSS_HOST_ARCH_GUESS-unknown-mingw32" )
|
|
| 571 | 630 | |
| 572 | 631 | # FIXME: The bindist configure script shouldn't need to be reminded of
|
| 573 | 632 | # the target platform. See #21970.
|
| ... | ... | @@ -1302,11 +1302,14 @@ cross_jobs = [ |
| 1302 | 1302 | . setVariable "WindresCmd" (llvm_prefix ++ "windres")
|
| 1303 | 1303 | . setVariable "LLVMAS" (llvm_prefix ++ "clang")
|
| 1304 | 1304 | . setVariable "LD" (llvm_prefix ++ "ld")
|
| 1305 | + -- See Note [Empty MergeObjsCmd]
|
|
| 1305 | 1306 | -- Windows target require to make linker merge feature check disabled.
|
| 1306 | 1307 | . setVariable "MergeObjsCmd" ""
|
| 1308 | + -- Note [Wide Triple Windows]
|
|
| 1309 | + -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
| 1307 | 1310 | -- LLVM MinGW Linux Toolchain expects to recieve "aarch64-w64-mingw32"
|
| 1308 | 1311 | -- as a triple but we use more common "aarch64-unknown-mingw32".
|
| 1309 | - -- Due of this we need configure ld manually for clang beacause
|
|
| 1312 | + -- Due of this we need configure ld manually for clang because
|
|
| 1310 | 1313 | -- it will use system's ld otherwise when --target will be specified to
|
| 1311 | 1314 | -- unexpected triple.
|
| 1312 | 1315 | . setVariable "CFLAGS" cflags
|
| ... | ... | @@ -52,6 +52,8 @@ def autoreconf(): |
| 52 | 52 | # Run autoreconf on everything that needs it.
|
| 53 | 53 | processes = {}
|
| 54 | 54 | if os.name == 'nt':
|
| 55 | + # Note [ACLOCAL_PATH for Windows]
|
|
| 56 | + # ~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
| 55 | 57 | # Get the normalized ACLOCAL_PATH for Windows
|
| 56 | 58 | # This is necessary since on Windows this will be a Windows
|
| 57 | 59 | # path, which autoreconf doesn't know doesn't know how to handle.
|
| ... | ... | @@ -658,12 +658,13 @@ GHC_LLVM_TARGET_SET_VAR |
| 658 | 658 | AC_SUBST(LlvmTarget)
|
| 659 | 659 | |
| 660 | 660 | dnl ** See whether cc supports --target=<triple> and set
|
| 661 | -dnl CONF_CC_OPTS_STAGE[012] accordingly.
|
|
| 662 | -FP_CC_SUPPORTS_TARGET([$CC_STAGE0], [CONF_CC_OPTS_STAGE0], [CONF_CXX_OPTS_STAGE0])
|
|
| 661 | +dnl CONF_CC_OPTS_STAGE[12] accordingly.
|
|
| 663 | 662 | FP_CC_SUPPORTS_TARGET([$CC], [CONF_CC_OPTS_STAGE1], [CONF_CXX_OPTS_STAGE1])
|
| 664 | 663 | FP_CC_SUPPORTS_TARGET([$CC], [CONF_CC_OPTS_STAGE2], [CONF_CXX_OPTS_STAGE2])
|
| 665 | 664 | |
| 666 | -FP_PROG_CC_LINKER_TARGET([$CC_STAGE0], [CONF_CC_OPTS_STAGE0], [CONF_GCC_LINKER_OPTS_STAGE0])
|
|
| 665 | +# CONF_CC_OPTS_STAGE0 should be left as is because it is already configured
|
|
| 666 | +# by bootstrap compiler settings
|
|
| 667 | + |
|
| 667 | 668 | FP_PROG_CC_LINKER_TARGET([$CC], [CONF_CC_OPTS_STAGE1], [CONF_GCC_LINKER_OPTS_STAGE1])
|
| 668 | 669 | FP_PROG_CC_LINKER_TARGET([$CC], [CONF_CC_OPTS_STAGE2], [CONF_GCC_LINKER_OPTS_STAGE2])
|
| 669 | 670 |
| ... | ... | @@ -26,7 +26,7 @@ import Hadrian.Builder.Tar |
| 26 | 26 | import Hadrian.Oracles.Path
|
| 27 | 27 | import Hadrian.Oracles.TextFile
|
| 28 | 28 | import Hadrian.Utilities
|
| 29 | -import Oracles.Setting (bashPath, targetStage)
|
|
| 29 | +import Oracles.Setting (bashPath, targetStage, isWinHost)
|
|
| 30 | 30 | import System.Exit
|
| 31 | 31 | import System.IO (stderr)
|
| 32 | 32 | |
| ... | ... | @@ -327,8 +327,14 @@ instance H.Builder Builder where |
| 327 | 327 | Ar Unpack _ -> cmd' [Cwd output] [path] buildArgs buildOptions
|
| 328 | 328 | |
| 329 | 329 | Autoreconf dir -> do
|
| 330 | + isWin <- isWinHost
|
|
| 331 | + let aclocal_env =
|
|
| 332 | + -- It is generally assumed that you would use MinGW's compilers from within an MSYS shell.
|
|
| 333 | + -- See Note [ACLOCAL_PATH for Windows]
|
|
| 334 | + if isWin then [AddEnv "ACLOCAL_PATH" "/c/msys64/usr/share/aclocal/"]
|
|
| 335 | + else []
|
|
| 330 | 336 | bash <- bashPath
|
| 331 | - cmd' [Cwd dir] [bash, path] buildArgs buildOptions
|
|
| 337 | + cmd' (Cwd dir `cons` aclocal_env) [bash, path] buildArgs buildOptions
|
|
| 332 | 338 | |
| 333 | 339 | Configure dir -> do
|
| 334 | 340 | -- Inject /bin/bash into `libtool`, instead of /bin/sh,
|
| ... | ... | @@ -115,7 +115,12 @@ installTo relocatable prefix = do |
| 115 | 115 | targetPlatform <- setting TargetPlatformFull
|
| 116 | 116 | let ghcVersionPretty = "ghc-" ++ version ++ "-" ++ targetPlatform
|
| 117 | 117 | bindistFilesDir = root -/- "bindist" -/- ghcVersionPretty
|
| 118 | - runBuilder (Configure bindistFilesDir) ["--prefix="++prefix] [] []
|
|
| 118 | + win <- isWinTarget
|
|
| 119 | + -- See Note [Empty MergeObjsCmd]
|
|
| 120 | + let disabledMerge =
|
|
| 121 | + if win then ["MergeObjsCmd="]
|
|
| 122 | + else []
|
|
| 123 | + runBuilder (Configure bindistFilesDir) (["--prefix="++prefix] ++ disabledMerge) [] []
|
|
| 119 | 124 | let env = case relocatable of
|
| 120 | 125 | Relocatable -> [AddEnv "RelocatableBuild" "YES"]
|
| 121 | 126 | NotRelocatable -> []
|
| ... | ... | @@ -232,7 +237,7 @@ bindistRules = do |
| 232 | 237 | -- N.B. the ghc-pkg executable may be prefixed with a target triple
|
| 233 | 238 | -- (c.f. #20267).
|
| 234 | 239 | ghcPkgName <- programName (vanillaContext Stage1 ghcPkg)
|
| 235 | - cmd_ (bindistFilesDir -/- "bin" -/- ghcPkgName) ["recache"]
|
|
| 240 | + cmd_ (bindistFilesDir -/- "bin" -/- ghcPkgName <.> exe) ["recache"]
|
|
| 236 | 241 | |
| 237 | 242 | |
| 238 | 243 |
| ... | ... | @@ -861,7 +861,9 @@ expirationTime mgr us = do |
| 861 | 861 | -- The 'TimeoutCallback' will not be called more than once.
|
| 862 | 862 | --
|
| 863 | 863 | -- Be careful not to exceed @maxBound :: Int@, which on 32-bit machines is only
|
| 864 | --- 2147483647 μs, less than 36 minutes.
|
|
| 864 | +-- 2147483647 microseconds, less than 36 minutes.
|
|
| 865 | +-- We can not use here utf/greek symbol due of:
|
|
| 866 | +-- _build/stage1/libraries/ghc-internal/build/GHC/Internal/Event/Windows.hs: commitBuffer: invalid argument (cannot encode character '\206')
|
|
| 865 | 867 | --
|
| 866 | 868 | {-# NOINLINE registerTimeout #-}
|
| 867 | 869 | registerTimeout :: Manager -> Int -> TimeoutCallback -> IO TimeoutKey
|
| ... | ... | @@ -878,7 +880,9 @@ registerTimeout mgr@Manager{..} uSrelTime cb = do |
| 878 | 880 | -- This has no effect if the timeout has already fired.
|
| 879 | 881 | --
|
| 880 | 882 | -- Be careful not to exceed @maxBound :: Int@, which on 32-bit machines is only
|
| 881 | --- 2147483647 μs, less than 36 minutes.
|
|
| 883 | +-- 2147483647 microseconds, less than 36 minutes.
|
|
| 884 | +-- We can not use here utf/greek symbol due of:
|
|
| 885 | +-- _build/stage1/libraries/ghc-internal/build/GHC/Internal/Event/Windows.hs: commitBuffer: invalid argument (cannot encode character '\206')
|
|
| 882 | 886 | --
|
| 883 | 887 | updateTimeout :: Manager -> TimeoutKey -> Seconds -> IO ()
|
| 884 | 888 | updateTimeout mgr (TK key) relTime = do
|
| ... | ... | @@ -980,7 +984,7 @@ step maxDelay mgr@Manager{..} = do |
| 980 | 984 | -- There are some unusual edge cases you need to deal with. The
|
| 981 | 985 | -- GetQueuedCompletionStatus function blocks a thread until there's
|
| 982 | 986 | -- work for it to do. Based on the return value, the number of bytes
|
| 983 | - -- and the overlapped structure, there’s a lot of possible "reasons"
|
|
| 987 | + -- and the overlapped structure, there's a lot of possible "reasons"
|
|
| 984 | 988 | -- for the function to have returned. Deciphering all the possible
|
| 985 | 989 | -- cases:
|
| 986 | 990 | --
|
| ... | ... | @@ -33,6 +33,8 @@ AC_DEFUN([FIND_MERGE_OBJECTS],[ |
| 33 | 33 | fi
|
| 34 | 34 | |
| 35 | 35 | |
| 36 | + # Note [Empty MergeObjsCmd]
|
|
| 37 | + # ~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
| 36 | 38 | # If MergeObjsCmd="" then we assume that the user is explicitly telling us that
|
| 37 | 39 | # they do not want to configure the MergeObjsCmd, this is particularly important for
|
| 38 | 40 | # the bundled windows toolchain.
|