From b8d78ee11d760666c10e0dc9428dca21a4d7dd52 Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Tue, 18 Feb 2025 16:24:34 +0800 Subject: [PATCH 01/84] chore(hie.yaml): add Build.hs --- hie.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hie.yaml b/hie.yaml index b666fd0f0517..91c6758cca54 100644 --- a/hie.yaml +++ b/hie.yaml @@ -7,11 +7,11 @@ # The format is documented here - https://github.com/mpickering/hie-bios cradle: multi: - - path: Build.hs + - path: ./Build.hs config: cradle: direct: arguments: [] - - path: "*" + - path: . config: cradle: {bios: {program: "./hadrian/hie-bios"}} From 78c15fb5a22d086092e41e03a7380464cb38da4f Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Wed, 12 Feb 2025 12:57:39 +0800 Subject: [PATCH 02/84] fix(rts): bump cabal-version The field "extra-libraries-static" is available only since version 3.8 of the Cabal specification. --- rts/rts.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rts/rts.cabal b/rts/rts.cabal index 612eae6bb273..c97136cc1f59 100644 --- a/rts/rts.cabal +++ b/rts/rts.cabal @@ -1,4 +1,4 @@ -cabal-version: 3.4 +cabal-version: 3.8 name: rts version: 1.0.3 synopsis: The GHC runtime system From 845440c8fa0336393e1a4647187a50c44eb8c094 Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Wed, 12 Feb 2025 13:00:13 +0800 Subject: [PATCH 03/84] chore(rts): remove another leftover file --- rts/Makefile | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 rts/Makefile diff --git a/rts/Makefile b/rts/Makefile deleted file mode 100644 index d6a9db37574f..000000000000 --- a/rts/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -# ----------------------------------------------------------------------------- -# -# (c) 2009 The University of Glasgow -# -# This file is part of the GHC build system. -# -# To understand how the build system works and how to modify it, see -# https://gitlab.haskell.org/ghc/ghc/wikis/building/architecture -# https://gitlab.haskell.org/ghc/ghc/wikis/building/modifying -# -# ----------------------------------------------------------------------------- - -dir = rts -TOP = .. -include $(TOP)/mk/sub-makefile.mk - -FAST_MAKE_OPTS += stage=none From 71a93559e693433e504dd5db2f17ea56f72045e7 Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Thu, 27 Feb 2025 12:07:05 +1100 Subject: [PATCH 04/84] refactor(rts): add --with-compiler to rts/configure.ac --- rts/configure.ac | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/rts/configure.ac b/rts/configure.ac index e9181aaf552a..b07d1db0cf4a 100644 --- a/rts/configure.ac +++ b/rts/configure.ac @@ -26,6 +26,35 @@ AC_CONFIG_FILES([ghcplatform.h.top]) AC_CONFIG_HEADERS([ghcautoconf.h.autoconf]) +AC_ARG_WITH([compiler], + [AS_HELP_STRING([--with-compiler=PATH], + [Use a particular compiler available at PATH (default: ghc)])], + [ + GHC="$withval" + dnl If a name was provided (not an absolute path), resolve it in PATH + case "$withval" in + /*) AC_PATH_PROG([GHC], [`basename -- "$withval"`], [], [`dirname -- "$withval"`]) + ;; # It's already an absolute path, do nothing + *) AC_PATH_PROG([GHC], [$GHC], [], [$PATH]) ;; # Resolve it in PATH + esac + ], + [AC_PATH_PROG([GHC], [ghc])] +) + +dnl Verify that the resolved GHC is valid +if test -z "$GHC"; then + AC_MSG_ERROR([No valid GHC compiler found. Please install GHC or specify one with --with-compiler=.]) +elif test ! -x "$GHC"; then + AC_MSG_ERROR([The specified compiler ($GHC) is not executable.]) +fi + +dnl Check if it's actually GHC +GHC_VERSION=`$GHC --numeric-version 2>/dev/null` +if test -z "$GHC_VERSION"; then + AC_MSG_ERROR([The specified compiler ($GHC) does not appear to be a valid GHC.]) +fi + + AC_ARG_ENABLE(asserts-all-ways, [AS_HELP_STRING([--enable-asserts-all-ways], [Usually ASSERTs are only compiled in the DEBUG way, From b53279e43384f53e121fd2e46e19efd6c8cfb55e Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Tue, 3 Dec 2024 17:54:27 +0800 Subject: [PATCH 05/84] chore: remove libraries/defineTOP.mk Unused at least since August 2008 (9329cdb264) --- libraries/defineTOP.mk | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 libraries/defineTOP.mk diff --git a/libraries/defineTOP.mk b/libraries/defineTOP.mk deleted file mode 100644 index 5d8adee9e44a..000000000000 --- a/libraries/defineTOP.mk +++ /dev/null @@ -1,3 +0,0 @@ - -TOP = ../.. - From d6dd0fff2b952136bbbe62762ffe1e2559f9b12e Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Thu, 19 Dec 2024 12:38:37 +0800 Subject: [PATCH 06/84] refactor(autoconf): drop FP_CHECK_TIMER_CREATE --- m4/fp_check_timer_create.m4 | 110 ------------------------------------ rts/configure.ac | 3 +- rts/posix/Ticker.c | 19 ++----- 3 files changed, 6 insertions(+), 126 deletions(-) delete mode 100644 m4/fp_check_timer_create.m4 diff --git a/m4/fp_check_timer_create.m4 b/m4/fp_check_timer_create.m4 deleted file mode 100644 index 957772ba456a..000000000000 --- a/m4/fp_check_timer_create.m4 +++ /dev/null @@ -1,110 +0,0 @@ -# Check for a working timer_create(). We need a pretty detailed check -# here, because there exist partially-working implementations of -# timer_create() in certain versions of Linux (see bug #1933). -# -AC_DEFUN([FP_CHECK_TIMER_CREATE],[ -AC_CHECK_FUNC([timer_create],[HAVE_timer_create=yes],[HAVE_timer_create=no]) - -if test "$HAVE_timer_create" = "yes" -then - if test "$cross_compiling" = "yes" - then - # We can't test timer_create when we're cross-compiling, so we - # optimistiaclly assume that it actually works properly. - AC_DEFINE([USE_TIMER_CREATE], 1, [Define to 1 if we can use timer_create(CLOCK_REALTIME,...)]) - else - AC_CACHE_CHECK([for a working timer_create(CLOCK_REALTIME)], - [fptools_cv_timer_create_works], - [AC_TRY_RUN([ -#include -#if defined(HAVE_STDLIB_H) -#include -#endif -#include -#if defined(HAVE_SIGNAL_H) -#include -#endif -#if defined(HAVE_UNISTD_H) -#include -#endif - -static volatile int tock = 0; -static void handler(int i) -{ - tock = 1; -} - -static void timeout(int i) -{ - // timer_settime() has been known to hang, so just in case - // we install a 1-second timeout (see #2257) - exit(99); -} - -int main(int argc, char *argv[]) -{ - - struct sigevent ev; - timer_t timer; - struct itimerspec it; - struct sigaction action; - int m,n,count = 0; - - ev.sigev_notify = SIGEV_SIGNAL; - ev.sigev_signo = SIGVTALRM; - - action.sa_handler = handler; - action.sa_flags = 0; - sigemptyset(&action.sa_mask); - if (sigaction(SIGVTALRM, &action, NULL) == -1) { - fprintf(stderr,"SIGVTALRM problem\n"); - exit(3); - } - - action.sa_handler = timeout; - action.sa_flags = 0; - sigemptyset(&action.sa_mask); - if (sigaction(SIGALRM, &action, NULL) == -1) { - fprintf(stderr,"SIGALRM problem\n"); - exit(3); - } - alarm(1); - - if (timer_create(CLOCK_REALTIME, &ev, &timer) != 0) { - fprintf(stderr,"No CLOCK_REALTIME timer\n"); - exit(2); - } - - tock = 0; - - it.it_value.tv_sec = 0; - it.it_value.tv_nsec = 1000000; // 1ms - it.it_interval = it.it_value; - if (timer_settime(timer, 0, &it, NULL) != 0) { - fprintf(stderr,"settime problem\n"); - exit(4); - } - - // some environments have coarse scheduler/timer granularity of ~10ms and worse - usleep(100000); // 100ms - - if (!tock) { - fprintf(stderr,"no CLOCK_REALTIME signal\n"); - exit(5); - } - - timer_delete(timer); - - exit(0); -} - ], - [fptools_cv_timer_create_works=yes], - [fptools_cv_timer_create_works=no]) - ]) -case $fptools_cv_timer_create_works in - yes) AC_DEFINE([USE_TIMER_CREATE], 1, - [Define to 1 if we can use timer_create(CLOCK_REALTIME,...)]);; -esac - fi -fi -]) diff --git a/rts/configure.ac b/rts/configure.ac index b07d1db0cf4a..994799ab6d5e 100644 --- a/rts/configure.ac +++ b/rts/configure.ac @@ -239,7 +239,8 @@ FP_MUSTTAIL dnl ** check for librt AC_CHECK_FUNCS(clock_gettime timer_settime) -FP_CHECK_TIMER_CREATE + +AC_CHECK_FUNC([timer_create],[HAVE_timer_create=yes],[HAVE_timer_create=no]) dnl ** check for Apple's "interesting" long double compatibility scheme AC_MSG_CHECKING(for printf\$LDBLStub) diff --git a/rts/posix/Ticker.c b/rts/posix/Ticker.c index 18bf1179dde5..d6ebfbd4a219 100644 --- a/rts/posix/Ticker.c +++ b/rts/posix/Ticker.c @@ -88,21 +88,10 @@ #endif #if defined(solaris2_HOST_OS) -/* USE_TIMER_CREATE is usually disabled for Solaris. In fact it is - supported well on this OS, but requires additional privilege. When - user does not have it, then the testing configure program fails - which results in USE_TIMER_CREATE not defined. - On the other hand when we cross-compile, then we optimistically - assume usage of timer_create function. The problem is that if we - cross compile for example from i386-solaris2 to x86_64-solaris2, - then the build fails with error like this: - -ghc-stage2: timer_create: Not owner - - which happens on first ghc-stage2 invocation. So to support - cross-compilation to Solaris we manually undefine USE_TIMER_CREATE +/* While timer_create is supported well on Solaris, it requires + additional privilege. So we manually undefine HAVE_TIMER_CREATE here */ -#undef USE_TIMER_CREATE +#undef HAVE_TIMER_CREATE #endif /* solaris2_HOST_OS */ // Select the variant to use @@ -110,7 +99,7 @@ ghc-stage2: timer_create: Not owner #include "ticker/TimerFd.c" #elif defined(USE_PTHREAD_FOR_ITIMER) #include "ticker/Pthread.c" -#elif defined(USE_TIMER_CREATE) +#elif defined(HAVE_TIMER_CREATE) #include "ticker/TimerCreate.c" #else #include "ticker/Setitimer.c" From a6a16520300cc525231101b192c604e0c0e84b21 Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Thu, 19 Dec 2024 12:28:59 +0800 Subject: [PATCH 07/84] refactor(autoconf): drop FP_SET_CFLAGS_C99 AC_PROG_CC already sets the necessary compiler flags to enable the latest language standard. --- configure.ac | 10 ++++++---- m4/fp_set_cflags_c99.m4 | 38 -------------------------------------- 2 files changed, 6 insertions(+), 42 deletions(-) delete mode 100644 m4/fp_set_cflags_c99.m4 diff --git a/configure.ac b/configure.ac index 6a39c3495f6f..b197b9893076 100644 --- a/configure.ac +++ b/configure.ac @@ -445,10 +445,12 @@ AC_SUBST([CmmCPPCmd]) AC_SUBST([CmmCPPArgs]) AC_SUBST([CmmCPPSupportsG0]) -FP_SET_CFLAGS_C99([CC],[CFLAGS],[CPPFLAGS]) -FP_SET_CFLAGS_C99([CC_STAGE0],[CONF_CC_OPTS_STAGE0],[CONF_CPP_OPTS_STAGE0]) -FP_SET_CFLAGS_C99([CC],[CONF_CC_OPTS_STAGE1],[CONF_CPP_OPTS_STAGE1]) -FP_SET_CFLAGS_C99([CC],[CONF_CC_OPTS_STAGE2],[CONF_CPP_OPTS_STAGE2]) +AC_PROG_CC + +dnl Autoconf will configure the latest standard. We require at least c99. +AS_CASE([$ac_prog_cc_stdc], + [c89], [AC_MSG_ERROR([C99-compatible compiler needed])] +) dnl ** Do we have a compatible emsdk version? dnl -------------------------------------------------------------- diff --git a/m4/fp_set_cflags_c99.m4 b/m4/fp_set_cflags_c99.m4 deleted file mode 100644 index b9644efe6618..000000000000 --- a/m4/fp_set_cflags_c99.m4 +++ /dev/null @@ -1,38 +0,0 @@ -# FP_SET_CFLAGS_C99 -# ---------------------------------- -# figure out which CFLAGS are needed to place the compiler into C99 mode -# $1 is name of CC variable (unmodified) -# $2 is name of CC flags variable (augmented if needed) -# $3 is name of CPP flags variable (augmented if needed) -AC_DEFUN([FP_SET_CFLAGS_C99], -[ - dnl save current state of AC_PROG_CC_C99 - FP_COPY_SHELLVAR([CC],[fp_save_CC]) - FP_COPY_SHELLVAR([CFLAGS],[fp_save_CFLAGS]) - FP_COPY_SHELLVAR([CPPFLAGS],[fp_save_CPPFLAGS]) - FP_COPY_SHELLVAR([ac_cv_prog_cc_c99],[fp_save_cc_c99]) - dnl set local state - CC="$$1" - CFLAGS="$$2" - CPPFLAGS="$$3" - unset ac_cv_prog_cc_c99 - dnl perform detection - AC_PROG_CC_C99 - fp_cc_c99="$ac_cv_prog_cc_c99" - case "x$ac_cv_prog_cc_c99" in - x) ;; # noop - xno) AC_MSG_ERROR([C99-compatible compiler needed]) ;; - *) $2="$$2 $ac_cv_prog_cc_c99" - $3="$$3 $ac_cv_prog_cc_c99" - ;; - esac - dnl restore saved state - FP_COPY_SHELLVAR([fp_save_CC],[CC]) - FP_COPY_SHELLVAR([fp_save_CFLAGS],[CFLAGS]) - FP_COPY_SHELLVAR([fp_save_CPPFLAGS],[CPPFLAGS]) - FP_COPY_SHELLVAR([fp_save_cc_c99],[ac_cv_prog_cc_c99]) - dnl cleanup - unset fp_save_CC - unset fp_save_CFLAGS - unset fp_save_cc_c99 -]) From b109395da9e22112ec8f09d1afaa9759baebc5a1 Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Thu, 19 Dec 2024 15:17:24 +0800 Subject: [PATCH 08/84] refactor(autoconf): remove inappropriate test in configure.ac Checking the source code is appropriate for a linter, not for the configure script. --- configure.ac | 4 ---- 1 file changed, 4 deletions(-) diff --git a/configure.ac b/configure.ac index b197b9893076..2720ce9648f7 100644 --- a/configure.ac +++ b/configure.ac @@ -945,10 +945,6 @@ AC_SUBST(BUILD_MAN) AC_SUBST(BUILD_SPHINX_HTML) AC_SUBST(BUILD_SPHINX_PDF) -if grep ' ' compiler/ghc.cabal.in 2>&1 >/dev/null; then - AC_MSG_ERROR([compiler/ghc.cabal.in contains tab characters; please remove them]) -fi - # We got caught by # http://savannah.gnu.org/bugs/index.php?1516 # $(eval ...) inside conditionals causes errors From a7578e719f1f82372beb8b47ba328b0f410f89e3 Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Tue, 11 Feb 2025 14:55:49 +0800 Subject: [PATCH 09/84] refactor: remove boot script The boot script performs two tasks - it checks for the presence of boot packages - it runs autoreconf in each boot package The first task is not valuable enough and likely could be implemented within autoconf. The second task be implemented in a standardised way using the macro AC_CONFIG_SUBDIRS. --- .github/workflows/ci.yml | 6 +-- boot | 83 ---------------------------------------- configure.ac | 27 ++++++------- 3 files changed, 17 insertions(+), 99 deletions(-) delete mode 100755 boot diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0c8875257dc8..73fc20a851b8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,12 +32,12 @@ jobs: cabal-version: "latest" cabal-update: true - - name: Configure the build - run: ./boot - - name: Build patched cabal run: make cabal + - # This runs autoconf also in the subdirectories + run: autoreconf -v + - name: Build the bindist env: CC: gcc diff --git a/boot b/boot deleted file mode 100755 index c73ed3a430b0..000000000000 --- a/boot +++ /dev/null @@ -1,83 +0,0 @@ -#!/usr/bin/env python3 - -import glob -import os -import os.path -import sys -from textwrap import dedent -import subprocess -import re -import shutil - -# Packages whose libraries aren't in the submodule root -EXCEPTIONS = { - 'libraries/containers/': 'libraries/containers/containers/' -} - -def print_err(s): - print(dedent(s), file=sys.stderr) - -def die(mesg): - print_err(mesg) - sys.exit(1) - -def check_boot_packages(): - # Check that we have all boot packages. - for l in open('packages', 'r'): - if l.startswith('#'): - continue - - parts = [part for part in l.split(' ') if part] - if len(parts) != 4: - die("Error: Bad line in packages file: " + l) - - dir_ = parts[0] - tag = parts[1] - - # If tag is not "-" then it is an optional repository, so its - # absence isn't an error. - if tag == '-': - # We would like to just check for a .git directory here, - # but in an lndir tree we avoid making .git directories, - # so it doesn't exist. We therefore require that every repo - # has a LICENSE file instead. - license_path = os.path.join(EXCEPTIONS.get(dir_+'/', dir_), 'LICENSE') - if not os.path.isfile(license_path): - die("""\ - Error: %s doesn't exist - Maybe you haven't run 'git submodule update --init'? - """ % license_path) - -def autoreconf(): - # Run autoreconf on everything that needs it. - processes = {} - if os.name == 'nt': - # Get the normalized ACLOCAL_PATH for Windows - # This is necessary since on Windows this will be a Windows - # path, which autoreconf doesn't know doesn't know how to handle. - ac_local = os.getenv('ACLOCAL_PATH', '') - ac_local_arg = re.sub(r';', r':', ac_local) - ac_local_arg = re.sub(r'\\', r'/', ac_local_arg) - ac_local_arg = re.sub(r'(\w):/', r'/\1/', ac_local_arg) - reconf_cmd = 'ACLOCAL_PATH=%s autoreconf' % ac_local_arg - else: - reconf_cmd = 'autoreconf' - - for dir_ in ['.', 'rts'] + glob.glob('libraries/*/'): - if os.path.isfile(os.path.join(dir_, 'configure.ac')): - print("Booting %s" % dir_) - processes[dir_] = subprocess.Popen(['sh', '-c', reconf_cmd], cwd=dir_) - - # Wait for all child processes to finish. - fail = False - for k,v in processes.items(): - code = v.wait() - if code != 0: - print_err('autoreconf in %s failed with exit code %d' % (k, code)) - fail = True - - if fail: - sys.exit(1) - -check_boot_packages() -autoreconf() diff --git a/configure.ac b/configure.ac index 2720ce9648f7..4236d25b1518 100644 --- a/configure.ac +++ b/configure.ac @@ -19,24 +19,25 @@ AC_INIT([The Glorious Glasgow Haskell Compilation System], [9.13], [glasgow-hask # (X.Y.Z) on stable branches (e.g. ghc-9.2) to ensure that pre-releases are # versioned correctly. +dnl TODO add here anything relevant from ./packages. Arguably this should be +dnl the source of truth and the rest should be generated by autoconf. +AC_CONFIG_SUBDIRS([ + distrib + libraries/directory + libraries/ghc-bignum + libraries/ghc-internal + libraries/process + libraries/terminfo + libraries/time + libraries/unix + rts +]) + AC_CONFIG_MACRO_DIRS([m4]) # Set this to YES for a released version, otherwise NO : ${RELEASE=NO} -# The primary version (e.g. 7.5, 7.4.1) is set in the AC_INIT line -# above. If this is not a released version, then we will append the -# date to the version number (e.g. 7.4.20111220). The date is -# constructed by finding the date of the most recent patch in the -# git repository. If this is a source distribution (not a git -# checkout), then we ship a file 'VERSION' containing the full version -# when the source distribution was created. - -if test ! -f rts/ghcautoconf.h.autoconf.in; then - echo "rts/ghcautoconf.h.autoconf.in doesn't exist: perhaps you haven't run 'python3 boot'?" - exit 1 -fi - dnl this makes sure `./configure --target=` dnl works as expected, since we're slightly modifying how Autoconf dnl interprets build/host/target and how this interacts with $CC tests From 013c9e7e933e84b5d3a517c9671197dda9a698ae Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Thu, 20 Feb 2025 15:08:27 +0800 Subject: [PATCH 10/84] refactor(compiler,hadrian): Remove runtime LLVM version check Checking LLVM version introduces complexity for not enough benefits. Trust the users and let them deal with the consequences. --- Build.hs | 7 ----- compiler/GHC/CmmToLlvm.hs | 34 ++------------------- compiler/GHC/CmmToLlvm/Base.hs | 14 +++------ compiler/GHC/CmmToLlvm/Config.hs | 1 - compiler/GHC/CmmToLlvm/Version.hs | 8 ----- compiler/GHC/CmmToLlvm/Version/Bounds.hs.in | 19 ------------ compiler/GHC/Driver/Config/CmmToLlvm.hs | 1 - compiler/GHC/Driver/Errors/Ppr.hs | 8 +---- compiler/GHC/Driver/Flags.hs | 3 -- compiler/GHC/Driver/Session.hs | 1 - compiler/GHC/SysTools/Tasks.hs | 10 ++---- compiler/ghc.cabal.in | 1 - hadrian/src/Hadrian/Haskell/Cabal/Parse.hs | 3 +- hadrian/src/Rules/Generate.hs | 9 +----- hadrian/src/Rules/Lint.hs | 3 +- 15 files changed, 15 insertions(+), 107 deletions(-) delete mode 100644 compiler/GHC/CmmToLlvm/Version/Bounds.hs.in diff --git a/Build.hs b/Build.hs index 694f67abb01c..1e69932df480 100755 --- a/Build.hs +++ b/Build.hs @@ -411,10 +411,6 @@ prepareGhcSources opts dst = do , (,) "@ProjectPatchLevel2@" (gboVersionPatchLevel2 opts) , (,) "@ProjectVersionInt@" (gboVersionInt opts) ] - llvm_substs = - [ (,) "@LlvmMinVersion@" (gboLlvmMinVersion opts) - , (,) "@LlvmMaxVersion@" (gboLlvmMaxVersion opts) - ] boot_th_substs = [ (,) "@Suffix@" "" , (,) "@SourceRoot@" "." @@ -428,9 +424,6 @@ prepareGhcSources opts dst = do subst_in (dst "libraries/template-haskell/template-haskell.cabal") common_substs subst_in (dst "libraries/ghci/ghci.cabal") common_substs - -- This is only used for a warning message. Nuke the check! - subst_in (dst "libraries/ghc/GHC/CmmToLlvm/Version/Bounds.hs") llvm_substs - subst_in (dst "utils/ghc-pkg/ghc-pkg.cabal") common_substs subst_in (dst "utils/iserv/iserv.cabal") common_substs subst_in (dst "utils/runghc/runghc.cabal") common_substs diff --git a/compiler/GHC/CmmToLlvm.hs b/compiler/GHC/CmmToLlvm.hs index 72a3161dec36..b85d620433b3 100644 --- a/compiler/GHC/CmmToLlvm.hs +++ b/compiler/GHC/CmmToLlvm.hs @@ -38,8 +38,8 @@ import GHC.Utils.Panic import GHC.Utils.Logger import qualified GHC.Data.Stream as Stream -import Control.Monad ( when, forM_ ) -import Data.Maybe ( fromMaybe, catMaybes, isNothing ) +import Control.Monad ( forM_ ) +import Data.Maybe ( catMaybes ) import System.IO -- ----------------------------------------------------------------------------- @@ -57,36 +57,8 @@ llvmCodeGen logger cfg h dus cmm_stream -- Pass header showPass logger "LLVM CodeGen" - -- get llvm version, cache for later use - let mb_ver = llvmCgLlvmVersion cfg - - -- warn if unsupported - forM_ mb_ver $ \ver -> do - debugTraceMsg logger 2 - (text "Using LLVM version:" <+> text (llvmVersionStr ver)) - let doWarn = llvmCgDoWarn cfg - when (not (llvmVersionSupported ver) && doWarn) $ putMsg logger $ - "You are using an unsupported version of LLVM!" $$ - "Currently only" <+> text (llvmVersionStr supportedLlvmVersionLowerBound) <+> - "up to" <+> text (llvmVersionStr supportedLlvmVersionUpperBound) <+> "(non inclusive) is supported." <+> - "System LLVM version: " <> text (llvmVersionStr ver) $$ - "We will try though..." - - when (isNothing mb_ver) $ do - let doWarn = llvmCgDoWarn cfg - when doWarn $ putMsg logger $ - "Failed to detect LLVM version!" $$ - "Make sure LLVM is installed correctly." $$ - "We will try though..." - - -- HACK: the Nothing case here is potentially wrong here but we - -- currently don't use the LLVM version to guide code generation - -- so this is okay. - let llvm_ver :: LlvmVersion - llvm_ver = fromMaybe supportedLlvmVersionLowerBound mb_ver - -- run code generation - (a, _) <- runLlvm logger cfg llvm_ver bufh dus $ + (a, _) <- runLlvm logger cfg bufh dus $ llvmCodeGen' cfg cmm_stream bFlush bufh diff --git a/compiler/GHC/CmmToLlvm/Base.hs b/compiler/GHC/CmmToLlvm/Base.hs index 3a7abc911e26..3532de66c824 100644 --- a/compiler/GHC/CmmToLlvm/Base.hs +++ b/compiler/GHC/CmmToLlvm/Base.hs @@ -18,7 +18,7 @@ module GHC.CmmToLlvm.Base ( LlvmM, runLlvm, withClearVars, varLookup, varInsert, markStackReg, checkStackReg, - funLookup, funInsert, getLlvmVer, + funLookup, funInsert, dumpIfSetLlvm, renderLlvm, markUsedVar, getUsedVars, ghcInternalFunctions, getPlatform, getConfig, @@ -277,8 +277,7 @@ llvmPtrBits platform = widthInBits $ typeWidth $ gcWord platform -- data LlvmEnv = LlvmEnv - { envVersion :: LlvmVersion -- ^ LLVM version - , envConfig :: !LlvmCgConfig -- ^ Configuration for LLVM code gen + { envConfig :: !LlvmCgConfig -- ^ Configuration for LLVM code gen , envLogger :: !Logger -- ^ Logger , envOutput :: BufHandle -- ^ Output buffer , envTag :: !Char -- ^ Tag for creating unique values @@ -331,8 +330,8 @@ liftUDSMT m = LlvmM $ \env -> do x <- m return (x, env) -- | Get initial Llvm environment. -runLlvm :: Logger -> LlvmCgConfig -> LlvmVersion -> BufHandle -> DSM.DUniqSupply -> LlvmM a -> IO (a, DSM.DUniqSupply) -runLlvm logger cfg ver out us m = do +runLlvm :: Logger -> LlvmCgConfig -> BufHandle -> DSM.DUniqSupply -> LlvmM a -> IO (a, DSM.DUniqSupply) +runLlvm logger cfg out us m = do ((a, _), us') <- DSM.runUDSMT us $ runLlvmM m env return (a, us') where env = LlvmEnv { envFunMap = emptyUFM @@ -340,7 +339,6 @@ runLlvm logger cfg ver out us m = do , envStackRegs = [] , envUsedVars = [] , envAliases = emptyUniqSet - , envVersion = ver , envConfig = cfg , envLogger = logger , envOutput = out @@ -386,10 +384,6 @@ getMetaUniqueId :: LlvmM MetaId getMetaUniqueId = LlvmM $ \env -> return (envFreshMeta env, env { envFreshMeta = succ $ envFreshMeta env }) --- | Get the LLVM version we are generating code for -getLlvmVer :: LlvmM LlvmVersion -getLlvmVer = getEnv envVersion - -- | Dumps the document if the corresponding flag has been set by the user dumpIfSetLlvm :: DumpFlag -> String -> DumpFormat -> Outp.SDoc -> LlvmM () dumpIfSetLlvm flag hdr fmt doc = do diff --git a/compiler/GHC/CmmToLlvm/Config.hs b/compiler/GHC/CmmToLlvm/Config.hs index 1e7e04144f96..e1ef61a52a2a 100644 --- a/compiler/GHC/CmmToLlvm/Config.hs +++ b/compiler/GHC/CmmToLlvm/Config.hs @@ -25,7 +25,6 @@ data LlvmCgConfig = LlvmCgConfig , llvmCgAvxEnabled :: !Bool , llvmCgBmiVersion :: Maybe BmiVersion -- ^ (x86) BMI instructions , llvmCgLlvmVersion :: Maybe LlvmVersion -- ^ version of Llvm we're using - , llvmCgDoWarn :: !Bool -- ^ True ==> warn unsupported Llvm version , llvmCgLlvmTarget :: !String -- ^ target triple passed to LLVM , llvmCgLlvmConfig :: !LlvmConfig -- ^ Supported LLVM configurations. -- see Note [LLVM configuration] diff --git a/compiler/GHC/CmmToLlvm/Version.hs b/compiler/GHC/CmmToLlvm/Version.hs index 9c3412f93160..a77977e47c4e 100644 --- a/compiler/GHC/CmmToLlvm/Version.hs +++ b/compiler/GHC/CmmToLlvm/Version.hs @@ -1,9 +1,6 @@ module GHC.CmmToLlvm.Version ( LlvmVersion(..) - , supportedLlvmVersionLowerBound - , supportedLlvmVersionUpperBound , parseLlvmVersion - , llvmVersionSupported , llvmVersionStr , llvmVersionList ) @@ -12,7 +9,6 @@ where import GHC.Prelude import GHC.CmmToLlvm.Version.Type -import GHC.CmmToLlvm.Version.Bounds import Data.Char (isDigit) import Data.List (intercalate) @@ -32,10 +28,6 @@ parseLlvmVersion = where (ver_str, rest) = span isDigit s -llvmVersionSupported :: LlvmVersion -> Bool -llvmVersionSupported v = - v >= supportedLlvmVersionLowerBound && v < supportedLlvmVersionUpperBound - llvmVersionStr :: LlvmVersion -> String llvmVersionStr = intercalate "." . map show . llvmVersionList diff --git a/compiler/GHC/CmmToLlvm/Version/Bounds.hs.in b/compiler/GHC/CmmToLlvm/Version/Bounds.hs.in deleted file mode 100644 index 19f4e4d37a91..000000000000 --- a/compiler/GHC/CmmToLlvm/Version/Bounds.hs.in +++ /dev/null @@ -1,19 +0,0 @@ -module GHC.CmmToLlvm.Version.Bounds - ( supportedLlvmVersionLowerBound - , supportedLlvmVersionUpperBound - ) -where - -import GHC.Prelude () - -import GHC.CmmToLlvm.Version.Type - -import qualified Data.List.NonEmpty as NE - --- | The (inclusive) lower bound on the LLVM Version that is currently supported. -supportedLlvmVersionLowerBound :: LlvmVersion -supportedLlvmVersionLowerBound = LlvmVersion (@LlvmMinVersion@ NE.:| []) - --- | The (not-inclusive) upper bound bound on the LLVM Version that is currently supported. -supportedLlvmVersionUpperBound :: LlvmVersion -supportedLlvmVersionUpperBound = LlvmVersion (@LlvmMaxVersion@ NE.:| []) diff --git a/compiler/GHC/Driver/Config/CmmToLlvm.hs b/compiler/GHC/Driver/Config/CmmToLlvm.hs index c0a21c9cb1f9..666e4342250a 100644 --- a/compiler/GHC/Driver/Config/CmmToLlvm.hs +++ b/compiler/GHC/Driver/Config/CmmToLlvm.hs @@ -29,7 +29,6 @@ initLlvmCgConfig logger config_cache dflags = do ArchX86 -> bmiVersion dflags _ -> Nothing , llvmCgLlvmVersion = version - , llvmCgDoWarn = wopt Opt_WarnUnsupportedLlvmVersion dflags , llvmCgLlvmTarget = platformMisc_llvmTarget $! platformMisc dflags , llvmCgLlvmConfig = llvm_config } diff --git a/compiler/GHC/Driver/Errors/Ppr.hs b/compiler/GHC/Driver/Errors/Ppr.hs index 32977fc97f4c..f414f6ca70ed 100644 --- a/compiler/GHC/Driver/Errors/Ppr.hs +++ b/compiler/GHC/Driver/Errors/Ppr.hs @@ -35,7 +35,6 @@ import GHC.HsToCore.Errors.Types (DsMessage) import GHC.Iface.Errors.Types import GHC.Tc.Errors.Ppr () -- instance Diagnostic TcRnMessage import GHC.Iface.Errors.Ppr () -- instance Diagnostic IfaceMessage -import GHC.CmmToLlvm.Version (llvmVersionStr, supportedLlvmVersionLowerBound, supportedLlvmVersionUpperBound) -- -- Suggestions @@ -272,12 +271,7 @@ instance Diagnostic DriverMessage where , nest 2 $ ppr node ] DriverNoConfiguredLLVMToolchain -> mkSimpleDecorated $ - text "GHC was not configured with a supported LLVM toolchain" $$ - text ("Make sure you have installed LLVM between [" - ++ llvmVersionStr supportedLlvmVersionLowerBound - ++ " and " - ++ llvmVersionStr supportedLlvmVersionUpperBound - ++ ") and reinstall GHC to make -fllvm work") + text "GHC was not configured with a supported LLVM toolchain" diagnosticReason = \case DriverUnknownMessage m diff --git a/compiler/GHC/Driver/Flags.hs b/compiler/GHC/Driver/Flags.hs index 45b32fd8d1fa..6a106b615601 100644 --- a/compiler/GHC/Driver/Flags.hs +++ b/compiler/GHC/Driver/Flags.hs @@ -1018,7 +1018,6 @@ data WarningFlag = | Opt_WarnMissedSpecs | Opt_WarnAllMissedSpecs | Opt_WarnUnsupportedCallingConventions - | Opt_WarnUnsupportedLlvmVersion | Opt_WarnMissedExtraSharedLib | Opt_WarnInlineRuleShadowing | Opt_WarnTypedHoles @@ -1144,7 +1143,6 @@ warnFlagNames wflag = case wflag of Opt_WarnMisplacedPragmas -> "misplaced-pragmas" :| [] Opt_WarnUnsafe -> "unsafe" :| [] Opt_WarnUnsupportedCallingConventions -> "unsupported-calling-conventions" :| [] - Opt_WarnUnsupportedLlvmVersion -> "unsupported-llvm-version" :| [] Opt_WarnMissedExtraSharedLib -> "missed-extra-shared-lib" :| [] Opt_WarnUntickedPromotedConstructors -> "unticked-promoted-constructors" :| [] Opt_WarnUnusedDoBind -> "unused-do-bind" :| [] @@ -1314,7 +1312,6 @@ standardWarnings -- see Note [Documenting warning flags] Opt_WarnDodgyForeignImports, Opt_WarnInlineRuleShadowing, Opt_WarnAlternativeLayoutRuleTransitional, - Opt_WarnUnsupportedLlvmVersion, Opt_WarnMissedExtraSharedLib, Opt_WarnTabs, Opt_WarnUnrecognisedWarningFlags, diff --git a/compiler/GHC/Driver/Session.hs b/compiler/GHC/Driver/Session.hs index bf1db99c3b37..21f22d359120 100644 --- a/compiler/GHC/Driver/Session.hs +++ b/compiler/GHC/Driver/Session.hs @@ -2310,7 +2310,6 @@ wWarningFlagsDeps = [minBound..maxBound] >>= \x -> case x of Opt_WarnMisplacedPragmas -> warnSpec x Opt_WarnUnsafe -> warnSpec' x setWarnUnsafe Opt_WarnUnsupportedCallingConventions -> warnSpec x - Opt_WarnUnsupportedLlvmVersion -> warnSpec x Opt_WarnMissedExtraSharedLib -> warnSpec x Opt_WarnUntickedPromotedConstructors -> warnSpec x Opt_WarnUnusedDoBind -> warnSpec x diff --git a/compiler/GHC/SysTools/Tasks.hs b/compiler/GHC/SysTools/Tasks.hs index 8f424a6d6e7c..d96046c8efc1 100644 --- a/compiler/GHC/SysTools/Tasks.hs +++ b/compiler/GHC/SysTools/Tasks.hs @@ -12,7 +12,7 @@ module GHC.SysTools.Tasks where import GHC.Prelude import GHC.ForeignSrcLang -import GHC.CmmToLlvm.Version (LlvmVersion, llvmVersionStr, supportedLlvmVersionUpperBound, parseLlvmVersion, supportedLlvmVersionLowerBound) +import GHC.CmmToLlvm.Version (LlvmVersion, parseLlvmVersion) import GHC.Settings @@ -327,14 +327,10 @@ figureLlvmVersion logger dflags = traceSystoolCommand logger "llc" $ do debugTraceMsg logger 2 (text "Error (figuring out LLVM version):" <+> text (show err)) + -- TODO: review this errorMsg logger $ vcat [ text "Warning:", nest 9 $ - text "Couldn't figure out LLVM version!" $$ - text ("Make sure you have installed LLVM between [" - ++ llvmVersionStr supportedLlvmVersionLowerBound - ++ " and " - ++ llvmVersionStr supportedLlvmVersionUpperBound - ++ ")") ] + text "Couldn't figure out LLVM version!" ] return Nothing) -- See Note [Merging object files for GHCi] in GHC.Driver.Pipeline. diff --git a/compiler/ghc.cabal.in b/compiler/ghc.cabal.in index 55083b5cdb39..b7b4c64d8d48 100644 --- a/compiler/ghc.cabal.in +++ b/compiler/ghc.cabal.in @@ -344,7 +344,6 @@ Library GHC.CmmToLlvm.Ppr GHC.CmmToLlvm.Regs GHC.CmmToLlvm.Version - GHC.CmmToLlvm.Version.Bounds GHC.CmmToLlvm.Version.Type GHC.Cmm.Dominators GHC.Cmm.Reducibility diff --git a/hadrian/src/Hadrian/Haskell/Cabal/Parse.hs b/hadrian/src/Hadrian/Haskell/Cabal/Parse.hs index 1a0177d8cfc5..2a9ce973caa6 100644 --- a/hadrian/src/Hadrian/Haskell/Cabal/Parse.hs +++ b/hadrian/src/Hadrian/Haskell/Cabal/Parse.hs @@ -126,8 +126,9 @@ biModules pd = go [ comp | comp@(bi,_,_,_) <- -- -- Put another way, while Hadrian knows these are generated, Cabal -- should just think they are regular source files. +-- TODO: Review if this is necessary extraPreConfigureDeps :: [String] -extraPreConfigureDeps = ["compiler/GHC/CmmToLlvm/Version/Bounds.hs"] +extraPreConfigureDeps = [] -- TODO: Track command line arguments and package configuration flags. -- | Configure a package using the Cabal library by collecting all the command diff --git a/hadrian/src/Rules/Generate.hs b/hadrian/src/Rules/Generate.hs index 1479f2e618a0..d7745256467d 100644 --- a/hadrian/src/Rules/Generate.hs +++ b/hadrian/src/Rules/Generate.hs @@ -77,9 +77,6 @@ rtsDependencies = do compilerDependencies :: Expr [FilePath] compilerDependencies = do - let fixed = ("compiler" -/-) <$> - [ "GHC/CmmToLlvm/Version/Bounds.hs" - ] stage <- getStage ghcPath <- expr $ buildPath (vanillaContext stage compiler) let buildSpecific = (ghcPath -/-) <$> @@ -104,7 +101,7 @@ compilerDependencies = do , "GHC/Platform/Constants.hs" , "GHC/Settings/Config.hs" ] - pure $ fixed ++ buildSpecific + pure buildSpecific generatedDependencies :: Expr [FilePath] generatedDependencies = do @@ -388,10 +385,6 @@ templateRules = do , interpolateSetting "LlvmMinVersion" LlvmMinVersion , interpolateSetting "LlvmMaxVersion" LlvmMaxVersion ] - templateRule "compiler/GHC/CmmToLlvm/Version/Bounds.hs" $ mconcat - [ interpolateVar "LlvmMinVersion" $ replaceEq '.' ',' <$> setting LlvmMinVersion - , interpolateVar "LlvmMaxVersion" $ replaceEq '.' ',' <$> setting LlvmMaxVersion - ] bindistRules bindistRules :: Rules () diff --git a/hadrian/src/Rules/Lint.hs b/hadrian/src/Rules/Lint.hs index a8b1660556a9..65b703685cd1 100644 --- a/hadrian/src/Rules/Lint.hs +++ b/hadrian/src/Rules/Lint.hs @@ -91,8 +91,7 @@ compiler = do let compilerDir = "compiler" let ghcautoconf = stage1RtsInc "ghcautoconf.h" let ghcplatform = stage1RtsInc "ghcplatform.h" - let ghcLlvmVersion = compilerDir "GHC/CmmToLlvm/Version/Bounds.hs" - need $ mconcat [[ghcautoconf, ghcplatform, ghcLlvmVersion], hsIncls stage1Compiler, [machDeps]] + need $ mconcat [[ghcautoconf, ghcplatform], hsIncls stage1Compiler, [machDeps]] let includeDirs = [ stage1RtsInc , compilerDir From 1e34a0eafbdcabadc0422b9d7d0ad7a416a49e2d Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Mon, 24 Feb 2025 13:59:58 +0800 Subject: [PATCH 11/84] refactor(rts): do not generate event types There is little value in generating a C array from a Python list. --- Build.hs | 16 -- rts/gen_event_types.py | 214 --------------- rts/include/rts/EventLogConstants.h | 82 ++++++ rts/include/rts/EventTypes.h | 392 ++++++++++++++++++++++++++++ 4 files changed, 474 insertions(+), 230 deletions(-) delete mode 100755 rts/gen_event_types.py create mode 100644 rts/include/rts/EventLogConstants.h create mode 100644 rts/include/rts/EventTypes.h diff --git a/Build.hs b/Build.hs index 1e69932df480..1162a885c536 100755 --- a/Build.hs +++ b/Build.hs @@ -382,22 +382,6 @@ prepareGhcSources opts dst = do cp "utils/fs/fs.*" (dst "libraries/rts/") cp "utils/fs/fs.*" (dst "utils/unlit/") - python <- findExecutable "python" >>= \case - Nothing -> error "Couldn't find 'python'" - Just r -> pure r - - void $ readCreateProcess (proc python - [ "rts/gen_event_types.py" - , "--event-types-defines" - , dst "libraries/rts/include/rts/EventLogConstants.h" - ]) "" - - void $ readCreateProcess (proc python - [ "rts/gen_event_types.py" - , "--event-types-array" - , dst "libraries/rts/include/rts/EventTypes.h" - ]) "" - -- substitute variables in files let subst fin fout rs = do t <- Text.readFile fin diff --git a/rts/gen_event_types.py b/rts/gen_event_types.py deleted file mode 100755 index a8dcc5279470..000000000000 --- a/rts/gen_event_types.py +++ /dev/null @@ -1,214 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -from typing import List, Union, Dict -from collections import namedtuple - -class FieldType: - def __init__(self, c_type: str): - self.c_type = c_type - -VariableLength = None -ThreadId = FieldType('EventThreadID') -KernelThreadId = FieldType('EventKernelThreadId') -CapNo = FieldType('EventCapNo') -CapsetType = FieldType('EventCapsetType') -Timestamp = FieldType('EventTimestamp') -CapsetId = FieldType('EventCapsetID') -TaskId = FieldType('EventTaskId') - -Word8 = FieldType('StgWord8') -Word16 = FieldType('StgWord16') -Word32 = FieldType('StgWord32') -Word64 = FieldType('StgWord64') - -class EventType: - def __init__(self, - n: int, - name: str, - fields: Union[VariableLength, List[FieldType]], - description: str): - self.n = n - self.name = name - self.fields = fields - self.description = description - - def __str__(self): - return '(n={n}, name={name})'.format(n=self.n, name=self.name) - -# When adding a new event type used by GHC you should also update -# NUM_GHC_EVENT_TAGS in rts/include/rts/EventLogFormat.h. -event_types = [ - EventType( 0, 'CREATE_THREAD', [ThreadId], 'Create thread'), - EventType( 1, 'RUN_THREAD', [ThreadId], 'Run thread'), - EventType( 2, 'STOP_THREAD', [ThreadId, Word16, ThreadId], 'Stop thread'), - EventType( 3, 'THREAD_RUNNABLE', [ThreadId], 'Thread runnable'), - EventType( 4, 'MIGRATE_THREAD', [ThreadId, CapNo], 'Migrate thread'), - # 5, 6, 7 deprecated - EventType( 8, 'THREAD_WAKEUP', [ThreadId, CapNo], 'Wakeup thread'), - EventType( 9, 'GC_START', [], 'Starting GC'), - EventType(10, 'GC_END', [], 'Finished GC'), - EventType(11, 'REQUEST_SEQ_GC', [], 'Request sequential GC'), - EventType(12, 'REQUEST_PAR_GC', [], 'Request parallel GC'), - # 13, 14 deprecated - EventType(15, 'CREATE_SPARK_THREAD', [ThreadId], 'Create spark thread'), - EventType(16, 'LOG_MSG', VariableLength, 'Log message'), - # 17 deprecated - EventType(18, 'BLOCK_MARKER', [Word32, Timestamp, CapNo], 'Block marker'), - EventType(19, 'USER_MSG', VariableLength, 'User message'), - EventType(20, 'GC_IDLE', [], 'GC idle'), - EventType(21, 'GC_WORK', [], 'GC working'), - EventType(22, 'GC_DONE', [], 'GC done'), - # 23, 24 used by eden - EventType(25, 'CAPSET_CREATE', [CapsetId, CapsetType], 'Create capability set'), - EventType(26, 'CAPSET_DELETE', [CapsetId], 'Delete capability set'), - EventType(27, 'CAPSET_ASSIGN_CAP',[CapsetId, CapNo], 'Add capability to capability set'), - EventType(28, 'CAPSET_REMOVE_CAP',[CapsetId, CapNo], 'Remove capability from capability set'), - EventType(29, 'RTS_IDENTIFIER', VariableLength, 'RTS name and version'), - EventType(30, 'PROGRAM_ARGS', VariableLength, 'Program arguments'), - EventType(31, 'PROGRAM_ENV', VariableLength, 'Program environment variables'), - EventType(32, 'OSPROCESS_PID', [CapsetId, Word32], 'Process ID'), - EventType(33, 'OSPROCESS_PPID', [CapsetId, Word32], 'Parent process ID'), - EventType(34, 'SPARK_COUNTERS', 7*[Word64], 'Spark counters'), - EventType(35, 'SPARK_CREATE', [], 'Spark create'), - EventType(36, 'SPARK_DUD', [], 'Spark dud'), - EventType(37, 'SPARK_OVERFLOW', [], 'Spark overflow'), - EventType(38, 'SPARK_RUN', [], 'Spark run'), - EventType(39, 'SPARK_STEAL', [CapNo], 'Spark steal'), - EventType(40, 'SPARK_FIZZLE', [], 'Spark fizzle'), - EventType(41, 'SPARK_GC', [], 'Spark GC'), - EventType(42, 'INTERN_STRING', VariableLength, 'Intern string'), - EventType(43, 'WALL_CLOCK_TIME', [CapsetId, Word64, Word32], 'Wall clock time'), - EventType(44, 'THREAD_LABEL', VariableLength, 'Thread label'), - EventType(45, 'CAP_CREATE', [CapNo], 'Create capability'), - EventType(46, 'CAP_DELETE', [CapNo], 'Delete capability'), - EventType(47, 'CAP_DISABLE', [CapNo], 'Disable capability'), - EventType(48, 'CAP_ENABLE', [CapNo], 'Enable capability'), - EventType(49, 'HEAP_ALLOCATED', [CapsetId, Word64], 'Total heap memory ever allocated'), - EventType(50, 'HEAP_SIZE', [CapsetId, Word64], 'Current heap size (number of allocated mblocks)'), - EventType(51, 'HEAP_LIVE', [CapsetId, Word64], 'Current heap live data'), - EventType(52, 'HEAP_INFO_GHC', [CapsetId, Word16] + 4*[Word64], 'Heap static parameters'), - EventType(53, 'GC_STATS_GHC', [CapsetId, Word16] + 3*[Word64] + [Word32] + 3*[Word64], 'GC statistics'), - EventType(54, 'GC_GLOBAL_SYNC', [], 'Synchronise stop-the-world GC'), - EventType(55, 'TASK_CREATE', [TaskId, CapNo, KernelThreadId], 'Task create'), - EventType(56, 'TASK_MIGRATE', [TaskId, CapNo, CapNo], 'Task migrate'), - EventType(57, 'TASK_DELETE', [TaskId], 'Task delete'), - EventType(58, 'USER_MARKER', VariableLength, 'User marker'), - EventType(59, 'HACK_BUG_T9003', [], 'Empty event for bug #9003'), - - # Range 60 - 80 is used by eden for parallel tracing. - # See http://www.mathematik.uni-marburg.de/~eden/ - - EventType(90, 'MEM_RETURN', [CapsetId, Word32, Word32, Word32], 'The RTS attempted to return heap memory to the OS'), - EventType(91, 'BLOCKS_SIZE', [CapsetId, Word64], 'Report the size of the heap in blocks'), - - # Range 100 - 139 is reserved for Mercury. - - # Range 140 - 159 is reserved for Perf events. - - # Range 160 - 180 is reserved for cost-centre heap profiling events. - - # Cost-centre profiler - EventType(160, 'HEAP_PROF_BEGIN', VariableLength, 'Start of heap profile'), - EventType(161, 'HEAP_PROF_COST_CENTRE', VariableLength, 'Cost-centre definition'), - EventType(162, 'HEAP_PROF_SAMPLE_BEGIN', [Word64], 'Start of heap profile sample'), - EventType(163, 'HEAP_PROF_SAMPLE_COST_CENTRE', VariableLength, 'Heap profile cost-centre sample'), - EventType(164, 'HEAP_PROF_SAMPLE_STRING', VariableLength, 'Heap profile string sample'), - EventType(165, 'HEAP_PROF_SAMPLE_END', [Word64], 'End of heap profile sample'), - EventType(166, 'HEAP_BIO_PROF_SAMPLE_BEGIN', [Word64, Word64], 'Start of heap profile (biographical) sample'), - - EventType(167, 'PROF_SAMPLE_COST_CENTRE', VariableLength, 'Time profile cost-centre stack'), - EventType(168, 'PROF_BEGIN', [Word64], 'Start of a time profile'), - EventType(169, 'IPE', VariableLength, 'An IPE entry'), - - EventType(181, 'USER_BINARY_MSG', VariableLength, 'User binary message'), - - # Non-moving GC - EventType(200, 'CONC_MARK_BEGIN', [], 'Begin concurrent mark phase'), - EventType(201, 'CONC_MARK_END', [Word32], 'End concurrent mark phase'), - EventType(202, 'CONC_SYNC_BEGIN', [], 'Begin concurrent GC synchronisation'), - EventType(203, 'CONC_SYNC_END', [], 'End concurrent mark synchronisation'), - EventType(204, 'CONC_SWEEP_BEGIN', [], 'Begin concurrent sweep phase'), - EventType(205, 'CONC_SWEEP_END', [], 'End concurrent sweep phase'), - EventType(206, 'CONC_UPD_REM_SET_FLUSH', [CapNo], 'Update remembered set flushed'), - EventType(207, 'NONMOVING_HEAP_CENSUS', [Word16, Word32, Word32, Word32], 'Nonmoving heap census'), - EventType(208, 'NONMOVING_PRUNED_SEGMENTS', [Word32, Word32], 'Report the amount of segments pruned and remaining on the free list.'), - - # Ticky-ticky profiling - EventType(210, 'TICKY_COUNTER_DEF', VariableLength, 'Ticky-ticky entry counter definition'), - EventType(211, 'TICKY_COUNTER_SAMPLE', 4*[Word64], 'Ticky-ticky entry counter sample'), - EventType(212, 'TICKY_COUNTER_BEGIN_SAMPLE', [], 'Ticky-ticky entry counter begin sample'), -] - -def check_events() -> Dict[int, EventType]: - seen_ids = {} - for ty in event_types: - if ty.n in seen_ids: - print('Duplicate event type {n}:'.format(n=ty.n)) - print(' {name}'.format(name=ty.name)) - print(' {seen}'.format(seen=seen_ids[ty.n].name)) - assert False - - seen_ids[ty.n] = ty - - return seen_ids - -def generate_event_types_array() -> str: - x = [] - pr = lambda s: x.append(s) - - pr('/*') - pr(' * Do not edit: This file is generated by gen_event_types.py') - pr(' */') - pr('') - pr('EventType eventTypes[] = {') - for ty in event_types: - if ty.fields is VariableLength: - length = '0xffff' - elif len(ty.fields) == 0: - length = '0' - else: - length = ' + '.join('sizeof({c_type})'.format(c_type=field.c_type) - for field in ty.fields) - - pr(' [EVENT_{}] = {{'.format(ty.name)) - pr(' .etNum = {},'.format(ty.n)) - pr(' .size = {},'.format(length)) - pr(' .desc = "{}"'.format(ty.description)) - pr(' },') - - pr('};') - return '\n'.join(x) - -def generate_event_types_defines() -> str: - x = [] - pr = lambda s: x.append(s) - - pr('/*') - pr(' * Do not edit: This file is generated by gen_event_types.py') - pr(' */') - pr('') - pr('#pragma once') - pr('') - for ty in event_types: - pr('#define EVENT_{name} {n}'.format(name=ty.name, n=ty.n)) - - return '\n'.join(x) - -def main() -> None: - import argparse - parser = argparse.ArgumentParser() - parser.add_argument('--event-types-array', type=argparse.FileType('w'), metavar='FILE') - parser.add_argument('--event-types-defines', type=argparse.FileType('w'), metavar='FILE') - args = parser.parse_args() - - check_events() - - if args.event_types_array: - args.event_types_array.write(generate_event_types_array()) - - if args.event_types_defines: - args.event_types_defines.write(generate_event_types_defines()) - -if __name__ == '__main__': - main() diff --git a/rts/include/rts/EventLogConstants.h b/rts/include/rts/EventLogConstants.h new file mode 100644 index 000000000000..44956698c935 --- /dev/null +++ b/rts/include/rts/EventLogConstants.h @@ -0,0 +1,82 @@ +#pragma once + +// When adding a new event type used by GHC you should also update +// NUM_GHC_EVENT_TAGS in include/rts/EventLogFormat.h. + +#define EVENT_CREATE_THREAD 0 +#define EVENT_RUN_THREAD 1 +#define EVENT_STOP_THREAD 2 +#define EVENT_THREAD_RUNNABLE 3 +#define EVENT_MIGRATE_THREAD 4 +#define EVENT_THREAD_WAKEUP 8 +#define EVENT_GC_START 9 +#define EVENT_GC_END 10 +#define EVENT_REQUEST_SEQ_GC 11 +#define EVENT_REQUEST_PAR_GC 12 +#define EVENT_CREATE_SPARK_THREAD 15 +#define EVENT_LOG_MSG 16 +#define EVENT_BLOCK_MARKER 18 +#define EVENT_USER_MSG 19 +#define EVENT_GC_IDLE 20 +#define EVENT_GC_WORK 21 +#define EVENT_GC_DONE 22 +#define EVENT_CAPSET_CREATE 25 +#define EVENT_CAPSET_DELETE 26 +#define EVENT_CAPSET_ASSIGN_CAP 27 +#define EVENT_CAPSET_REMOVE_CAP 28 +#define EVENT_RTS_IDENTIFIER 29 +#define EVENT_PROGRAM_ARGS 30 +#define EVENT_PROGRAM_ENV 31 +#define EVENT_OSPROCESS_PID 32 +#define EVENT_OSPROCESS_PPID 33 +#define EVENT_SPARK_COUNTERS 34 +#define EVENT_SPARK_CREATE 35 +#define EVENT_SPARK_DUD 36 +#define EVENT_SPARK_OVERFLOW 37 +#define EVENT_SPARK_RUN 38 +#define EVENT_SPARK_STEAL 39 +#define EVENT_SPARK_FIZZLE 40 +#define EVENT_SPARK_GC 41 +#define EVENT_INTERN_STRING 42 +#define EVENT_WALL_CLOCK_TIME 43 +#define EVENT_THREAD_LABEL 44 +#define EVENT_CAP_CREATE 45 +#define EVENT_CAP_DELETE 46 +#define EVENT_CAP_DISABLE 47 +#define EVENT_CAP_ENABLE 48 +#define EVENT_HEAP_ALLOCATED 49 +#define EVENT_HEAP_SIZE 50 +#define EVENT_HEAP_LIVE 51 +#define EVENT_HEAP_INFO_GHC 52 +#define EVENT_GC_STATS_GHC 53 +#define EVENT_GC_GLOBAL_SYNC 54 +#define EVENT_TASK_CREATE 55 +#define EVENT_TASK_MIGRATE 56 +#define EVENT_TASK_DELETE 57 +#define EVENT_USER_MARKER 58 +#define EVENT_HACK_BUG_T9003 59 +#define EVENT_MEM_RETURN 90 +#define EVENT_BLOCKS_SIZE 91 +#define EVENT_HEAP_PROF_BEGIN 160 +#define EVENT_HEAP_PROF_COST_CENTRE 161 +#define EVENT_HEAP_PROF_SAMPLE_BEGIN 162 +#define EVENT_HEAP_PROF_SAMPLE_COST_CENTRE 163 +#define EVENT_HEAP_PROF_SAMPLE_STRING 164 +#define EVENT_HEAP_PROF_SAMPLE_END 165 +#define EVENT_HEAP_BIO_PROF_SAMPLE_BEGIN 166 +#define EVENT_PROF_SAMPLE_COST_CENTRE 167 +#define EVENT_PROF_BEGIN 168 +#define EVENT_IPE 169 +#define EVENT_USER_BINARY_MSG 181 +#define EVENT_CONC_MARK_BEGIN 200 +#define EVENT_CONC_MARK_END 201 +#define EVENT_CONC_SYNC_BEGIN 202 +#define EVENT_CONC_SYNC_END 203 +#define EVENT_CONC_SWEEP_BEGIN 204 +#define EVENT_CONC_SWEEP_END 205 +#define EVENT_CONC_UPD_REM_SET_FLUSH 206 +#define EVENT_NONMOVING_HEAP_CENSUS 207 +#define EVENT_NONMOVING_PRUNED_SEGMENTS 208 +#define EVENT_TICKY_COUNTER_DEF 210 +#define EVENT_TICKY_COUNTER_SAMPLE 211 +#define EVENT_TICKY_COUNTER_BEGIN_SAMPLE 212 diff --git a/rts/include/rts/EventTypes.h b/rts/include/rts/EventTypes.h new file mode 100644 index 000000000000..4cf4acda8da6 --- /dev/null +++ b/rts/include/rts/EventTypes.h @@ -0,0 +1,392 @@ +#pragma once + +// When adding a new event type used by GHC you should also update +// NUM_GHC_EVENT_TAGS in include/rts/EventLogFormat.h. + +EventType eventTypes[] = { + [EVENT_CREATE_THREAD] = { + .etNum = EVENT_CREATE_THREAD, + .size = sizeof(EventThreadID), + .desc = "Create thread" + }, + [EVENT_RUN_THREAD] = { + .etNum = EVENT_RUN_THREAD, + .size = sizeof(EventThreadID), + .desc = "Run thread" + }, + [EVENT_STOP_THREAD] = { + .etNum = EVENT_STOP_THREAD, + .size = sizeof(EventThreadID) + sizeof(StgWord16) + sizeof(EventThreadID), + .desc = "Stop thread" + }, + [EVENT_THREAD_RUNNABLE] = { + .etNum = EVENT_THREAD_RUNNABLE, + .size = sizeof(EventThreadID), + .desc = "Thread runnable" + }, + [EVENT_MIGRATE_THREAD] = { + .etNum = EVENT_MIGRATE_THREAD, + .size = sizeof(EventThreadID) + sizeof(EventCapNo), + .desc = "Migrate thread" + }, + [EVENT_THREAD_WAKEUP] = { + .etNum = EVENT_THREAD_WAKEUP, + .size = sizeof(EventThreadID) + sizeof(EventCapNo), + .desc = "Wakeup thread" + }, + [EVENT_GC_START] = { + .etNum = EVENT_GC_START, + .size = 0, + .desc = "Starting GC" + }, + [EVENT_GC_END] = { + .etNum = EVENT_GC_END , + .size = 0, + .desc = "Finished GC" + }, + [EVENT_REQUEST_SEQ_GC] = { + .etNum = EVENT_REQUEST_SEQ_GC , + .size = 0, + .desc = "Request sequential GC" + }, + [EVENT_REQUEST_PAR_GC] = { + .etNum = EVENT_REQUEST_PAR_GC , + .size = 0, + .desc = "Request parallel GC" + }, + [EVENT_CREATE_SPARK_THREAD] = { + .etNum = EVENT_CREATE_SPARK_THREAD , + .size = sizeof(EventThreadID), + .desc = "Create spark thread" + }, + [EVENT_LOG_MSG] = { + .etNum = EVENT_LOG_MSG , + .size = 0xffff, + .desc = "Log message" + }, + [EVENT_BLOCK_MARKER] = { + .etNum = EVENT_BLOCK_MARKER , + .size = sizeof(StgWord32) + sizeof(EventTimestamp) + sizeof(EventCapNo), + .desc = "Block marker" + }, + [EVENT_USER_MSG] = { + .etNum = EVENT_USER_MSG , + .size = 0xffff, + .desc = "User message" + }, + [EVENT_GC_IDLE] = { + .etNum = EVENT_GC_IDLE , + .size = 0, + .desc = "GC idle" + }, + [EVENT_GC_WORK] = { + .etNum = EVENT_GC_WORK , + .size = 0, + .desc = "GC working" + }, + [EVENT_GC_DONE] = { + .etNum = EVENT_GC_DONE , + .size = 0, + .desc = "GC done" + }, + [EVENT_CAPSET_CREATE] = { + .etNum = EVENT_CAPSET_CREATE , + .size = sizeof(EventCapsetID) + sizeof(EventCapsetType), + .desc = "Create capability set" + }, + [EVENT_CAPSET_DELETE] = { + .etNum = EVENT_CAPSET_DELETE , + .size = sizeof(EventCapsetID), + .desc = "Delete capability set" + }, + [EVENT_CAPSET_ASSIGN_CAP] = { + .etNum = EVENT_CAPSET_ASSIGN_CAP , + .size = sizeof(EventCapsetID) + sizeof(EventCapNo), + .desc = "Add capability to capability set" + }, + [EVENT_CAPSET_REMOVE_CAP] = { + .etNum = EVENT_CAPSET_REMOVE_CAP , + .size = sizeof(EventCapsetID) + sizeof(EventCapNo), + .desc = "Remove capability from capability set" + }, + [EVENT_RTS_IDENTIFIER] = { + .etNum = EVENT_RTS_IDENTIFIER , + .size = 0xffff, + .desc = "RTS name and version" + }, + [EVENT_PROGRAM_ARGS] = { + .etNum = EVENT_PROGRAM_ARGS , + .size = 0xffff, + .desc = "Program arguments" + }, + [EVENT_PROGRAM_ENV] = { + .etNum = EVENT_PROGRAM_ENV , + .size = 0xffff, + .desc = "Program environment variables" + }, + [EVENT_OSPROCESS_PID] = { + .etNum = EVENT_OSPROCESS_PID , + .size = sizeof(EventCapsetID) + sizeof(StgWord32), + .desc = "Process ID" + }, + [EVENT_OSPROCESS_PPID] = { + .etNum = EVENT_OSPROCESS_PPID , + .size = sizeof(EventCapsetID) + sizeof(StgWord32), + .desc = "Parent process ID" + }, + [EVENT_SPARK_COUNTERS] = { + .etNum = EVENT_SPARK_COUNTERS , + .size = sizeof(StgWord64) + sizeof(StgWord64) + sizeof(StgWord64) + sizeof(StgWord64) + sizeof(StgWord64) + sizeof(StgWord64) + sizeof(StgWord64), + .desc = "Spark counters" + }, + [EVENT_SPARK_CREATE] = { + .etNum = EVENT_SPARK_CREATE , + .size = 0, + .desc = "Spark create" + }, + [EVENT_SPARK_DUD] = { + .etNum = EVENT_SPARK_DUD , + .size = 0, + .desc = "Spark dud" + }, + [EVENT_SPARK_OVERFLOW] = { + .etNum = EVENT_SPARK_OVERFLOW , + .size = 0, + .desc = "Spark overflow" + }, + [EVENT_SPARK_RUN] = { + .etNum = EVENT_SPARK_RUN , + .size = 0, + .desc = "Spark run" + }, + [EVENT_SPARK_STEAL] = { + .etNum = EVENT_SPARK_STEAL , + .size = sizeof(EventCapNo), + .desc = "Spark steal" + }, + [EVENT_SPARK_FIZZLE] = { + .etNum = EVENT_SPARK_FIZZLE , + .size = 0, + .desc = "Spark fizzle" + }, + [EVENT_SPARK_GC] = { + .etNum = EVENT_SPARK_GC , + .size = 0, + .desc = "Spark GC" + }, + [EVENT_INTERN_STRING] = { + .etNum = EVENT_INTERN_STRING , + .size = 0xffff, + .desc = "Intern string" + }, + [EVENT_WALL_CLOCK_TIME] = { + .etNum = EVENT_WALL_CLOCK_TIME , + .size = sizeof(EventCapsetID) + sizeof(StgWord64) + sizeof(StgWord32), + .desc = "Wall clock time" + }, + [EVENT_THREAD_LABEL] = { + .etNum = EVENT_THREAD_LABEL , + .size = 0xffff, + .desc = "Thread label" + }, + [EVENT_CAP_CREATE] = { + .etNum = EVENT_CAP_CREATE , + .size = sizeof(EventCapNo), + .desc = "Create capability" + }, + [EVENT_CAP_DELETE] = { + .etNum = EVENT_CAP_DELETE , + .size = sizeof(EventCapNo), + .desc = "Delete capability" + }, + [EVENT_CAP_DISABLE] = { + .etNum = EVENT_CAP_DISABLE , + .size = sizeof(EventCapNo), + .desc = "Disable capability" + }, + [EVENT_CAP_ENABLE] = { + .etNum = EVENT_CAP_ENABLE , + .size = sizeof(EventCapNo), + .desc = "Enable capability" + }, + [EVENT_HEAP_ALLOCATED] = { + .etNum = EVENT_HEAP_ALLOCATED , + .size = sizeof(EventCapsetID) + sizeof(StgWord64), + .desc = "Total heap memory ever allocated" + }, + [EVENT_HEAP_SIZE] = { + .etNum = EVENT_HEAP_SIZE , + .size = sizeof(EventCapsetID) + sizeof(StgWord64), + .desc = "Current heap size (number of allocated mblocks)" + }, + [EVENT_HEAP_LIVE] = { + .etNum = EVENT_HEAP_LIVE , + .size = sizeof(EventCapsetID) + sizeof(StgWord64), + .desc = "Current heap live data" + }, + [EVENT_HEAP_INFO_GHC] = { + .etNum = EVENT_HEAP_INFO_GHC , + .size = sizeof(EventCapsetID) + sizeof(StgWord16) + sizeof(StgWord64) + sizeof(StgWord64) + sizeof(StgWord64) + sizeof(StgWord64), + .desc = "Heap static parameters" + }, + [EVENT_GC_STATS_GHC] = { + .etNum = EVENT_GC_STATS_GHC , + .size = sizeof(EventCapsetID) + sizeof(StgWord16) + sizeof(StgWord64) + sizeof(StgWord64) + sizeof(StgWord64) + sizeof(StgWord32) + sizeof(StgWord64) + sizeof(StgWord64) + sizeof(StgWord64), + .desc = "GC statistics" + }, + [EVENT_GC_GLOBAL_SYNC] = { + .etNum = EVENT_GC_GLOBAL_SYNC , + .size = 0, + .desc = "Synchronise stop-the-world GC" + }, + [EVENT_TASK_CREATE] = { + .etNum = EVENT_TASK_CREATE , + .size = sizeof(EventTaskId) + sizeof(EventCapNo) + sizeof(EventKernelThreadId), + .desc = "Task create" + }, + [EVENT_TASK_MIGRATE] = { + .etNum = EVENT_TASK_MIGRATE , + .size = sizeof(EventTaskId) + sizeof(EventCapNo) + sizeof(EventCapNo), + .desc = "Task migrate" + }, + [EVENT_TASK_DELETE] = { + .etNum = EVENT_TASK_DELETE , + .size = sizeof(EventTaskId), + .desc = "Task delete" + }, + [EVENT_USER_MARKER] = { + .etNum = EVENT_USER_MARKER , + .size = 0xffff, + .desc = "User marker" + }, + [EVENT_HACK_BUG_T9003] = { + .etNum = EVENT_HACK_BUG_T9003 , + .size = 0, + .desc = "Empty event for bug #9003" + }, + [EVENT_MEM_RETURN] = { + .etNum = EVENT_MEM_RETURN , + .size = sizeof(EventCapsetID) + sizeof(StgWord32) + sizeof(StgWord32) + sizeof(StgWord32), + .desc = "The RTS attempted to return heap memory to the OS" + }, + [EVENT_BLOCKS_SIZE] = { + .etNum = EVENT_BLOCKS_SIZE , + .size = sizeof(EventCapsetID) + sizeof(StgWord64), + .desc = "Report the size of the heap in blocks" + }, + [EVENT_HEAP_PROF_BEGIN] = { + .etNum = EVENT_HEAP_PROF_BEGIN, + .size = 0xffff, + .desc = "Start of heap profile" + }, + [EVENT_HEAP_PROF_COST_CENTRE] = { + .etNum = EVENT_HEAP_PROF_COST_CENTRE, + .size = 0xffff, + .desc = "Cost-centre definition" + }, + [EVENT_HEAP_PROF_SAMPLE_BEGIN] = { + .etNum = EVENT_HEAP_PROF_SAMPLE_BEGIN, + .size = sizeof(StgWord64), + .desc = "Start of heap profile sample" + }, + [EVENT_HEAP_PROF_SAMPLE_COST_CENTRE] = { + .etNum = EVENT_HEAP_PROF_SAMPLE_COST_CENTRE, + .size = 0xffff, + .desc = "Heap profile cost-centre sample" + }, + [EVENT_HEAP_PROF_SAMPLE_STRING] = { + .etNum = EVENT_HEAP_PROF_SAMPLE_STRING, + .size = 0xffff, + .desc = "Heap profile string sample" + }, + [EVENT_HEAP_PROF_SAMPLE_END] = { + .etNum = EVENT_HEAP_PROF_SAMPLE_END, + .size = sizeof(StgWord64), + .desc = "End of heap profile sample" + }, + [EVENT_HEAP_BIO_PROF_SAMPLE_BEGIN] = { + .etNum = EVENT_HEAP_BIO_PROF_SAMPLE_BEGIN, + .size = sizeof(StgWord64) + sizeof(StgWord64), + .desc = "Start of heap profile (biographical) sample" + }, + [EVENT_PROF_SAMPLE_COST_CENTRE] = { + .etNum = EVENT_PROF_SAMPLE_COST_CENTRE, + .size = 0xffff, + .desc = "Time profile cost-centre stack" + }, + [EVENT_PROF_BEGIN] = { + .etNum = EVENT_PROF_BEGIN, + .size = sizeof(StgWord64), + .desc = "Start of a time profile" + }, + [EVENT_IPE] = { + .etNum = EVENT_IPE, + .size = 0xffff, + .desc = "An IPE entry" + }, + [EVENT_USER_BINARY_MSG] = { + .etNum = EVENT_USER_BINARY_MSG, + .size = 0xffff, + .desc = "User binary message" + }, + [EVENT_CONC_MARK_BEGIN] = { + .etNum = EVENT_CONC_MARK_BEGIN, + .size = 0, + .desc = "Begin concurrent mark phase" + }, + [EVENT_CONC_MARK_END] = { + .etNum = EVENT_CONC_MARK_END, + .size = sizeof(StgWord32), + .desc = "End concurrent mark phase" + }, + [EVENT_CONC_SYNC_BEGIN] = { + .etNum = EVENT_CONC_SYNC_BEGIN, + .size = 0, + .desc = "Begin concurrent GC synchronisation" + }, + [EVENT_CONC_SYNC_END] = { + .etNum = EVENT_CONC_SYNC_END, + .size = 0, + .desc = "End concurrent mark synchronisation" + }, + [EVENT_CONC_SWEEP_BEGIN] = { + .etNum = EVENT_CONC_SWEEP_BEGIN, + .size = 0, + .desc = "Begin concurrent sweep phase" + }, + [EVENT_CONC_SWEEP_END] = { + .etNum = EVENT_CONC_SWEEP_END, + .size = 0, + .desc = "End concurrent sweep phase" + }, + [EVENT_CONC_UPD_REM_SET_FLUSH] = { + .etNum = EVENT_CONC_UPD_REM_SET_FLUSH, + .size = sizeof(EventCapNo), + .desc = "Update remembered set flushed" + }, + [EVENT_NONMOVING_HEAP_CENSUS] = { + .etNum = EVENT_NONMOVING_HEAP_CENSUS, + .size = sizeof(StgWord16) + sizeof(StgWord32) + sizeof(StgWord32) + sizeof(StgWord32), + .desc = "Nonmoving heap census" + }, + [EVENT_NONMOVING_PRUNED_SEGMENTS] = { + .etNum = EVENT_NONMOVING_PRUNED_SEGMENTS, + .size = sizeof(StgWord32) + sizeof(StgWord32), + .desc = "Report the amount of segments pruned and remaining on the free list." + }, + [EVENT_TICKY_COUNTER_DEF] = { + .etNum = EVENT_TICKY_COUNTER_DEF, + .size = 0xffff, + .desc = "Ticky-ticky entry counter definition" + }, + [EVENT_TICKY_COUNTER_SAMPLE] = { + .etNum = EVENT_TICKY_COUNTER_SAMPLE, + .size = sizeof(StgWord64) + sizeof(StgWord64) + sizeof(StgWord64) + sizeof(StgWord64), + .desc = "Ticky-ticky entry counter sample" + }, + [EVENT_TICKY_COUNTER_BEGIN_SAMPLE] = { + .etNum = EVENT_TICKY_COUNTER_BEGIN_SAMPLE, + .size = 0, + .desc = "Ticky-ticky entry counter begin sample" + }, +}; From 5ff07b4747dec58ce3d15209462957fbf93b08b1 Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Fri, 24 Jan 2025 14:06:35 +0800 Subject: [PATCH 12/84] ci: switch to haskell/ghcup-setup@v1 --- .github/workflows/ci.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 73fc20a851b8..1bf221ccfbe4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,13 +24,12 @@ jobs: with: submodules: "recursive" - - uses: haskell-actions/setup@v2 - id: setup - name: Setup Haskell tools + - uses: haskell/ghcup-setup@v1 with: - ghc-version: ${{ matrix.ghc }} - cabal-version: "latest" - cabal-update: true + ghc: ${{ matrix.ghc }} + cabal: latest + + - run: cabal update - name: Build patched cabal run: make cabal From c7ddac23322090cb728ba02f7efa6d0d7f26cae0 Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Fri, 14 Feb 2025 14:51:21 +0800 Subject: [PATCH 13/84] ci: cache aggressively --- .github/workflows/ci.yml | 65 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1bf221ccfbe4..869442a1b5f7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,12 +25,49 @@ jobs: submodules: "recursive" - uses: haskell/ghcup-setup@v1 + + - id: ghcup + run: | + ghcup config set cache true + echo "basedir=$(ghcup whereis basedir)" >> $GITHUB_OUTPUT + + - id: ghcup-cache + name: Cache GHCup basedir + uses: actions/cache@v4 with: - ghc: ${{ matrix.ghc }} - cabal: latest + key: ghcup-basedir-${{ github.run_id }} + restore-keys: ghcup-basedir- + path: ${{ steps.ghcup.outputs.basedir }} + + - run: | + ghcup install ghc --set ${{ matrix.ghc }} + ghcup install cabal --set + + - id: cabal-paths + run: | + cabal user-config init + echo "store=$(cabal path --store-dir)" >> $GITHUB_OUTPUT + echo "remote-repo-cache=$(cabal path --remote-repo-cache)" >> $GITHUB_OUTPUT + - name: Restore Hackage index + uses: actions/cache/restore@v4 + with: + key: hackage-${{ github.run_id }} + restore-keys: hackage- + path: ${{ steps.cabal-paths.outputs.remote-repo-cache }} + - run: cabal update + - name: Restore build artifacts + uses: actions/cache/restore@v4 + with: + key: ${{ matrix.os }}-${{ matrix.ghc }}-${{ github.run_id }} + restore-keys: ${{ matrix.os }}-${{ matrix.ghc }}- + path: | + ${{ steps.cabal-paths.outputs.store }} + libraries/Cabal/dist-newstyle + _build + - name: Build patched cabal run: make cabal @@ -61,3 +98,27 @@ jobs: _build/test-perf.csv _build/test-summary.txt _build/test-junit.xml + + - name: Save GHCup cache + uses: actions/cache/save@v4 + if: always() + with: + key: ghcup-${{ github.run_id }} + path: ${{ steps.ghcup.outputs.cachedir }} + + - name: Save Hackage index + uses: actions/cache/save@v4 + if: always() + with: + key: hackage-${{ github.run_id }} + path: ${{ steps.cabal-paths.outputs.remote-repo-cache }} + + - name: Save build artifacts + if: always() + uses: actions/cache/save@v4 + with: + key: ${{ matrix.os }}-${{ matrix.ghc }}-${{ github.run_id }} + path: | + ${{ steps.cabal-paths.outputs.store }} + libraries/Cabal/dist-newstyle + _build From 269c895ce04c5d538d60d58f36535f278000dcc5 Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Thu, 20 Feb 2025 16:37:31 +1100 Subject: [PATCH 14/84] feat: inline all the versions --- .gitignore | 21 --------- Build.hs | 44 ++----------------- compiler/{ghc.cabal.in => ghc.cabal} | 19 ++++---- ...ci-wrapper.cabal.in => ghci-wrapper.cabal} | 19 ++++---- ghc/{ghc-bin.cabal.in => ghc-bin.cabal} | 20 ++++----- libraries/base/{base.cabal.in => base.cabal} | 7 +-- ...ghc-boot-th.cabal.in => ghc-boot-th.cabal} | 17 +++---- .../{ghc-boot.cabal.in => ghc-boot.cabal} | 14 +++--- ...mental.cabal.in => ghc-experimental.cabal} | 12 ++--- .../{ghc-heap.cabal.in => ghc-heap.cabal} | 6 ++- ...c-internal.cabal.in => ghc-internal.cabal} | 7 +-- libraries/ghci/{ghci.cabal.in => ghci.cabal} | 23 +++++----- ...askell.cabal.in => template-haskell.cabal} | 11 ++--- .../{ghc-pkg.cabal.in => ghc-pkg.cabal} | 11 ++--- utils/iserv/{iserv.cabal.in => iserv.cabal} | 16 +++---- ...mote-iserv.cabal.in => remote-iserv.cabal} | 16 +++---- .../runghc/{runghc.cabal.in => runghc.cabal} | 11 ++--- 17 files changed, 91 insertions(+), 183 deletions(-) rename compiler/{ghc.cabal.in => ghc.cabal} (98%) rename driver/ghci/{ghci-wrapper.cabal.in => ghci-wrapper.cabal} (68%) rename ghc/{ghc-bin.cabal.in => ghc-bin.cabal} (85%) rename libraries/base/{base.cabal.in => base.cabal} (97%) rename libraries/ghc-boot-th/{ghc-boot-th.cabal.in => ghc-boot-th.cabal} (83%) rename libraries/ghc-boot/{ghc-boot.cabal.in => ghc-boot.cabal} (90%) rename libraries/ghc-experimental/{ghc-experimental.cabal.in => ghc-experimental.cabal} (73%) rename libraries/ghc-heap/{ghc-heap.cabal.in => ghc-heap.cabal} (93%) rename libraries/ghc-internal/{ghc-internal.cabal.in => ghc-internal.cabal} (97%) rename libraries/ghci/{ghci.cabal.in => ghci.cabal} (85%) rename libraries/template-haskell/{template-haskell.cabal.in => template-haskell.cabal} (84%) rename utils/ghc-pkg/{ghc-pkg.cabal.in => ghc-pkg.cabal} (86%) rename utils/iserv/{iserv.cabal.in => iserv.cabal} (77%) rename utils/remote-iserv/{remote-iserv.cabal.in => remote-iserv.cabal} (64%) rename utils/runghc/{runghc.cabal.in => runghc.cabal} (84%) diff --git a/.gitignore b/.gitignore index a96f6c05bb1b..efaf03e63064 100644 --- a/.gitignore +++ b/.gitignore @@ -116,8 +116,6 @@ _darcs/ /compiler/MachRegs.h /compiler/MachRegs /compiler/GHC/CmmToLlvm/Version/Bounds.hs -/compiler/ghc.cabal -/compiler/ghc.cabal.old /distrib/configure.ac /distrib/ghc.iss /docs/index.html @@ -138,7 +136,6 @@ _darcs/ /docs/users_guide/utils.pyc /driver/ghci/ghc-pkg-inplace /driver/ghci/ghci-inplace -/driver/ghci/ghci-wrapper.cabal /driver/ghci/ghci.res /driver/ghci/cwrapper.c /driver/ghci/cwrapper.h @@ -150,7 +147,6 @@ _darcs/ /driver/package.conf.inplace.old /settings /ghc.spec -/ghc/ghc-bin.cabal /index.html /inplace/ /libffi/build/ @@ -165,29 +161,19 @@ _darcs/ /libraries/doc-index*.html /libraries/frames.html /libraries/ghc-boot/GNUmakefile -/libraries/ghc-boot/ghc-boot.cabal /libraries/ghc-boot-th/GNUmakefile -/libraries/ghc-boot-th/ghc-boot-th.cabal -/libraries/ghc-boot-th-next/ghc-boot-th-next.cabal /libraries/ghc-boot-th/ghc.mk -/libraries/ghc-heap/ghc-heap.cabal -/libraries/ghc-internal/ghc-internal.cabal -/libraries/ghc-experimental/ghc-experimental.cabal -/libraries/base/base.cabal /libraries/ghci/GNUmakefile -/libraries/ghci/ghci.cabal /libraries/ghci/ghc.mk /libraries/haddock-util.js /libraries/hslogo-16.png /libraries/index-frames.html /libraries/index.html -/libraries/libiserv/libiserv.cabal /libraries/minus.gif /libraries/ocean.css /libraries/plus.gif /libraries/synopsis.png /libraries/stamp/ -/libraries/template-haskell/template-haskell.cabal /linter.log /mk/are-validating.mk /mk/build.mk @@ -202,13 +188,6 @@ _darcs/ /testsuite_summary*.txt /testsuite*.xml /testlog* -/utils/iserv/iserv.cabal -/utils/iserv-proxy/iserv-proxy.cabal -/utils/remote-iserv/remote-iserv.cabal -/utils/mkUserGuidePart/mkUserGuidePart.cabal -/utils/runghc/runghc.cabal -/utils/gen-dll/gen-dll.cabal -/utils/ghc-pkg/ghc-pkg.cabal utils/unlit/fs.* libraries/ghc-internal/include/fs.h libraries/ghc-internal/cbits/fs.c diff --git a/Build.hs b/Build.hs index 1162a885c536..5a0f42baa9aa 100755 --- a/Build.hs +++ b/Build.hs @@ -129,7 +129,7 @@ buildGhcStage2 = buildGhcStage False buildGhcStage :: Bool -> GhcBuildOptions -> Cabal -> Ghc -> FilePath -> IO () buildGhcStage booting opts cabal ghc0 dst = do let src = dst "src" - prepareGhcSources opts src + prepareGhcSources src msg " - Building GHC and utility programs..." @@ -354,8 +354,8 @@ buildGhcStage booting opts cabal ghc0 dst = do -- | Prepare GHC sources in the given directory -prepareGhcSources :: GhcBuildOptions -> FilePath -> IO () -prepareGhcSources opts dst = do +prepareGhcSources :: FilePath -> IO () +prepareGhcSources dst = do msg $ " - Preparing sources in " ++ dst ++ "..." createDirectoryIfMissing True dst createDirectoryIfMissing True (dst "libraries/ghc/MachRegs") @@ -382,46 +382,10 @@ prepareGhcSources opts dst = do cp "utils/fs/fs.*" (dst "libraries/rts/") cp "utils/fs/fs.*" (dst "utils/unlit/") - -- substitute variables in files - let subst fin fout rs = do - t <- Text.readFile fin - Text.writeFile fout (List.foldl' (\v (needle,rep) -> Text.replace needle rep v) t rs) - let subst_in f = subst (f <.> "in") f - let common_substs = - [ (,) "@ProjectVersion@" (gboVersion opts) - , (,) "@ProjectVersionMunged@" (gboVersionMunged opts) - , (,) "@ProjectVersionForLib@" (gboVersionForLib opts) - , (,) "@ProjectPatchLevel1@" (gboVersionPatchLevel1 opts) - , (,) "@ProjectPatchLevel2@" (gboVersionPatchLevel2 opts) - , (,) "@ProjectVersionInt@" (gboVersionInt opts) - ] - boot_th_substs = - [ (,) "@Suffix@" "" - , (,) "@SourceRoot@" "." - ] - - subst_in (dst "ghc-bin/ghc-bin.cabal") common_substs - subst_in (dst "libraries/ghc/ghc.cabal") common_substs - subst_in (dst "libraries/ghc-boot/ghc-boot.cabal") common_substs - subst_in (dst "libraries/ghc-boot-th/ghc-boot-th.cabal") (common_substs ++ boot_th_substs) - subst_in (dst "libraries/ghc-heap/ghc-heap.cabal") common_substs - subst_in (dst "libraries/template-haskell/template-haskell.cabal") common_substs - subst_in (dst "libraries/ghci/ghci.cabal") common_substs - - subst_in (dst "utils/ghc-pkg/ghc-pkg.cabal") common_substs - subst_in (dst "utils/iserv/iserv.cabal") common_substs - subst_in (dst "utils/runghc/runghc.cabal") common_substs - - subst_in (dst "libraries/ghc-internal/ghc-internal.cabal") common_substs - subst_in (dst "libraries/ghc-experimental/ghc-experimental.cabal") common_substs - subst_in (dst "libraries/base/base.cabal") common_substs - subst_in (dst "libraries/rts/include/ghcversion.h") common_substs - - buildBootLibraries :: Cabal -> Ghc -> GhcPkg -> DeriveConstants -> GenApply -> GenPrimop -> GhcBuildOptions -> FilePath -> IO () buildBootLibraries cabal ghc ghcpkg derive_constants genapply genprimop opts dst = do src <- makeAbsolute (dst "src") - prepareGhcSources opts src + prepareGhcSources src -- Build the RTS src_rts <- makeAbsolute (src "libraries/rts") diff --git a/compiler/ghc.cabal.in b/compiler/ghc.cabal similarity index 98% rename from compiler/ghc.cabal.in rename to compiler/ghc.cabal index b7b4c64d8d48..d87a114a7128 100644 --- a/compiler/ghc.cabal.in +++ b/compiler/ghc.cabal @@ -1,9 +1,7 @@ Cabal-Version: 2.2 --- WARNING: ghc.cabal is automatically generated from ghc.cabal.in by --- ./configure. Make sure you are editing ghc.cabal.in, not ghc.cabal. - Name: ghc -Version: @ProjectVersionMunged@ +-- ProjectVersionMunged +Version: 9.13 License: BSD-3-Clause License-File: LICENSE Author: The GHC Team @@ -132,16 +130,19 @@ Library semaphore-compat, stm, rts, - ghc-boot == @ProjectVersionMunged@, - ghc-heap == @ProjectVersionMunged@, - ghci == @ProjectVersionMunged@ + -- ProjectVersionMunged + ghc-boot == 9.13, + ghc-heap == 9.13, + ghci == 9.13 if flag(bootstrap) Build-Depends: - ghc-boot-th-next == @ProjectVersionMunged@ + -- ProjectVersionMunged + ghc-boot-th-next == 9.13 else Build-Depends: - ghc-boot-th == @ProjectVersionMunged@ + -- ProjectVersionMunged + ghc-boot-th == 9.13 if os(windows) Build-Depends: Win32 >= 2.3 && < 2.15 diff --git a/driver/ghci/ghci-wrapper.cabal.in b/driver/ghci/ghci-wrapper.cabal similarity index 68% rename from driver/ghci/ghci-wrapper.cabal.in rename to driver/ghci/ghci-wrapper.cabal index 2857e47a9da5..cd644175cb8e 100644 --- a/driver/ghci/ghci-wrapper.cabal.in +++ b/driver/ghci/ghci-wrapper.cabal @@ -1,20 +1,14 @@ --- WARNING: ghci-wrapper.cabal is automatically generated from ghci-wrapper.cabal.in by --- ./configure. Make sure you are editing ghci-wrapper.cabal.in, not ghci-wrapper.cabal. - +cabal-version: 3.0 Name: ghci-wrapper -Version: @ProjectVersion@ -Copyright: XXX -License: BSD3 --- XXX License-File: LICENSE -Author: XXX -Maintainer: XXX +-- ProjectVersion +Version: 9.13 +License: BSD-3-Clause Synopsis: A wrapper around GHCi allowing convenient execution of scripts Description: @ghci@ is a small wrapper program around GHC used on Windows to ensure that console setup is performed correctly. Category: Development build-type: Simple -cabal-version: >=1.10 Executable ghci Default-Language: Haskell2010 @@ -26,7 +20,10 @@ Executable ghci C-Sources: -- the following get copied from ../utils by hadrian getLocation.c isMinTTY.c cwrapper.c + -- We need to call the versioned ghc executable because the unversioned -- GHC executable is a wrapper that doesn't call FreeConsole and so -- breaks an interactive process like GHCi. See #21889, #14150 and #13411 - cc-options: -DEXE_PATH="ghc-@ProjectVersion@" + + -- ProjectVersion + cc-options: -DEXE_PATH="ghc-9.13" diff --git a/ghc/ghc-bin.cabal.in b/ghc/ghc-bin.cabal similarity index 85% rename from ghc/ghc-bin.cabal.in rename to ghc/ghc-bin.cabal index 5aafb0c35776..7ae83829a9a5 100644 --- a/ghc/ghc-bin.cabal.in +++ b/ghc/ghc-bin.cabal @@ -1,12 +1,7 @@ --- WARNING: ghc-bin.cabal is automatically generated from ghc-bin.cabal.in by --- ./configure. Make sure you are editing ghc-bin.cabal.in, not ghc-bin.cabal. - +Cabal-Version: 3.0 Name: ghc-bin -Version: @ProjectVersion@ -Copyright: XXX --- License: XXX --- License-File: XXX -Author: XXX +-- ProjectVersion +Version: 9.13 Maintainer: glasgow-haskell-users@haskell.org Homepage: http://www.haskell.org/ghc/ Synopsis: The Glorious Glasgow Haskell Compiler. @@ -15,7 +10,6 @@ Description: to the Glasgow Haskell Compiler. Category: Development Build-Type: Simple -Cabal-Version: >=1.10 Flag internal-interpreter Description: Build with internal interpreter support. @@ -39,8 +33,9 @@ Executable ghc filepath >= 1.5 && < 1.6, containers >= 0.5 && < 0.8, transformers >= 0.5 && < 0.7, - ghc-boot == @ProjectVersionMunged@, - ghc == @ProjectVersionMunged@ + -- ProjectVersionMunged + ghc-boot == 9.13, + ghc == 9.13, if os(windows) Build-Depends: Win32 >= 2.3 && < 2.15 @@ -58,7 +53,8 @@ Executable ghc Build-depends: deepseq >= 1.4 && < 1.6, ghc-prim >= 0.5.0 && < 0.14, - ghci == @ProjectVersionMunged@, + -- ProjectVersionMunged + ghci == 9.13, haskeline == 0.8.*, exceptions == 0.10.*, time >= 1.8 && < 1.15 diff --git a/libraries/base/base.cabal.in b/libraries/base/base.cabal similarity index 97% rename from libraries/base/base.cabal.in rename to libraries/base/base.cabal index 8ffd310d4518..9e4152e10375 100644 --- a/libraries/base/base.cabal.in +++ b/libraries/base/base.cabal @@ -1,8 +1,4 @@ cabal-version: 3.0 - --- WARNING: ghc-experimental.cabal is automatically generated from ghc-experimental.cabal.in --- Make sure you are editing ghc-experimental.cabal.in, not ghc-experimental.cabal - name: base version: 4.21.0.0 -- NOTE: Don't forget to update ./changelog.md @@ -30,7 +26,8 @@ Library default-language: Haskell2010 default-extensions: NoImplicitPrelude build-depends: - ghc-internal == @ProjectVersionForLib@.*, + -- ProjectVersionForLib + ghc-internal == 9.1300, ghc-prim, exposed-modules: diff --git a/libraries/ghc-boot-th/ghc-boot-th.cabal.in b/libraries/ghc-boot-th/ghc-boot-th.cabal similarity index 83% rename from libraries/ghc-boot-th/ghc-boot-th.cabal.in rename to libraries/ghc-boot-th/ghc-boot-th.cabal index 3c2cfca509d9..93544978d48e 100644 --- a/libraries/ghc-boot-th/ghc-boot-th.cabal.in +++ b/libraries/ghc-boot-th/ghc-boot-th.cabal @@ -1,10 +1,8 @@ --- WARNING: ghc-boot-th@Suffix@.cabal is automatically generated from --- ghc-boot-th@Suffix@.cabal.in by ../../configure. Make sure you are editing --- ghc-boot-th@Suffix@.cabal.in, not ghc-boot-th@Suffix@.cabal. - -name: ghc-boot-th@Suffix@ -version: @ProjectVersionMunged@ -license: BSD3 +cabal-version: 3.0 +name: ghc-boot-th +-- ProjectVersionMunged +version: 9.13 +license: BSD-3-Clause license-file: LICENSE category: GHC maintainer: ghc-devs@haskell.org @@ -17,7 +15,6 @@ description: This library contains various bits shared between the @ghc@ and This package exists to ensure that @template-haskell@ has a minimal set of transitive dependencies, since it is intended to be depended upon by user code. -cabal-version: >=1.10 build-type: Simple extra-source-files: changelog.md @@ -56,7 +53,7 @@ Library cpp-options: -DBOOTSTRAP_TH build-depends: ghc-prim - hs-source-dirs: @SourceRoot@ ../ghc-internal/src + hs-source-dirs: . ../ghc-internal/src exposed-modules: GHC.Internal.TH.Lib GHC.Internal.TH.Syntax @@ -65,7 +62,7 @@ Library GHC.Internal.LanguageExtensions GHC.Internal.Lexeme else - hs-source-dirs: @SourceRoot@ + hs-source-dirs: . build-depends: ghc-internal reexported-modules: diff --git a/libraries/ghc-boot/ghc-boot.cabal.in b/libraries/ghc-boot/ghc-boot.cabal similarity index 90% rename from libraries/ghc-boot/ghc-boot.cabal.in rename to libraries/ghc-boot/ghc-boot.cabal index 992c7834739e..8ca9dbad8afb 100644 --- a/libraries/ghc-boot/ghc-boot.cabal.in +++ b/libraries/ghc-boot/ghc-boot.cabal @@ -1,11 +1,7 @@ cabal-version: 3.0 - --- WARNING: ghc-boot.cabal is automatically generated from ghc-boot.cabal.in by --- ../../configure. Make sure you are editing ghc-boot.cabal.in, not --- ghc-boot.cabal. - name: ghc-boot -version: @ProjectVersionMunged@ +-- ProjectVersionMunged +version: 9.13 license: BSD-3-Clause license-file: LICENSE category: GHC @@ -94,10 +90,12 @@ Library if flag(bootstrap) build-depends: - ghc-boot-th-next == @ProjectVersionMunged@ + -- ProjectVersionMunged + ghc-boot-th-next == 9.13 else build-depends: - ghc-boot-th == @ProjectVersionMunged@ + -- ProjectVersionMunged + ghc-boot-th == 9.13 if !os(windows) build-depends: diff --git a/libraries/ghc-experimental/ghc-experimental.cabal.in b/libraries/ghc-experimental/ghc-experimental.cabal similarity index 73% rename from libraries/ghc-experimental/ghc-experimental.cabal.in rename to libraries/ghc-experimental/ghc-experimental.cabal index 07a0052a50b5..ffc55fe4de31 100644 --- a/libraries/ghc-experimental/ghc-experimental.cabal.in +++ b/libraries/ghc-experimental/ghc-experimental.cabal @@ -1,12 +1,7 @@ cabal-version: 3.0 - --- WARNING: ghc-experimental.cabal is automatically generated from ghc-experimental.cabal.in --- Make sure you are editing ghc-experimental.cabal.in, not ghc-experimental.cabal - name: ghc-experimental --- The project is ghc's version plus ghc-experimental's version suffix. --- For example, for ghc=9.10.1, ghc-experimental's version will be 9.1001.0. -version: @ProjectVersionForLib@.0 +-- ProjectVersionForLib +version: 9.1300.0 synopsis: Experimental features of GHC's standard library description: This package is where experimental GHC standard library interfaces start @@ -42,6 +37,7 @@ library exposed-modules: GHC.Wasm.Prim other-extensions: build-depends: base >=4.20 && < 4.22, - ghc-internal == @ProjectVersionForLib@.* + -- ProjectVersionForLib + ghc-internal == 9.1300.*, hs-source-dirs: src default-language: Haskell2010 diff --git a/libraries/ghc-heap/ghc-heap.cabal.in b/libraries/ghc-heap/ghc-heap.cabal similarity index 93% rename from libraries/ghc-heap/ghc-heap.cabal.in rename to libraries/ghc-heap/ghc-heap.cabal index d3430642e474..e1bb956a747c 100644 --- a/libraries/ghc-heap/ghc-heap.cabal.in +++ b/libraries/ghc-heap/ghc-heap.cabal @@ -1,6 +1,7 @@ cabal-version: 3.0 name: ghc-heap -version: @ProjectVersionMunged@ +-- ProjectVersionMunged +version: 9.13 license: BSD-3-Clause license-file: LICENSE maintainer: libraries@haskell.org @@ -28,7 +29,8 @@ library , containers >= 0.6.2.1 && < 0.8 if impl(ghc >= 9.9) - build-depends: ghc-internal >= 9.900 && < @ProjectVersionForLib@.99999 + -- ProjectVersionForLib + build-depends: ghc-internal >= 9.900 && < 9.1300.99999 ghc-options: -Wall if !os(ghcjs) diff --git a/libraries/ghc-internal/ghc-internal.cabal.in b/libraries/ghc-internal/ghc-internal.cabal similarity index 97% rename from libraries/ghc-internal/ghc-internal.cabal.in rename to libraries/ghc-internal/ghc-internal.cabal index a35b5707853e..ecc42e816866 100644 --- a/libraries/ghc-internal/ghc-internal.cabal.in +++ b/libraries/ghc-internal/ghc-internal.cabal @@ -1,10 +1,7 @@ cabal-version: 3.0 --- WARNING: ghc-internal.cabal is automatically generated from ghc-internal.cabal.in by --- the top-level ./configure script. Make sure you are editing ghc-internal.cabal.in, not ghc-internal.cabal. name: ghc-internal --- The project is ghc's version plus ghc-internal's version suffix. --- For example, for ghc=9.10.1, ghc-internal's version will be 9.1001.0. -version: @ProjectVersionForLib@.0 +-- ProjectVersionForLib +version: 9.1300 license: BSD-3-Clause license-file: LICENSE maintainer: The GHC Developers diff --git a/libraries/ghci/ghci.cabal.in b/libraries/ghci/ghci.cabal similarity index 85% rename from libraries/ghci/ghci.cabal.in rename to libraries/ghci/ghci.cabal index 726b6d682672..5fb32220304f 100644 --- a/libraries/ghci/ghci.cabal.in +++ b/libraries/ghci/ghci.cabal @@ -1,9 +1,7 @@ --- WARNING: ghci.cabal is automatically generated from ghci.cabal.in by --- ../../configure. Make sure you are editing ghci.cabal.in, not ghci.cabal. - +cabal-version: 3.0 name: ghci -version: @ProjectVersionMunged@ -license: BSD3 +version: 9.13 +license: BSD-3-Clause license-file: LICENSE category: GHC maintainer: ghc-devs@haskell.org @@ -13,7 +11,6 @@ description: This library offers interfaces which mediate interactions between the @ghci@ interactive shell and @iserv@, GHC's out-of-process interpreter backend. -cabal-version: >=1.10 build-type: Simple extra-source-files: changelog.md @@ -96,19 +93,23 @@ library containers >= 0.5 && < 0.8, deepseq >= 1.4 && < 1.6, filepath >= 1.4 && < 1.6, - ghc-boot == @ProjectVersionMunged@, - ghc-heap == @ProjectVersionMunged@, + -- ProjectVersionMunged + ghc-boot == 9.13, + ghc-heap == 9.13, transformers >= 0.5 && < 0.7 if flag(bootstrap) build-depends: - ghc-boot-th-next == @ProjectVersionMunged@ + -- ProjectVersionMunged + ghc-boot-th-next == 9.13 else build-depends: - ghc-boot-th == @ProjectVersionMunged@ + -- ProjectVersionMunged + ghc-boot-th == 9.13 if !os(windows) Build-Depends: unix >= 2.7 && < 2.9 if arch(wasm32) - build-depends: ghc-experimental == @ProjectVersionForLib@.0 + -- ProjectVersionForLib + build-depends: ghc-experimental == 9.1300.0 diff --git a/libraries/template-haskell/template-haskell.cabal.in b/libraries/template-haskell/template-haskell.cabal similarity index 84% rename from libraries/template-haskell/template-haskell.cabal.in rename to libraries/template-haskell/template-haskell.cabal index f2269b3173b6..adfb0f953919 100644 --- a/libraries/template-haskell/template-haskell.cabal.in +++ b/libraries/template-haskell/template-haskell.cabal @@ -1,18 +1,14 @@ --- WARNING: template-haskell.cabal is automatically generated from template-haskell.cabal.in by --- ../../configure. Make sure you are editing template-haskell.cabal.in, not --- template-haskell.cabal. - +cabal-Version: 3.0 name: template-haskell version: 2.23.0.0 -- NOTE: Don't forget to update ./changelog.md -license: BSD3 +license: BSD-3-Clause license-file: LICENSE category: Template Haskell maintainer: libraries@haskell.org bug-reports: https://gitlab.haskell.org/ghc/ghc/issues/new synopsis: Support library for Template Haskell build-type: Simple -Cabal-Version: >= 1.10 description: This package provides modules containing facilities for manipulating Haskell source code using Template Haskell. @@ -53,7 +49,8 @@ Library build-depends: base >= 4.11 && < 4.22, - ghc-boot-th == @ProjectVersionMunged@ + -- ProjectVersionMunged + ghc-boot-th == 9.13 other-modules: System.FilePath diff --git a/utils/ghc-pkg/ghc-pkg.cabal.in b/utils/ghc-pkg/ghc-pkg.cabal similarity index 86% rename from utils/ghc-pkg/ghc-pkg.cabal.in rename to utils/ghc-pkg/ghc-pkg.cabal index b40a6efe0422..d42676ff8599 100644 --- a/utils/ghc-pkg/ghc-pkg.cabal.in +++ b/utils/ghc-pkg/ghc-pkg.cabal @@ -1,10 +1,8 @@ +cabal-version: 3.0 Name: ghc-pkg --- XXX Version number -Version: @ProjectVersion@ -Copyright: XXX -License: BSD3 --- XXX License-File: LICENSE -Author: XXX +-- ProjectVersion +Version: 9.13 +License: BSD-3-Clause Maintainer: cvs-fptools@haskell.org Synopsis: A utility for querying and managing the GHC package database. Description: @@ -13,7 +11,6 @@ Description: usage information. Category: Development build-type: Simple -cabal-version: >=1.10 Executable ghc-pkg Default-Language: GHC2021 diff --git a/utils/iserv/iserv.cabal.in b/utils/iserv/iserv.cabal similarity index 77% rename from utils/iserv/iserv.cabal.in rename to utils/iserv/iserv.cabal index 0f5d77456ae0..69f645d87356 100644 --- a/utils/iserv/iserv.cabal.in +++ b/utils/iserv/iserv.cabal @@ -1,12 +1,8 @@ --- WARNING: iserv.cabal is automatically generated from iserv.cabal.in by --- ../../configure. Make sure you are editing iserv.cabal.in, not --- iserv.cabal. - +cabal-version: 3.0 Name: iserv -Version: @ProjectVersion@ -Copyright: XXX -License: BSD3 --- XXX License-File: LICENSE +-- ProjectVersion +Version: 9.13 +License: BSD-3-Clause Author: XXX Maintainer: XXX Synopsis: iserv allows GHC to delegate Template Haskell computations @@ -21,7 +17,6 @@ Description: Category: Development build-type: Simple -cabal-version: >=1.10 Executable iserv Default-Language: Haskell2010 @@ -36,7 +31,8 @@ Executable iserv bytestring >= 0.10 && < 0.13, containers >= 0.5 && < 0.8, deepseq >= 1.4 && < 1.6, - ghci == @ProjectVersionMunged@ + -- ProjectVersionMunged + ghci == 9.13 if os(windows) Cpp-Options: -DWINDOWS diff --git a/utils/remote-iserv/remote-iserv.cabal.in b/utils/remote-iserv/remote-iserv.cabal similarity index 64% rename from utils/remote-iserv/remote-iserv.cabal.in rename to utils/remote-iserv/remote-iserv.cabal index 24c5c99c748d..fa2eb4f78b10 100644 --- a/utils/remote-iserv/remote-iserv.cabal.in +++ b/utils/remote-iserv/remote-iserv.cabal @@ -1,12 +1,8 @@ --- WARNING: iserv-proxy.cabal is automatically generated from remote-iserv.cabal.in by --- ../../configure. Make sure you are editing remote-iserv.cabal.in, not --- remote-iserv.cabal. - +cabal-version: 3.0 Name: remote-iserv -Version: @ProjectVersion@ -Copyright: XXX -License: BSD3 --- XXX License-File: LICENSE +-- ProjectVersion +Version: 9.13 +License: BSD-3-Clause Author: Moritz Angermann Maintainer: Moritz Angermann Synopsis: iserv allows GHC to delegate Template Haskell computations @@ -17,11 +13,11 @@ Description: then connect. Category: Development build-type: Simple -cabal-version: >=1.10 Executable remote-iserv Default-Language: Haskell2010 Main-Is: Cli.hs Hs-Source-Dirs: src Build-Depends: base >= 4 && < 5, - ghci == @ProjectVersionMunged@ + -- ProjectVersionMunged + ghci == 9.13 diff --git a/utils/runghc/runghc.cabal.in b/utils/runghc/runghc.cabal similarity index 84% rename from utils/runghc/runghc.cabal.in rename to utils/runghc/runghc.cabal index cf0d085a3453..bdf6ec2df781 100644 --- a/utils/runghc/runghc.cabal.in +++ b/utils/runghc/runghc.cabal @@ -1,10 +1,8 @@ +cabal-version: 3.0 Name: runghc -Version: @ProjectVersion@ -Copyright: XXX -License: BSD3 --- XXX License-File: LICENSE -Author: XXX -Maintainer: XXX +-- ProjectVersion +Version: 9.13 +License: BSD-3-Clause Synopsis: A wrapper around GHC allowing convenient execution of scripts Description: @runghc@ is a small wrapper program around GHC which allows the compiler @@ -21,7 +19,6 @@ Description: @ Category: Development build-type: Simple -cabal-version: >=1.10 Executable runghc Default-Language: Haskell2010 From ce12e2dee86e865d1483aae855dd81634613beed Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Mon, 24 Feb 2025 12:32:26 +0800 Subject: [PATCH 15/84] FIXME ci: add cabal-install workflow --- .github/workflows/ci-cabal-install.yml | 102 +++++++++++++++++++++++++ cabal.project.stage1 | 53 +++++++++++++ 2 files changed, 155 insertions(+) create mode 100644 .github/workflows/ci-cabal-install.yml create mode 100644 cabal.project.stage1 diff --git a/.github/workflows/ci-cabal-install.yml b/.github/workflows/ci-cabal-install.yml new file mode 100644 index 000000000000..5f3e762cc087 --- /dev/null +++ b/.github/workflows/ci-cabal-install.yml @@ -0,0 +1,102 @@ +name: CI + +# Trigger the workflow on push or pull request, but only for the master branch +on: + pull_request: + types: + - opened + - synchronize + push: + branches: [master] + +jobs: + cabal: + name: ${{ matrix.os }} / ghc ${{ matrix.ghc }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + ghc: ['9.8.4'] # bootstrapping compiler + + steps: + - uses: actions/checkout@v4 + with: + submodules: "recursive" + + - uses: haskell/ghcup-setup@v1 + + - id: ghcup + run: | + ghcup config set cache true + echo "basedir=$(ghcup whereis basedir)" >> $GITHUB_OUTPUT + + - id: ghcup-cache + name: Cache GHCup basedir + uses: actions/cache@v4 + with: + key: ghcup-basedir-${{ github.run_id }} + restore-keys: ghcup-basedir- + path: ${{ steps.ghcup.outputs.basedir }} + + - run: | + ghcup install ghc --set ${{ matrix.ghc }} + ghcup install cabal --set + + - id: cabal-paths + run: | + cabal user-config init + echo "store=$(cabal path --store-dir)" >> $GITHUB_OUTPUT + echo "remote-repo-cache=$(cabal path --remote-repo-cache)" >> $GITHUB_OUTPUT + + - name: Restore Hackage index + uses: actions/cache/restore@v4 + with: + key: hackage-${{ github.run_id }} + restore-keys: hackage- + path: ${{ steps.cabal-paths.outputs.remote-repo-cache }} + + - run: cabal update + + - name: Restore build artifacts + uses: actions/cache/restore@v4 + with: + key: ${{ matrix.os }}-${{ matrix.ghc }}-${{ github.run_id }} + restore-keys: ${{ matrix.os }}-${{ matrix.ghc }}- + path: | + ${{ steps.cabal-paths.outputs.store }} + libraries/Cabal/dist-newstyle + _build + + - name: Build stage1 + run: make stage1 + + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: stage1 + path: _stage1 + + - name: Save GHCup cache + uses: actions/cache/save@v4 + if: always() + with: + key: ghcup-${{ github.run_id }} + path: ${{ steps.ghcup.outputs.cachedir }} + + - name: Save Hackage index + uses: actions/cache/save@v4 + if: always() + with: + key: hackage-${{ github.run_id }} + path: ${{ steps.cabal-paths.outputs.remote-repo-cache }} + + - name: Save build artifacts + if: always() + uses: actions/cache/save@v4 + with: + key: ${{ matrix.os }}-${{ matrix.ghc }}-${{ github.run_id }} + path: | + ${{ steps.cabal-paths.outputs.store }} + libraries/Cabal/dist-newstyle + _build diff --git a/cabal.project.stage1 b/cabal.project.stage1 new file mode 100644 index 000000000000..9c248a1ceeda --- /dev/null +++ b/cabal.project.stage1 @@ -0,0 +1,53 @@ +-- aka cabal.project-ghc +-- NOTE: this should be in sync with stage1_project in Build.hs until we merge them +-- (except some packages paths) + +packages: + ./compiler + ./ghc + ./libraries/directory + ./libraries/file-io + ./libraries/filepath + ./libraries/ghc-platform + ./libraries/ghc-boot + ./libraries/ghc-boot-th + ./libraries/ghc-heap + ./libraries/ghci + ./libraries/os-string + ./libraries/process + ./libraries/semaphore-compat + ./libraries/time + ./libraries/unix + ./libraries/Win32 + ./utils/ghc-pkg + ./utils/hsc2hs + ./utils/unlit + ./utils/genprimopcode + ./utils/genapply + ./utils/deriveConstants + ./utils/ghc-toolchain + ./utils/ghc-toolchain/exe + +benchmark: False +tests: False +allow-boot-library-installs: True + +package * + library-vanilla: True + shared: False + executable-profiling: False + executable-dynamic: False + executable-static: True + +package ghc-boot-th + flags: +bootstrap + +package hsc2hs + flags: +in-ghc-tree + +-- allow template-haskell with newer ghc-boot-th +allow-newer: ghc-boot-th + +constraints: +-- FIXME: template-haskell 2.23 is too recent when booting with 9.8.4 + template-haskell <= 2.22 From a9ae5ac690530c5fa422a78040495570ae15dadd Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Wed, 26 Feb 2025 13:00:14 +0800 Subject: [PATCH 16/84] refactor(rts-headers): Move shared headers to new package --- Build.hs | 10 ++--- cabal.project.stage1 | 1 + compiler/CodeGen.Platform.h | 2 +- compiler/GHC/ByteCode/Asm.hs | 2 +- compiler/GHC/Runtime/Heap/Layout.hs | 4 +- compiler/GHC/StgToCmm/Layout.hs | 2 +- compiler/GHC/StgToCmm/TagCheck.hs | 2 +- compiler/ghc.cabal | 21 +--------- {rts => rts-headers}/include/rts/Bytecodes.h | 0 .../include/rts/storage/ClosureTypes.h | 0 .../include/rts/storage/FunTypes.h | 0 {rts => rts-headers}/include/stg/MachRegs.h | 0 .../include/stg/MachRegs/arm32.h | 0 .../include/stg/MachRegs/arm64.h | 0 .../include/stg/MachRegs/loongarch64.h | 0 .../include/stg/MachRegs/ppc.h | 0 .../include/stg/MachRegs/riscv64.h | 0 .../include/stg/MachRegs/s390x.h | 0 .../include/stg/MachRegs/wasm32.h | 0 .../include/stg/MachRegs/x86.h | 0 rts-headers/rts-headers.cabal | 31 +++++++++++++++ rts/include/stg/MachRegsForHost.h | 2 +- rts/rts.cabal | 38 ++----------------- 23 files changed, 47 insertions(+), 68 deletions(-) rename {rts => rts-headers}/include/rts/Bytecodes.h (100%) rename {rts => rts-headers}/include/rts/storage/ClosureTypes.h (100%) rename {rts => rts-headers}/include/rts/storage/FunTypes.h (100%) rename {rts => rts-headers}/include/stg/MachRegs.h (100%) rename {rts => rts-headers}/include/stg/MachRegs/arm32.h (100%) rename {rts => rts-headers}/include/stg/MachRegs/arm64.h (100%) rename {rts => rts-headers}/include/stg/MachRegs/loongarch64.h (100%) rename {rts => rts-headers}/include/stg/MachRegs/ppc.h (100%) rename {rts => rts-headers}/include/stg/MachRegs/riscv64.h (100%) rename {rts => rts-headers}/include/stg/MachRegs/s390x.h (100%) rename {rts => rts-headers}/include/stg/MachRegs/wasm32.h (100%) rename {rts => rts-headers}/include/stg/MachRegs/x86.h (100%) create mode 100644 rts-headers/rts-headers.cabal diff --git a/Build.hs b/Build.hs index 5a0f42baa9aa..799131a53cc0 100755 --- a/Build.hs +++ b/Build.hs @@ -173,6 +173,7 @@ buildGhcStage booting opts cabal ghc0 dst = do , " " ++ src "libraries/ghci" , " " ++ src "libraries/os-string/" , " " ++ src "libraries/process/" + , " " ++ src "libraries/rts-headers/" , " " ++ src "libraries/semaphore-compat" , " " ++ src "libraries/time" , " " ++ src "libraries/unix/" @@ -363,19 +364,13 @@ prepareGhcSources dst = do cp "./libraries" dst cp "./compiler/*" (dst "libraries/ghc/") cp "./rts" (dst "libraries/") + cp "./rts-headers" (dst "libraries/") cp "./ghc" (dst "ghc-bin") cp "./utils" dst cp "./config.sub" (dst "libraries/rts/") cp "./config.guess" (dst "libraries/rts/") - -- These needs to shared - cp "rts/include/rts/Bytecodes.h" (dst "libraries/ghc/") - cp "rts/include/rts/storage/ClosureTypes.h" (dst "libraries/ghc/") - cp "rts/include/rts/storage/FunTypes.h" (dst "libraries/ghc/") - cp "rts/include/stg/MachRegs.h" (dst "libraries/ghc/") - cp "rts/include/stg/MachRegs/*.h" (dst "libraries/ghc/MachRegs/") - -- shared among ghc-internal rts and unlit cp "utils/fs/fs.h" (dst "libraries/ghc-internal/include") cp "utils/fs/fs.c" (dst "libraries/ghc-internal/cbits") @@ -448,6 +443,7 @@ buildBootLibraries cabal ghc ghcpkg derive_constants genapply genprimop opts dst , "" , "packages:" , " " ++ src "libraries/rts" + , " " ++ src "libraries/rts-headers" , "" , "benchmarks: False" , "tests: False" diff --git a/cabal.project.stage1 b/cabal.project.stage1 index 9c248a1ceeda..12b83e003a29 100644 --- a/cabal.project.stage1 +++ b/cabal.project.stage1 @@ -5,6 +5,7 @@ packages: ./compiler ./ghc + ./rts-headers ./libraries/directory ./libraries/file-io ./libraries/filepath diff --git a/compiler/CodeGen.Platform.h b/compiler/CodeGen.Platform.h index 78a712072d5e..417347c06ad2 100644 --- a/compiler/CodeGen.Platform.h +++ b/compiler/CodeGen.Platform.h @@ -7,7 +7,7 @@ import GHC.Utils.Panic.Plain #endif import GHC.Platform.Reg -#include "MachRegs.h" +#include "stg/MachRegs.h" #if defined(MACHREGS_i386) || defined(MACHREGS_x86_64) diff --git a/compiler/GHC/ByteCode/Asm.hs b/compiler/GHC/ByteCode/Asm.hs index 237919058f79..36f20125f59a 100644 --- a/compiler/GHC/ByteCode/Asm.hs +++ b/compiler/GHC/ByteCode/Asm.hs @@ -365,7 +365,7 @@ inspectAsm platform long_jumps initial_offset count (IOp _) = if largeOps then largeArg16s platform else 1 -- Bring in all the bci_ bytecode constants. -#include "Bytecodes.h" +#include "rts/Bytecodes.h" largeArgInstr :: Word16 -> Word16 largeArgInstr bci = bci_FLAG_LARGE_ARGS .|. bci diff --git a/compiler/GHC/Runtime/Heap/Layout.hs b/compiler/GHC/Runtime/Heap/Layout.hs index 73e2ff9e410a..e0956185a59a 100644 --- a/compiler/GHC/Runtime/Heap/Layout.hs +++ b/compiler/GHC/Runtime/Heap/Layout.hs @@ -438,8 +438,8 @@ cardTableSizeW platform elems = ----------------------------------------------------------------------------- -- deriving the RTS closure type from an SMRep -#include "ClosureTypes.h" -#include "FunTypes.h" +#include "rts/storage/ClosureTypes.h" +#include "rts/storage/FunTypes.h" -- Defines CONSTR, CONSTR_1_0 etc -- | Derives the RTS closure type from an 'SMRep' diff --git a/compiler/GHC/StgToCmm/Layout.hs b/compiler/GHC/StgToCmm/Layout.hs index f5e8fdd63b09..fa7270f8f388 100644 --- a/compiler/GHC/StgToCmm/Layout.hs +++ b/compiler/GHC/StgToCmm/Layout.hs @@ -547,7 +547,7 @@ mkVirtConstrSizes profile field_reps ------------------------------------------------------------------------- -- bring in ARG_P, ARG_N, etc. -#include "FunTypes.h" +#include "rts/storage/FunTypes.h" mkArgDescr :: Platform -> [Id] -> ArgDescr mkArgDescr platform args diff --git a/compiler/GHC/StgToCmm/TagCheck.hs b/compiler/GHC/StgToCmm/TagCheck.hs index c2476b84905e..c4299b30e550 100644 --- a/compiler/GHC/StgToCmm/TagCheck.hs +++ b/compiler/GHC/StgToCmm/TagCheck.hs @@ -12,7 +12,7 @@ module GHC.StgToCmm.TagCheck ( emitTagAssertion, emitArgTagCheck, checkArg, whenCheckTags, checkArgStatic, checkFunctionArgTags,checkConArgsStatic,checkConArgsDyn) where -#include "ClosureTypes.h" +#include "rts/storage/ClosureTypes.h" import GHC.Prelude diff --git a/compiler/ghc.cabal b/compiler/ghc.cabal index d87a114a7128..3b27f68d187c 100644 --- a/compiler/ghc.cabal +++ b/compiler/ghc.cabal @@ -30,22 +30,6 @@ extra-source-files: GHC/Builtin/primops.txt.pp Unique.h CodeGen.Platform.h - -- Shared with rts via hard-link at configure time. This is safer - -- for Windows, where symlinks don't work out of the box, so we - -- can't just commit some in git. - Bytecodes.h - ClosureTypes.h - FunTypes.h - MachRegs.h - MachRegs/arm32.h - MachRegs/arm64.h - MachRegs/loongarch64.h - MachRegs/ppc.h - MachRegs/riscv64.h - MachRegs/s390x.h - MachRegs/wasm32.h - MachRegs/x86.h - custom-setup setup-depends: base >= 3 && < 5, Cabal >= 1.6 && <3.16, directory, process, filepath, containers @@ -93,12 +77,10 @@ Flag bootstrap Library Default-Language: GHC2021 Exposed: False + Includes: Unique.h -- CodeGen.Platform.h -- invalid as C, skip -- shared with rts via symlink - Bytecodes.h - ClosureTypes.h - FunTypes.h if flag(build-tool-depends) build-tool-depends: alex:alex >= 3.2.6, happy:happy >= 1.20.0, genprimopcode:genprimopcode, deriveConstants:deriveConstants @@ -130,6 +112,7 @@ Library semaphore-compat, stm, rts, + rts-headers, -- ProjectVersionMunged ghc-boot == 9.13, ghc-heap == 9.13, diff --git a/rts/include/rts/Bytecodes.h b/rts-headers/include/rts/Bytecodes.h similarity index 100% rename from rts/include/rts/Bytecodes.h rename to rts-headers/include/rts/Bytecodes.h diff --git a/rts/include/rts/storage/ClosureTypes.h b/rts-headers/include/rts/storage/ClosureTypes.h similarity index 100% rename from rts/include/rts/storage/ClosureTypes.h rename to rts-headers/include/rts/storage/ClosureTypes.h diff --git a/rts/include/rts/storage/FunTypes.h b/rts-headers/include/rts/storage/FunTypes.h similarity index 100% rename from rts/include/rts/storage/FunTypes.h rename to rts-headers/include/rts/storage/FunTypes.h diff --git a/rts/include/stg/MachRegs.h b/rts-headers/include/stg/MachRegs.h similarity index 100% rename from rts/include/stg/MachRegs.h rename to rts-headers/include/stg/MachRegs.h diff --git a/rts/include/stg/MachRegs/arm32.h b/rts-headers/include/stg/MachRegs/arm32.h similarity index 100% rename from rts/include/stg/MachRegs/arm32.h rename to rts-headers/include/stg/MachRegs/arm32.h diff --git a/rts/include/stg/MachRegs/arm64.h b/rts-headers/include/stg/MachRegs/arm64.h similarity index 100% rename from rts/include/stg/MachRegs/arm64.h rename to rts-headers/include/stg/MachRegs/arm64.h diff --git a/rts/include/stg/MachRegs/loongarch64.h b/rts-headers/include/stg/MachRegs/loongarch64.h similarity index 100% rename from rts/include/stg/MachRegs/loongarch64.h rename to rts-headers/include/stg/MachRegs/loongarch64.h diff --git a/rts/include/stg/MachRegs/ppc.h b/rts-headers/include/stg/MachRegs/ppc.h similarity index 100% rename from rts/include/stg/MachRegs/ppc.h rename to rts-headers/include/stg/MachRegs/ppc.h diff --git a/rts/include/stg/MachRegs/riscv64.h b/rts-headers/include/stg/MachRegs/riscv64.h similarity index 100% rename from rts/include/stg/MachRegs/riscv64.h rename to rts-headers/include/stg/MachRegs/riscv64.h diff --git a/rts/include/stg/MachRegs/s390x.h b/rts-headers/include/stg/MachRegs/s390x.h similarity index 100% rename from rts/include/stg/MachRegs/s390x.h rename to rts-headers/include/stg/MachRegs/s390x.h diff --git a/rts/include/stg/MachRegs/wasm32.h b/rts-headers/include/stg/MachRegs/wasm32.h similarity index 100% rename from rts/include/stg/MachRegs/wasm32.h rename to rts-headers/include/stg/MachRegs/wasm32.h diff --git a/rts/include/stg/MachRegs/x86.h b/rts-headers/include/stg/MachRegs/x86.h similarity index 100% rename from rts/include/stg/MachRegs/x86.h rename to rts-headers/include/stg/MachRegs/x86.h diff --git a/rts-headers/rts-headers.cabal b/rts-headers/rts-headers.cabal new file mode 100644 index 000000000000..6d1b89a7ca33 --- /dev/null +++ b/rts-headers/rts-headers.cabal @@ -0,0 +1,31 @@ +cabal-version: 3.4 +name: rts-headers +version: 1.0.3 +synopsis: The GHC runtime system +description: + The GHC runtime system. + + Code produced by GHC links this library to provide missing functionality + that cannot be written in Haskell itself. +license: BSD-3-Clause +maintainer: glasgow-haskell-users@haskell.org +build-type: Simple + + +library + include-dirs: + include + + install-includes: + rts/Bytecodes.h + rts/storage/ClosureTypes.h + rts/storage/FunTypes.h + stg/MachRegs.h + stg/MachRegs/arm32.h + stg/MachRegs/arm64.h + stg/MachRegs/loongarch64.h + stg/MachRegs/ppc.h + stg/MachRegs/riscv64.h + stg/MachRegs/s390x.h + stg/MachRegs/wasm32.h + stg/MachRegs/x86.h diff --git a/rts/include/stg/MachRegsForHost.h b/rts/include/stg/MachRegsForHost.h index 7c045c0214bf..cd28215ea0f1 100644 --- a/rts/include/stg/MachRegsForHost.h +++ b/rts/include/stg/MachRegsForHost.h @@ -84,4 +84,4 @@ #endif -#include "MachRegs.h" +#include "stg/MachRegs.h" diff --git a/rts/rts.cabal b/rts/rts.cabal index c97136cc1f59..b616a2624a93 100644 --- a/rts/rts.cabal +++ b/rts/rts.cabal @@ -68,7 +68,6 @@ extra-source-files: include/rts/Adjustor.h include/RtsAPI.h include/rts/BlockSignals.h - include/rts/Bytecodes.h include/rts/Config.h include/rts/Constants.h include/rts/EventLogFormat.h @@ -105,9 +104,6 @@ extra-source-files: include/rts/StaticPtrTable.h include/rts/storage/Block.h include/rts/storage/ClosureMacros.h - include/rts/storage/Closures.h - include/rts/storage/ClosureTypes.h - include/rts/storage/FunTypes.h include/rts/storage/GC.h include/rts/storage/HeapAlloc.h include/rts/storage/Heap.h @@ -124,16 +120,7 @@ extra-source-files: include/rts/Utils.h include/stg/DLL.h include/Stg.h - include/stg/MachRegs/arm32.h - include/stg/MachRegs/arm64.h include/stg/MachRegsForHost.h - include/stg/MachRegs.h - include/stg/MachRegs/loongarch64.h - include/stg/MachRegs/ppc.h - include/stg/MachRegs/riscv64.h - include/stg/MachRegs/s390x.h - include/stg/MachRegs/wasm32.h - include/stg/MachRegs/x86.h include/stg/MiscClosures.h include/stg/Prim.h include/stg/Regs.h @@ -386,15 +373,6 @@ library install-includes: HsFFI.h MachDeps.h Rts.h RtsAPI.h Stg.h ghcautoconf.h ghcconfig.h ghcplatform.h ghcversion.h DerivedConstants.h - stg/MachRegs.h - stg/MachRegs/arm32.h - stg/MachRegs/arm64.h - stg/MachRegs/loongarch64.h - stg/MachRegs/ppc.h - stg/MachRegs/riscv64.h - stg/MachRegs/s390x.h - stg/MachRegs/wasm32.h - stg/MachRegs/x86.h stg/MachRegsForHost.h stg/Types.h @@ -508,7 +486,6 @@ library rts/Adjustor.h rts/ExecPage.h rts/BlockSignals.h - rts/Bytecodes.h rts/Config.h rts/Constants.h rts/EventLogFormat.h @@ -550,9 +527,7 @@ library rts/prof/LDV.h rts/storage/Block.h rts/storage/ClosureMacros.h - rts/storage/ClosureTypes.h rts/storage/Closures.h - rts/storage/FunTypes.h rts/storage/Heap.h rts/storage/HeapAlloc.h rts/storage/GC.h @@ -560,16 +535,6 @@ library rts/storage/MBlock.h rts/storage/TSO.h stg/DLL.h - stg/MachRegs.h - stg/MachRegs/arm32.h - stg/MachRegs/arm64.h - stg/MachRegs/loongarch64.h - stg/MachRegs/ppc.h - stg/MachRegs/riscv64.h - stg/MachRegs/s390x.h - stg/MachRegs/wasm32.h - stg/MachRegs/x86.h - stg/MachRegsForHost.h stg/MiscClosures.h stg/Prim.h stg/Regs.h @@ -810,6 +775,9 @@ library -- We don't want to compile posix/ticker/*.c, these will be #included -- from Ticker.c + build-depends: + rts-headers + -- Note [Undefined symbols in the RTS] -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- The RTS is built with a number of `-u` flags. This is to handle cyclic From 5c75136190104c789818e0bf960e0726285ec002 Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Thu, 27 Feb 2025 09:51:18 +0800 Subject: [PATCH 17/84] refactor(rts-fs): turn utils/fs into a cabal package --- Build.hs | 9 +++------ cabal.project.stage1 | 1 + compiler/ghc.cabal | 2 -- libraries/ghc-internal/ghc-internal.cabal | 5 ++--- {utils/fs => rts-fs}/README | 2 -- {utils/fs => rts-fs}/fs.c | 0 {utils/fs => rts-fs}/fs.h | 0 rts-fs/rts-fs.cabal | 15 +++++++++++++++ rts/.gitignore | 1 - rts/rts.cabal | 5 ++--- utils/unlit/unlit.cabal | 11 +++-------- 11 files changed, 26 insertions(+), 25 deletions(-) rename {utils/fs => rts-fs}/README (68%) rename {utils/fs => rts-fs}/fs.c (100%) rename {utils/fs => rts-fs}/fs.h (100%) create mode 100644 rts-fs/rts-fs.cabal diff --git a/Build.hs b/Build.hs index 799131a53cc0..864b5bfa6cf5 100755 --- a/Build.hs +++ b/Build.hs @@ -173,6 +173,7 @@ buildGhcStage booting opts cabal ghc0 dst = do , " " ++ src "libraries/ghci" , " " ++ src "libraries/os-string/" , " " ++ src "libraries/process/" + , " " ++ src "libraries/rts-fs/" , " " ++ src "libraries/rts-headers/" , " " ++ src "libraries/semaphore-compat" , " " ++ src "libraries/time" @@ -364,6 +365,7 @@ prepareGhcSources dst = do cp "./libraries" dst cp "./compiler/*" (dst "libraries/ghc/") cp "./rts" (dst "libraries/") + cp "./rts-fs" (dst "libraries/") cp "./rts-headers" (dst "libraries/") cp "./ghc" (dst "ghc-bin") cp "./utils" dst @@ -371,12 +373,6 @@ prepareGhcSources dst = do cp "./config.sub" (dst "libraries/rts/") cp "./config.guess" (dst "libraries/rts/") - -- shared among ghc-internal rts and unlit - cp "utils/fs/fs.h" (dst "libraries/ghc-internal/include") - cp "utils/fs/fs.c" (dst "libraries/ghc-internal/cbits") - cp "utils/fs/fs.*" (dst "libraries/rts/") - cp "utils/fs/fs.*" (dst "utils/unlit/") - buildBootLibraries :: Cabal -> Ghc -> GhcPkg -> DeriveConstants -> GenApply -> GenPrimop -> GhcBuildOptions -> FilePath -> IO () buildBootLibraries cabal ghc ghcpkg derive_constants genapply genprimop opts dst = do src <- makeAbsolute (dst "src") @@ -443,6 +439,7 @@ buildBootLibraries cabal ghc ghcpkg derive_constants genapply genprimop opts dst , "" , "packages:" , " " ++ src "libraries/rts" + , " " ++ src "libraries/rts-fs" , " " ++ src "libraries/rts-headers" , "" , "benchmarks: False" diff --git a/cabal.project.stage1 b/cabal.project.stage1 index 12b83e003a29..13215f3c8228 100644 --- a/cabal.project.stage1 +++ b/cabal.project.stage1 @@ -6,6 +6,7 @@ packages: ./compiler ./ghc ./rts-headers + ./rts-fs ./libraries/directory ./libraries/file-io ./libraries/filepath diff --git a/compiler/ghc.cabal b/compiler/ghc.cabal index 3b27f68d187c..2023a3af2fce 100644 --- a/compiler/ghc.cabal +++ b/compiler/ghc.cabal @@ -79,8 +79,6 @@ Library Exposed: False Includes: Unique.h - -- CodeGen.Platform.h -- invalid as C, skip - -- shared with rts via symlink if flag(build-tool-depends) build-tool-depends: alex:alex >= 3.2.6, happy:happy >= 1.20.0, genprimopcode:genprimopcode, deriveConstants:deriveConstants diff --git a/libraries/ghc-internal/ghc-internal.cabal b/libraries/ghc-internal/ghc-internal.cabal index ecc42e816866..a4c672cf3b4e 100644 --- a/libraries/ghc-internal/ghc-internal.cabal +++ b/libraries/ghc-internal/ghc-internal.cabal @@ -36,7 +36,6 @@ extra-source-files: include/HsBaseConfig.h.in include/ieee-flpt.h include/md5.h - include/fs.h include/winio_structs.h include/WordSize.h include/HsIntegerGmp.h.in @@ -116,7 +115,8 @@ Library Unsafe build-depends: - rts == 1.0.* + rts == 1.0.*, + rts-fs == 1.0.* exposed-modules: GHC.Internal.ClosureTypes @@ -431,7 +431,6 @@ Library cbits/md5.c cbits/primFloat.c cbits/sysconf.c - cbits/fs.c cbits/strerror.c cbits/atomic.c cbits/bswap.c diff --git a/utils/fs/README b/rts-fs/README similarity index 68% rename from utils/fs/README rename to rts-fs/README index 5011939a381f..446f95e9eceb 100644 --- a/utils/fs/README +++ b/rts-fs/README @@ -1,4 +1,2 @@ This "fs" library, used by various ghc utilities is used to share some common I/O filesystem functions with different packages. - -This file is copied across the build-system by configure. diff --git a/utils/fs/fs.c b/rts-fs/fs.c similarity index 100% rename from utils/fs/fs.c rename to rts-fs/fs.c diff --git a/utils/fs/fs.h b/rts-fs/fs.h similarity index 100% rename from utils/fs/fs.h rename to rts-fs/fs.h diff --git a/rts-fs/rts-fs.cabal b/rts-fs/rts-fs.cabal new file mode 100644 index 000000000000..f2ebc8aab300 --- /dev/null +++ b/rts-fs/rts-fs.cabal @@ -0,0 +1,15 @@ +cabal-version: 3.0 +name: rts-fs +version: 1.0.0.0 +license: NONE +author: Andrea Bedini +maintainer: andrea@andreabedini.com +build-type: Simple +extra-doc-files: README +extra-source-files: fs.h + +library + c-sources: fs.c + include-dirs: . + install-includes: fs.h + default-language: Haskell2010 diff --git a/rts/.gitignore b/rts/.gitignore index 179d62d55cf7..f1a295e18db0 100644 --- a/rts/.gitignore +++ b/rts/.gitignore @@ -8,7 +8,6 @@ /package.conf.inplace.raw /package.conf.install /package.conf.install.raw -/fs.* /aclocal.m4 /autom4te.cache/ diff --git a/rts/rts.cabal b/rts/rts.cabal index b616a2624a93..5cd95e7a11f0 100644 --- a/rts/rts.cabal +++ b/rts/rts.cabal @@ -55,7 +55,6 @@ extra-source-files: FileLock.h ForeignExports.h fs_rts.h - fs.h GetEnv.h GetTime.h Globals.h @@ -731,7 +730,6 @@ library sm/Scav_thr.c sm/Storage.c sm/Sweep.c - fs.c -- I wish we had wildcards..., this would be: -- *.c hooks/**/*.c sm/**/*.c eventlog/**/*.c linker/**/*.c @@ -776,7 +774,8 @@ library -- from Ticker.c build-depends: - rts-headers + rts-headers, + rts-fs -- Note [Undefined symbols in the RTS] -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/utils/unlit/unlit.cabal b/utils/unlit/unlit.cabal index 0707d5d95ae6..bbb157dc5d40 100644 --- a/utils/unlit/unlit.cabal +++ b/utils/unlit/unlit.cabal @@ -1,18 +1,13 @@ -cabal-version: 2.4 +cabal-version: 3.0 Name: unlit Version: 0.1 -Copyright: XXX License: BSD-3-Clause -Author: XXX -Maintainer: XXX Synopsis: Literate program filter -Description: XXX Category: Development build-type: Simple -extra-source-files: fs.h Executable unlit Default-Language: Haskell2010 Main-Is: unlit.c - C-Sources: fs.c - Includes: fs.h + build-depends: + rts-fs From 6eb8b9bfcb78b625466c6e54ad8ae2291b4519db Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Wed, 26 Feb 2025 12:19:36 +0800 Subject: [PATCH 18/84] feat(ghc): generate ghcversion.h on the fly --- Build.hs | 3 - compiler/GHC/Driver/Pipeline/Execute.hs | 2 +- compiler/GHC/SysTools/Cpp.hs | 75 +++++++++++++------------ rts/configure.ac | 3 +- rts/include/ghcversion.h.in | 18 ------ rts/rts.cabal | 4 +- 6 files changed, 43 insertions(+), 62 deletions(-) delete mode 100644 rts/include/ghcversion.h.in diff --git a/Build.hs b/Build.hs index 864b5bfa6cf5..c2dfa6a95a11 100755 --- a/Build.hs +++ b/Build.hs @@ -381,7 +381,6 @@ buildBootLibraries cabal ghc ghcpkg derive_constants genapply genprimop opts dst -- Build the RTS src_rts <- makeAbsolute (src "libraries/rts") build_dir <- makeAbsolute (dst "cabal") - ghcversionh <- makeAbsolute (src_rts "include/ghcversion.h") -- FIXME: could we build a cross compiler, simply by not reading this from the boot compiler, but passing it in? target_triple <- ghcTargetTriple ghc @@ -462,7 +461,6 @@ buildBootLibraries cabal ghc ghcpkg derive_constants genapply genprimop opts dst , "rts" , "--with-compiler=" ++ ghcPath ghc , "--with-hc-pkg=" ++ ghcPkgPath ghcpkg - , "--ghc-options=\"-ghcversion-file=" ++ ghcversionh ++ "\"" , "--builddir=" ++ build_dir ] @@ -629,7 +627,6 @@ buildBootLibraries cabal ghc ghcpkg derive_constants genapply genprimop opts dst , "--project-file=" ++ cabal_project_bootlibs_path , "--with-compiler=" ++ ghcPath ghc , "--with-hc-pkg=" ++ ghcPkgPath ghcpkg - , "--ghc-options=\"-ghcversion-file=" ++ ghcversionh ++ "\"" , "--builddir=" ++ build_dir , "-j" diff --git a/compiler/GHC/Driver/Pipeline/Execute.hs b/compiler/GHC/Driver/Pipeline/Execute.hs index 4f72eff1b737..798da42a5e63 100644 --- a/compiler/GHC/Driver/Pipeline/Execute.hs +++ b/compiler/GHC/Driver/Pipeline/Execute.hs @@ -478,7 +478,7 @@ runCcPhase cc_phase pipe_env hsc_env location input_fn = do -- very weakly typed, being derived from C--. ["-fno-strict-aliasing"] - include_ghcVersionH <- getGhcVersionIncludeFlags dflags unit_env + include_ghcVersionH <- getGhcVersionIncludeFlags dflags logger tmpfs withAtomicRename output_fn $ \temp_outputFilename -> GHC.SysTools.runCc (phaseForeignLanguage cc_phase) logger tmpfs dflags ( diff --git a/compiler/GHC/SysTools/Cpp.hs b/compiler/GHC/SysTools/Cpp.hs index 2f7f60afb92e..0059d2122781 100644 --- a/compiler/GHC/SysTools/Cpp.hs +++ b/compiler/GHC/SysTools/Cpp.hs @@ -6,7 +6,6 @@ module GHC.SysTools.Cpp ( doCpp , CppOpts(..) - , getGhcVersionPathName , getGhcVersionIncludeFlags , applyCDefs , offsetIncludePaths @@ -39,6 +38,7 @@ import Control.Monad import System.Directory import System.FilePath +import GHC.Settings.Config (cProjectVersionInt, cProjectPatchLevel1, cProjectVersion, cProjectPatchLevel2) data CppOpts = CppOpts { sourceCodePreprocessor :: !SourceCodePreprocessor @@ -125,10 +125,10 @@ doCpp logger tmpfs dflags unit_env opts input_fn output_fn = do [homeUnitEnv_dflags . ue_findHomeUnitEnv uid $ unit_env | uid <- ue_transitiveHomeDeps (ue_currentUnit unit_env) unit_env] dep_pkg_extra_inputs = [offsetIncludePaths fs (includePaths fs) | fs <- home_pkg_deps] - let include_paths_global = foldr (\ x xs -> ("-I" ++ x) : xs) [] + let include_paths_global = map ("-I" ++) (includePathsGlobal cmdline_include_paths ++ pkg_include_dirs ++ concatMap includePathsGlobal dep_pkg_extra_inputs) - let include_paths_quote = foldr (\ x xs -> ("-iquote" ++ x) : xs) [] + let include_paths_quote = map ("-iquote" ++) (includePathsQuote cmdline_include_paths ++ includePathsQuoteImplicit cmdline_include_paths) let include_paths = include_paths_quote ++ include_paths_global @@ -176,7 +176,7 @@ doCpp logger tmpfs dflags unit_env opts input_fn output_fn = do let asserts_def = [ "-D__GLASGOW_HASKELL_ASSERTS_IGNORED__" | gopt Opt_IgnoreAsserts dflags] -- Default CPP defines in Haskell source - hsSourceCppOpts <- getGhcVersionIncludeFlags dflags unit_env + hsSourceCppOpts <- getGhcVersionIncludeFlags dflags logger tmpfs -- MIN_VERSION macros let uids = explicitUnits unit_state @@ -262,40 +262,41 @@ generateMacros prefix name version = _ -> error "take3" (major1,major2,minor) = take3 $ map show (versionBranch version) ++ repeat "0" -getGhcVersionIncludeFlags :: DynFlags -> UnitEnv -> IO [String] -getGhcVersionIncludeFlags dflags unit_env = do - mghcversionh <- getGhcVersionPathName dflags unit_env - pure $ case mghcversionh of - Nothing -> [] - Just p -> ["-include", p] - --- | Find out path to @ghcversion.h@ file -getGhcVersionPathName :: DynFlags -> UnitEnv -> IO (Maybe FilePath) -getGhcVersionPathName dflags unit_env = do +getGhcVersionIncludeFlags :: DynFlags -> Logger -> TmpFs -> IO [String] +getGhcVersionIncludeFlags dflags logger tmpfs = do case ghcVersionFile dflags of - -- the user has provided an explicit `ghcversion.h` file to use. - Just path -> doesFileExist path >>= \case - True -> pure (Just path) - False -> throwGhcExceptionIO (InstallationError - ("ghcversion.h missing; tried user-supplied path: " ++ path)) - -- otherwise, try to find it in the rts' include-dirs. - -- Note: only in the RTS include-dirs! not all preload units less we may - -- use a wrong file. See #25106 where a globally installed - -- /usr/include/ghcversion.h file was used instead of the one provided - -- by the rts. - Nothing -> case lookupUnitId (ue_homeUnitState unit_env) rtsUnitId of - Nothing -> do - -- print warning and return nothing - putStrLn "Couldn't find ghcversion.h file: no rts unit available and -ghcversion-file flag not passed" - pure Nothing - Just info -> do - let candidates = ( "ghcversion.h") <$> collectIncludeDirs [info] - found <- filterM doesFileExist candidates - case found of - [] -> throwGhcExceptionIO (InstallationError - ("ghcversion.h missing; tried: " - ++ intercalate ", " candidates)) - (x:_) -> return (Just x) + -- the user has provided an explicit `ghcversion.h` file to use. + Just path -> do + found <- doesFileExist path + unless found $ + throwGhcExceptionIO (InstallationError ("ghcversion.h missing; tried: " ++ path)) + return ["-include", path] + Nothing -> do + macro_stub <- newTempName logger tmpfs (tmpDir dflags) TFL_CurrentModule "h" + writeFile macro_stub ghcVersionH + return ["-include", macro_stub] + +-- --------------------------------------------------------------------------- +-- ghcversion.h + +ghcVersionH :: String +ghcVersionH = + concat + ["#define __GLASGOW_HASKELL__ ", show cProjectVersionInt, "\n" + ,"#define __GLASGOW_HASKELL_FULL_VERSION__ ", show cProjectVersion, "\n" + ,"\n" + ,"#define __GLASGOW_HASKELL_PATCHLEVEL1__ ", show cProjectPatchLevel1, "\n" + ,"#define __GLASGOW_HASKELL_PATCHLEVEL2__ ", show cProjectPatchLevel2, "\n" + ,"\n" + ,"#define MIN_VERSION_GLASGOW_HASKELL(ma,mi,pl1,pl2) ( \\\n" + ," ((ma)*100+(mi)) < __GLASGOW_HASKELL__ || \\\n" + ," ((ma)*100+(mi)) == __GLASGOW_HASKELL__ \\\n" + ," && (pl1) < __GLASGOW_HASKELL_PATCHLEVEL1__ || \\\n" + ," ((ma)*100+(mi)) == __GLASGOW_HASKELL__ \\\n" + ," && (pl1) == __GLASGOW_HASKELL_PATCHLEVEL1__ \\\n" + ," && (pl2) <= __GLASGOW_HASKELL_PATCHLEVEL2__ )\n" + ,"\n\n" + ] applyCDefs :: DefunctionalizedCDefs -> Logger -> DynFlags -> IO [String] applyCDefs NoCDefs _ _ = return [] diff --git a/rts/configure.ac b/rts/configure.ac index 994799ab6d5e..a9b881fab61e 100644 --- a/rts/configure.ac +++ b/rts/configure.ac @@ -24,7 +24,8 @@ AC_PREREQ([2.69]) AC_CONFIG_FILES([ghcplatform.h.top]) -AC_CONFIG_HEADERS([ghcautoconf.h.autoconf]) +AC_CONFIG_FILES([include/ghcplatform.h]) +AC_CONFIG_HEADERS([include/ghcautoconf.h]) AC_ARG_WITH([compiler], [AS_HELP_STRING([--with-compiler=PATH], diff --git a/rts/include/ghcversion.h.in b/rts/include/ghcversion.h.in deleted file mode 100644 index dc700a4fbbf9..000000000000 --- a/rts/include/ghcversion.h.in +++ /dev/null @@ -1,18 +0,0 @@ -#if !defined(__GHCVERSION_H__) -#define __GHCVERSION_H__ - -#define __GLASGOW_HASKELL__ @ProjectVersionInt@ -#define __GLASGOW_HASKELL_FULL_VERSION__ "@ProjectVersion@" - -#define __GLASGOW_HASKELL_PATCHLEVEL1__ @ProjectPatchLevel1@ -#define __GLASGOW_HASKELL_PATCHLEVEL2__ @ProjectPatchLevel2@ - -#define MIN_VERSION_GLASGOW_HASKELL(ma,mi,pl1,pl2) ( \ - ((ma)*100+(mi)) < __GLASGOW_HASKELL__ || \ - ((ma)*100+(mi)) == __GLASGOW_HASKELL__ \ - && (pl1) < __GLASGOW_HASKELL_PATCHLEVEL1__ || \ - ((ma)*100+(mi)) == __GLASGOW_HASKELL__ \ - && (pl1) == __GLASGOW_HASKELL_PATCHLEVEL1__ \ - && (pl2) <= __GLASGOW_HASKELL_PATCHLEVEL2__ ) - -#endif /* __GHCVERSION_H__ */ diff --git a/rts/rts.cabal b/rts/rts.cabal index 5cd95e7a11f0..fb07c827e071 100644 --- a/rts/rts.cabal +++ b/rts/rts.cabal @@ -370,7 +370,7 @@ library js/time.js install-includes: HsFFI.h MachDeps.h Rts.h RtsAPI.h Stg.h - ghcautoconf.h ghcconfig.h ghcplatform.h ghcversion.h + ghcautoconf.h ghcconfig.h ghcplatform.h DerivedConstants.h stg/MachRegsForHost.h stg/Types.h @@ -475,7 +475,7 @@ library includes: Rts.h autogen-includes: ghcautoconf.h ghcplatform.h install-includes: Cmm.h HsFFI.h MachDeps.h Jumps.h Rts.h RtsAPI.h RtsSymbols.h Stg.h - ghcautoconf.h ghcconfig.h ghcplatform.h ghcversion.h + ghcautoconf.h ghcconfig.h ghcplatform.h -- ^ from include DerivedConstants.h rts/EventLogConstants.h From c1f34e9b70fce211afbd4216a22dec8eee2adc3c Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Thu, 27 Feb 2025 20:40:11 +0800 Subject: [PATCH 19/84] refactor(rts): simplify creation of rts/ghcautoconf.h --- rts/.gitignore | 4 +- rts/configure.ac | 20 -- rts/include/ghcautoconf.h.in | 665 +++++++++++++++++++++++++++++++++++ rts/rts.cabal | 13 +- 4 files changed, 675 insertions(+), 27 deletions(-) create mode 100644 rts/include/ghcautoconf.h.in diff --git a/rts/.gitignore b/rts/.gitignore index f1a295e18db0..f8ae0bde0528 100644 --- a/rts/.gitignore +++ b/rts/.gitignore @@ -3,6 +3,7 @@ /dist-*/ /include/ghcversion.h +/include/ghcautoconf.h /package.conf.inplace /package.conf.inplace.raw @@ -16,6 +17,3 @@ /configure /external-symbols.list -/ghcautoconf.h.autoconf.in -/ghcautoconf.h.autoconf -/include/ghcautoconf.h diff --git a/rts/configure.ac b/rts/configure.ac index a9b881fab61e..f2576491d96c 100644 --- a/rts/configure.ac +++ b/rts/configure.ac @@ -491,26 +491,6 @@ AS_IF( cat $srcdir/ghcplatform.h.bottom >> include/ghcplatform.h ] -dnl ###################################################################### -dnl Generate ghcautoconf.h -dnl ###################################################################### - -[ -touch include/ghcautoconf.h -> include/ghcautoconf.h - -echo "#if !defined(__GHCAUTOCONF_H__)" >> include/ghcautoconf.h -echo "#define __GHCAUTOCONF_H__" >> include/ghcautoconf.h -# Copy the contents of ghcautoconf.h.autoconf, turning '#define PACKAGE_FOO -# "blah"' into '/* #undef PACKAGE_FOO */' to avoid clashes. -cat ghcautoconf.h.autoconf | sed \ - -e 's,^\([ ]*\)#[ ]*define[ ][ ]*\(PACKAGE_[A-Z]*\)[ ][ ]*".*".*$,\1/* #undef \2 */,' \ - -e '/__GLASGOW_HASKELL/d' \ - -e '/REMOVE ME/d' \ - >> include/ghcautoconf.h -echo "#endif /* __GHCAUTOCONF_H__ */" >> include/ghcautoconf.h -] - dnl ###################################################################### dnl Generate external symbol flags (-Wl,-u...) dnl ###################################################################### diff --git a/rts/include/ghcautoconf.h.in b/rts/include/ghcautoconf.h.in new file mode 100644 index 000000000000..4195344b866f --- /dev/null +++ b/rts/include/ghcautoconf.h.in @@ -0,0 +1,665 @@ +/* include/ghcautoconf.h.in. Generated from configure.ac by autoheader. */ + +/* Define if building universal (internal helper macro) */ +#undef AC_APPLE_UNIVERSAL_BUILD + +/* The alignment of a `char'. */ +#undef ALIGNMENT_CHAR + +/* The alignment of a `double'. */ +#undef ALIGNMENT_DOUBLE + +/* The alignment of a `float'. */ +#undef ALIGNMENT_FLOAT + +/* The alignment of a `int'. */ +#undef ALIGNMENT_INT + +/* The alignment of a `int16_t'. */ +#undef ALIGNMENT_INT16_T + +/* The alignment of a `int32_t'. */ +#undef ALIGNMENT_INT32_T + +/* The alignment of a `int64_t'. */ +#undef ALIGNMENT_INT64_T + +/* The alignment of a `int8_t'. */ +#undef ALIGNMENT_INT8_T + +/* The alignment of a `long'. */ +#undef ALIGNMENT_LONG + +/* The alignment of a `long long'. */ +#undef ALIGNMENT_LONG_LONG + +/* The alignment of a `short'. */ +#undef ALIGNMENT_SHORT + +/* The alignment of a `uint16_t'. */ +#undef ALIGNMENT_UINT16_T + +/* The alignment of a `uint32_t'. */ +#undef ALIGNMENT_UINT32_T + +/* The alignment of a `uint64_t'. */ +#undef ALIGNMENT_UINT64_T + +/* The alignment of a `uint8_t'. */ +#undef ALIGNMENT_UINT8_T + +/* The alignment of a `unsigned char'. */ +#undef ALIGNMENT_UNSIGNED_CHAR + +/* The alignment of a `unsigned int'. */ +#undef ALIGNMENT_UNSIGNED_INT + +/* The alignment of a `unsigned long'. */ +#undef ALIGNMENT_UNSIGNED_LONG + +/* The alignment of a `unsigned long long'. */ +#undef ALIGNMENT_UNSIGNED_LONG_LONG + +/* The alignment of a `unsigned short'. */ +#undef ALIGNMENT_UNSIGNED_SHORT + +/* The alignment of a `void *'. */ +#undef ALIGNMENT_VOID_P + +/* Define (to 1) if C compiler has an LLVM back end */ +#undef CC_LLVM_BACKEND + +/* Define to 1 if __thread is supported */ +#undef CC_SUPPORTS_TLS + +/* Define to 1 if using 'alloca.c'. */ +#undef C_ALLOCA + +/* Define to 1 if your processor stores words of floats with the most + significant byte first */ +#undef FLOAT_WORDS_BIGENDIAN + +/* Has musttail */ +#undef HAS_MUSTTAIL + +/* Has visibility hidden */ +#undef HAS_VISIBILITY_HIDDEN + +/* Define to 1 if you have 'alloca', as a function or macro. */ +#undef HAVE_ALLOCA + +/* Define to 1 if works. */ +#undef HAVE_ALLOCA_H + +/* Does the toolchain use ARMv8 outline atomics */ +#undef HAVE_ARM_OUTLINE_ATOMICS + +/* Define to 1 if you have the header file. */ +#undef HAVE_BFD_H + +/* Define to 1 if you have the 'clock_gettime' function. */ +#undef HAVE_CLOCK_GETTIME + +/* Define to 1 if you have the 'ctime_r' function. */ +#undef HAVE_CTIME_R + +/* Define to 1 if you have the header file. */ +#undef HAVE_CTYPE_H + +/* Define to 1 if you have the declaration of 'ctime_r', and to 0 if you + don't. */ +#undef HAVE_DECL_CTIME_R + +/* Define to 1 if you have the declaration of 'environ', and to 0 if you + don't. */ +#undef HAVE_DECL_ENVIRON + +/* Define to 1 if you have the declaration of 'MADV_DONTNEED', and to 0 if you + don't. */ +#undef HAVE_DECL_MADV_DONTNEED + +/* Define to 1 if you have the declaration of 'MADV_FREE', and to 0 if you + don't. */ +#undef HAVE_DECL_MADV_FREE + +/* Define to 1 if you have the declaration of 'MAP_NORESERVE', and to 0 if you + don't. */ +#undef HAVE_DECL_MAP_NORESERVE + +/* Define to 1 if you have the declaration of 'program_invocation_short_name', + and to 0 if you don't. */ +#undef HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME + +/* Define to 1 if you have the header file. */ +#undef HAVE_DIRENT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_DLFCN_H + +/* Define to 1 if you have the 'dlinfo' function. */ +#undef HAVE_DLINFO + +/* Define to 1 if you have the header file. */ +#undef HAVE_ERRNO_H + +/* Define to 1 if you have the 'eventfd' function. */ +#undef HAVE_EVENTFD + +/* Define to 1 if you have the header file. */ +#undef HAVE_FCNTL_H + +/* Define to 1 if you have the 'fork' function. */ +#undef HAVE_FORK + +/* Define to 1 if you have the 'getclock' function. */ +#undef HAVE_GETCLOCK + +/* Define to 1 if you have the `GetModuleFileName' function. */ +#undef HAVE_GETMODULEFILENAME + +/* Define to 1 if you have the 'getpid' function. */ +#undef HAVE_GETPID + +/* Define to 1 if you have the 'getrusage' function. */ +#undef HAVE_GETRUSAGE + +/* Define to 1 if you have the 'gettimeofday' function. */ +#undef HAVE_GETTIMEOFDAY + +/* Define to 1 if you have the 'getuid' function. */ +#undef HAVE_GETUID + +/* Define (to 1) if GNU-style non-executable stack note is supported */ +#undef HAVE_GNU_NONEXEC_STACK + +/* Define to 1 if you have the header file. */ +#undef HAVE_GRP_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_INTTYPES_H + +/* Define to 1 if you have the 'bfd' library (-lbfd). */ +#undef HAVE_LIBBFD + +/* Define to 1 if you have the 'dl' library (-ldl). */ +#undef HAVE_LIBDL + +/* Define to 1 if you have the 'iberty' library (-liberty). */ +#undef HAVE_LIBIBERTY + +/* Define to 1 if you need to link with libm */ +#undef HAVE_LIBM + +/* Define to 1 if you have libnuma */ +#undef HAVE_LIBNUMA + +/* Define to 1 if you have the 'pthread' library (-lpthread). */ +#undef HAVE_LIBPTHREAD + +/* Define to 1 if you wish to compress IPE data in compiler results (requires + libzstd) */ +#undef HAVE_LIBZSTD + +/* Define to 1 if you have the header file. */ +#undef HAVE_LIMITS_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_LOCALE_H + +/* Define to 1 if the system has the type 'long long'. */ +#undef HAVE_LONG_LONG + +/* Define to 1 if you have the header file. */ +#undef HAVE_MINIX_CONFIG_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_NLIST_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_NUMAIF_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_NUMA_H + +/* Define to 1 if we have printf$LDBLStub (Apple Mac OS >= 10.4, PPC). */ +#undef HAVE_PRINTF_LDBLSTUB + +/* Define to 1 if you have the 'pthread_condattr_setclock' function. */ +#undef HAVE_PTHREAD_CONDATTR_SETCLOCK + +/* Define to 1 if you have the header file. */ +#undef HAVE_PTHREAD_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_PTHREAD_NP_H + +/* Define to 1 if you have the glibc version of pthread_setname_np */ +#undef HAVE_PTHREAD_SETNAME_NP + +/* Define to 1 if you have the Darwin version of pthread_setname_np */ +#undef HAVE_PTHREAD_SETNAME_NP_DARWIN + +/* Define to 1 if you have the NetBSD version of pthread_setname_np */ +#undef HAVE_PTHREAD_SETNAME_NP_NETBSD + +/* Define to 1 if you have pthread_set_name_np */ +#undef HAVE_PTHREAD_SET_NAME_NP + +/* Define to 1 if you have the header file. */ +#undef HAVE_PWD_H + +/* Define to 1 if you have the 'raise' function. */ +#undef HAVE_RAISE + +/* Define to 1 if you have the 'sched_getaffinity' function. */ +#undef HAVE_SCHED_GETAFFINITY + +/* Define to 1 if you have the header file. */ +#undef HAVE_SCHED_H + +/* Define to 1 if you have the 'sched_setaffinity' function. */ +#undef HAVE_SCHED_SETAFFINITY + +/* Define to 1 if you have the 'setitimer' function. */ +#undef HAVE_SETITIMER + +/* Define to 1 if you have the 'setlocale' function. */ +#undef HAVE_SETLOCALE + +/* Define to 1 if you have the 'siginterrupt' function. */ +#undef HAVE_SIGINTERRUPT + +/* Define to 1 if you have the header file. */ +#undef HAVE_SIGNAL_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDIO_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDLIB_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if Apple-style dead-stripping is supported. */ +#undef HAVE_SUBSECTIONS_VIA_SYMBOLS + +/* Define to 1 if you have the 'sysconf' function. */ +#undef HAVE_SYSCONF + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_CPUSET_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_EVENTFD_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_MMAN_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_PARAM_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_RESOURCE_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_SELECT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TIMEB_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TIMERFD_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TIMERS_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TIMES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TIME_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_UTSNAME_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_WAIT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_TERMIOS_H + +/* Define to 1 if you have the 'timer_settime' function. */ +#undef HAVE_TIMER_SETTIME + +/* Define to 1 if you have the 'times' function. */ +#undef HAVE_TIMES + +/* Define to 1 if you have the header file. */ +#undef HAVE_UNISTD_H + +/* Define to 1 if you have the 'uselocale' function. */ +#undef HAVE_USELOCALE + +/* Define to 1 if you have the header file. */ +#undef HAVE_UTIME_H + +/* Define to 1 if you have the 'vfork' function. */ +#undef HAVE_VFORK + +/* Define to 1 if you have the header file. */ +#undef HAVE_VFORK_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_WCHAR_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_WINDOWS_H + +/* Define to 1 if you have the `WinExec' function. */ +#undef HAVE_WINEXEC + +/* Define to 1 if you have the header file. */ +#undef HAVE_WINSOCK_H + +/* Define to 1 if 'fork' works. */ +#undef HAVE_WORKING_FORK + +/* Define to 1 if 'vfork' works. */ +#undef HAVE_WORKING_VFORK + +/* Define to 1 if the mio I/O manager should be built */ +#undef IOMGR_BUILD_MIO + +/* Define to 1 if the select I/O manager should be built */ +#undef IOMGR_BUILD_SELECT + +/* Define to 1 if the win32-legacy I/O manager should be built */ +#undef IOMGR_BUILD_WIN32_LEGACY + +/* Define to 1 if the winio I/O manager should be built */ +#undef IOMGR_BUILD_WINIO + +/* Define to 1 if the select I/O manager is the default for the non-threaded + RTS */ +#undef IOMGR_DEFAULT_NON_THREADED_SELECT + +/* Define to 1 if the win32-legacy I/O manager is the default for the + non-threaded RTS */ +#undef IOMGR_DEFAULT_NON_THREADED_WIN32_LEGACY + +/* Define to 1 if the winio I/O manager is the default for the non-threaded + RTS */ +#undef IOMGR_DEFAULT_NON_THREADED_WINIO + +/* Define to 1 if the mio I/O manager is the default for the threaded RTS */ +#undef IOMGR_DEFAULT_THREADED_MIO + +/* Define to 1 if the winio I/O manager is the default for the threaded RTS */ +#undef IOMGR_DEFAULT_THREADED_WINIO + +/* Define to 1 if C symbols have a leading underscore added by the compiler. + */ +#undef LEADING_UNDERSCORE + +/* Define to 1 if we need -latomic for sub-word atomic operations. */ +#undef NEED_ATOMIC_LIB + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the home page for this package. */ +#undef PACKAGE_URL + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Use mmap in the runtime linker */ +#undef RTS_LINKER_USE_MMAP + +/* The size of 'char', as computed by sizeof. */ +#undef SIZEOF_CHAR + +/* The size of 'double', as computed by sizeof. */ +#undef SIZEOF_DOUBLE + +/* The size of 'float', as computed by sizeof. */ +#undef SIZEOF_FLOAT + +/* The size of 'int', as computed by sizeof. */ +#undef SIZEOF_INT + +/* The size of 'int16_t', as computed by sizeof. */ +#undef SIZEOF_INT16_T + +/* The size of 'int32_t', as computed by sizeof. */ +#undef SIZEOF_INT32_T + +/* The size of 'int64_t', as computed by sizeof. */ +#undef SIZEOF_INT64_T + +/* The size of 'int8_t', as computed by sizeof. */ +#undef SIZEOF_INT8_T + +/* The size of 'long', as computed by sizeof. */ +#undef SIZEOF_LONG + +/* The size of 'long long', as computed by sizeof. */ +#undef SIZEOF_LONG_LONG + +/* The size of 'short', as computed by sizeof. */ +#undef SIZEOF_SHORT + +/* The size of 'uint16_t', as computed by sizeof. */ +#undef SIZEOF_UINT16_T + +/* The size of 'uint32_t', as computed by sizeof. */ +#undef SIZEOF_UINT32_T + +/* The size of 'uint64_t', as computed by sizeof. */ +#undef SIZEOF_UINT64_T + +/* The size of 'uint8_t', as computed by sizeof. */ +#undef SIZEOF_UINT8_T + +/* The size of 'unsigned char', as computed by sizeof. */ +#undef SIZEOF_UNSIGNED_CHAR + +/* The size of 'unsigned int', as computed by sizeof. */ +#undef SIZEOF_UNSIGNED_INT + +/* The size of 'unsigned long', as computed by sizeof. */ +#undef SIZEOF_UNSIGNED_LONG + +/* The size of 'unsigned long long', as computed by sizeof. */ +#undef SIZEOF_UNSIGNED_LONG_LONG + +/* The size of 'unsigned short', as computed by sizeof. */ +#undef SIZEOF_UNSIGNED_SHORT + +/* The size of 'void *', as computed by sizeof. */ +#undef SIZEOF_VOID_P + +/* If using the C implementation of alloca, define if you know the + direction of stack growth for your system; otherwise it will be + automatically deduced at runtime. + STACK_DIRECTION > 0 => grows toward higher addresses + STACK_DIRECTION < 0 => grows toward lower addresses + STACK_DIRECTION = 0 => direction of growth unknown */ +#undef STACK_DIRECTION + +/* Define to 1 if you wish to statically link the libzstd compression library + in the compiler (requires libzstd) */ +#undef STATIC_LIBZSTD + +/* Define to 1 if all of the C89 standard headers exist (not just the ones + required in a freestanding environment). This macro is provided for + backward compatibility; new code need not use it. */ +#undef STDC_HEADERS + +/* Define to 1 if info tables are laid out next to code */ +#undef TABLES_NEXT_TO_CODE + +/* Compile-in ASSERTs in all ways. */ +#undef USE_ASSERTS_ALL_WAYS + +/* Enable single heap address space support */ +#undef USE_LARGE_ADDRESS_SPACE + +/* Set to 1 to use libdw */ +#undef USE_LIBDW + +/* Enable extensions on AIX, Interix, z/OS. */ +#ifndef _ALL_SOURCE +# undef _ALL_SOURCE +#endif +/* Enable general extensions on macOS. */ +#ifndef _DARWIN_C_SOURCE +# undef _DARWIN_C_SOURCE +#endif +/* Enable general extensions on Solaris. */ +#ifndef __EXTENSIONS__ +# undef __EXTENSIONS__ +#endif +/* Enable GNU extensions on systems that have them. */ +#ifndef _GNU_SOURCE +# undef _GNU_SOURCE +#endif +/* Enable X/Open compliant socket functions that do not require linking + with -lxnet on HP-UX 11.11. */ +#ifndef _HPUX_ALT_XOPEN_SOCKET_API +# undef _HPUX_ALT_XOPEN_SOCKET_API +#endif +/* Identify the host operating system as Minix. + This macro does not affect the system headers' behavior. + A future release of Autoconf may stop defining this macro. */ +#ifndef _MINIX +# undef _MINIX +#endif +/* Enable general extensions on NetBSD. + Enable NetBSD compatibility extensions on Minix. */ +#ifndef _NETBSD_SOURCE +# undef _NETBSD_SOURCE +#endif +/* Enable OpenBSD compatibility extensions on NetBSD. + Oddly enough, this does nothing on OpenBSD. */ +#ifndef _OPENBSD_SOURCE +# undef _OPENBSD_SOURCE +#endif +/* Define to 1 if needed for POSIX-compatible behavior. */ +#ifndef _POSIX_SOURCE +# undef _POSIX_SOURCE +#endif +/* Define to 2 if needed for POSIX-compatible behavior. */ +#ifndef _POSIX_1_SOURCE +# undef _POSIX_1_SOURCE +#endif +/* Enable POSIX-compatible threading on Solaris. */ +#ifndef _POSIX_PTHREAD_SEMANTICS +# undef _POSIX_PTHREAD_SEMANTICS +#endif +/* Enable extensions specified by ISO/IEC TS 18661-5:2014. */ +#ifndef __STDC_WANT_IEC_60559_ATTRIBS_EXT__ +# undef __STDC_WANT_IEC_60559_ATTRIBS_EXT__ +#endif +/* Enable extensions specified by ISO/IEC TS 18661-1:2014. */ +#ifndef __STDC_WANT_IEC_60559_BFP_EXT__ +# undef __STDC_WANT_IEC_60559_BFP_EXT__ +#endif +/* Enable extensions specified by ISO/IEC TS 18661-2:2015. */ +#ifndef __STDC_WANT_IEC_60559_DFP_EXT__ +# undef __STDC_WANT_IEC_60559_DFP_EXT__ +#endif +/* Enable extensions specified by C23 Annex F. */ +#ifndef __STDC_WANT_IEC_60559_EXT__ +# undef __STDC_WANT_IEC_60559_EXT__ +#endif +/* Enable extensions specified by ISO/IEC TS 18661-4:2015. */ +#ifndef __STDC_WANT_IEC_60559_FUNCS_EXT__ +# undef __STDC_WANT_IEC_60559_FUNCS_EXT__ +#endif +/* Enable extensions specified by C23 Annex H and ISO/IEC TS 18661-3:2015. */ +#ifndef __STDC_WANT_IEC_60559_TYPES_EXT__ +# undef __STDC_WANT_IEC_60559_TYPES_EXT__ +#endif +/* Enable extensions specified by ISO/IEC TR 24731-2:2010. */ +#ifndef __STDC_WANT_LIB_EXT2__ +# undef __STDC_WANT_LIB_EXT2__ +#endif +/* Enable extensions specified by ISO/IEC 24747:2009. */ +#ifndef __STDC_WANT_MATH_SPEC_FUNCS__ +# undef __STDC_WANT_MATH_SPEC_FUNCS__ +#endif +/* Enable extensions on HP NonStop. */ +#ifndef _TANDEM_SOURCE +# undef _TANDEM_SOURCE +#endif +/* Enable X/Open extensions. Define to 500 only if necessary + to make mbstate_t available. */ +#ifndef _XOPEN_SOURCE +# undef _XOPEN_SOURCE +#endif + + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +# undef WORDS_BIGENDIAN +# endif +#endif + +/* Number of bits in a file offset, on hosts where this is settable. */ +#undef _FILE_OFFSET_BITS + +/* Define to 1 on platforms where this makes off_t a 64-bit type. */ +#undef _LARGE_FILES + +/* Number of bits in time_t, on hosts where this is settable. */ +#undef _TIME_BITS + +/* Define to 1 on platforms where this makes time_t a 64-bit type. */ +#undef __MINGW_USE_VC2005_COMPAT + +/* ARM pre v6 */ +#undef arm_HOST_ARCH_PRE_ARMv6 + +/* ARM pre v7 */ +#undef arm_HOST_ARCH_PRE_ARMv7 + +/* Define to empty if 'const' does not conform to ANSI C. */ +#undef const + +/* Define as a signed integer type capable of holding a process identifier. */ +#undef pid_t + +/* Define as 'unsigned int' if doesn't define. */ +#undef size_t + +/* Define as 'fork' if 'vfork' does not work. */ +#undef vfork diff --git a/rts/rts.cabal b/rts/rts.cabal index fb07c827e071..0fd24423614e 100644 --- a/rts/rts.cabal +++ b/rts/rts.cabal @@ -17,7 +17,6 @@ extra-source-files: config.sub ghcplatform.h.top.in ghcplatform.h.bottom - ghcautoconf.h.autoconf.in configure.ac external-symbols.list.in rts.buildinfo.in @@ -61,6 +60,7 @@ extra-source-files: Hash.h hooks/Hooks.h include/Cmm.h + include/ghcautoconf.h.in include/ghcconfig.h include/HsFFI.h include/MachDeps.h @@ -336,6 +336,11 @@ library exposed: True exposed-modules: + autogen-includes: + ghcautoconf.h + install-includes: + ghcautoconf.h + if arch(javascript) include-dirs: include @@ -370,7 +375,7 @@ library js/time.js install-includes: HsFFI.h MachDeps.h Rts.h RtsAPI.h Stg.h - ghcautoconf.h ghcconfig.h ghcplatform.h + ghcconfig.h ghcplatform.h DerivedConstants.h stg/MachRegsForHost.h stg/Types.h @@ -473,9 +478,9 @@ library -- TODO: move internal headers into include/private? include-dirs: . includes: Rts.h - autogen-includes: ghcautoconf.h ghcplatform.h + autogen-includes: ghcplatform.h install-includes: Cmm.h HsFFI.h MachDeps.h Jumps.h Rts.h RtsAPI.h RtsSymbols.h Stg.h - ghcautoconf.h ghcconfig.h ghcplatform.h + ghcconfig.h ghcplatform.h -- ^ from include DerivedConstants.h rts/EventLogConstants.h From 5c68f661545aced4232ff3816f773fa75506afa5 Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Tue, 18 Feb 2025 10:43:23 +0800 Subject: [PATCH 20/84] refactor(rts): simplify creation of ghcplatform.h --- rts/configure.ac | 28 ++----------------- rts/ghcplatform.h.bottom | 2 -- .../ghcplatform.h.in} | 4 +++ rts/rts.cabal | 7 +++-- 4 files changed, 11 insertions(+), 30 deletions(-) delete mode 100644 rts/ghcplatform.h.bottom rename rts/{ghcplatform.h.top.in => include/ghcplatform.h.in} (87%) diff --git a/rts/configure.ac b/rts/configure.ac index f2576491d96c..3db1a254a469 100644 --- a/rts/configure.ac +++ b/rts/configure.ac @@ -22,8 +22,6 @@ dnl #define SIZEOF_CHAR 0 dnl recently. AC_PREREQ([2.69]) -AC_CONFIG_FILES([ghcplatform.h.top]) - AC_CONFIG_FILES([include/ghcplatform.h]) AC_CONFIG_HEADERS([include/ghcautoconf.h]) @@ -376,6 +374,9 @@ AS_IF( [test "$CABAL_FLAG_libnuma" = 1], [AC_CHECK_HEADERS([numa.h numaif.h])]) +dnl ** Do an unregisterised build? +dnl -------------------------------------------------------------- +AC_SUBST(CABAL_FLAG_unregisterised) dnl ** I/O managers dnl -------------------------------------------------------------- @@ -468,29 +469,6 @@ dnl -------------------------------------------------------------- AC_OUTPUT -dnl ###################################################################### -dnl Generate ghcplatform.h -dnl ###################################################################### - -[ -mkdir -p include - -touch include/ghcplatform.h -> include/ghcplatform.h - -cat ghcplatform.h.top >> include/ghcplatform.h -] - -dnl ** Do an unregisterised build? -dnl -------------------------------------------------------------- -AS_IF( - [test "$CABAL_FLAG_unregisterised" = 1], - [echo "#define UnregisterisedCompiler 1" >> include/ghcplatform.h]) - -[ -cat $srcdir/ghcplatform.h.bottom >> include/ghcplatform.h -] - dnl ###################################################################### dnl Generate external symbol flags (-Wl,-u...) dnl ###################################################################### diff --git a/rts/ghcplatform.h.bottom b/rts/ghcplatform.h.bottom deleted file mode 100644 index 77c4b776533d..000000000000 --- a/rts/ghcplatform.h.bottom +++ /dev/null @@ -1,2 +0,0 @@ - -#endif /* __GHCPLATFORM_H__ */ diff --git a/rts/ghcplatform.h.top.in b/rts/include/ghcplatform.h.in similarity index 87% rename from rts/ghcplatform.h.top.in rename to rts/include/ghcplatform.h.in index ebb1961a1f1e..125645554d89 100644 --- a/rts/ghcplatform.h.top.in +++ b/rts/include/ghcplatform.h.in @@ -21,3 +21,7 @@ #define @HostVendor_CPP@_HOST_VENDOR 1 #define BUILD_VENDOR "@BuildVendor_CPP@" #define HOST_VENDOR "@HostVendor_CPP@" + +#define UnregisterisedCompiler @CABAL_FLAG_unregisterised@ + +#endif /* __GHCPLATFORM_H__ */ diff --git a/rts/rts.cabal b/rts/rts.cabal index 0fd24423614e..a662e67d79a8 100644 --- a/rts/rts.cabal +++ b/rts/rts.cabal @@ -15,8 +15,6 @@ extra-source-files: configure config.guess config.sub - ghcplatform.h.top.in - ghcplatform.h.bottom configure.ac external-symbols.list.in rts.buildinfo.in @@ -61,6 +59,7 @@ extra-source-files: hooks/Hooks.h include/Cmm.h include/ghcautoconf.h.in + include/ghcplatform.h.in include/ghcconfig.h include/HsFFI.h include/MachDeps.h @@ -338,8 +337,11 @@ library autogen-includes: ghcautoconf.h + ghcplatform.h + install-includes: ghcautoconf.h + ghcplatform.h if arch(javascript) @@ -478,7 +480,6 @@ library -- TODO: move internal headers into include/private? include-dirs: . includes: Rts.h - autogen-includes: ghcplatform.h install-includes: Cmm.h HsFFI.h MachDeps.h Jumps.h Rts.h RtsAPI.h RtsSymbols.h Stg.h ghcconfig.h ghcplatform.h -- ^ from include From cd5ee062d74a26e437b53077d7877233c97a9222 Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Fri, 14 Feb 2025 15:42:21 +0800 Subject: [PATCH 21/84] feat: replace some submodules with official versions This removes the need of a separate bootstrap. --- cabal.project.stage1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cabal.project.stage1 b/cabal.project.stage1 index 13215f3c8228..f008ebe25873 100644 --- a/cabal.project.stage1 +++ b/cabal.project.stage1 @@ -7,7 +7,7 @@ packages: ./ghc ./rts-headers ./rts-fs - ./libraries/directory + https://hackage.haskell.org/package/directory-1.3.9.0/directory-1.3.9.0.tar.gz ./libraries/file-io ./libraries/filepath ./libraries/ghc-platform @@ -15,11 +15,11 @@ packages: ./libraries/ghc-boot-th ./libraries/ghc-heap ./libraries/ghci - ./libraries/os-string - ./libraries/process + https://hackage.haskell.org/package/os-string-2.0.7/os-string-2.0.7.tar.gz + https://hackage.haskell.org/package/process-1.6.25.0/process-1.6.25.0.tar.gz ./libraries/semaphore-compat - ./libraries/time - ./libraries/unix + https://hackage.haskell.org/package/time-1.14/time-1.14.tar.gz + https://hackage.haskell.org/package/unix-2.8.6.0/unix-2.8.6.0.tar.gz ./libraries/Win32 ./utils/ghc-pkg ./utils/hsc2hs From bc9af297e204f9cf792f88368386cece3be0562a Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Thu, 27 Feb 2025 09:20:08 +0800 Subject: [PATCH 22/84] refactor(rts/configure.ac): produce rts.buildinfo in a more standard way --- rts/configure.ac | 54 ++++----- ...-symbols.list.in => external-symbols.list} | 112 ++++++++---------- rts/rts.buildinfo.in | 4 +- rts/rts.cabal | 2 +- 4 files changed, 72 insertions(+), 100 deletions(-) rename rts/{external-symbols.list.in => external-symbols.list} (93%) diff --git a/rts/configure.ac b/rts/configure.ac index 3db1a254a469..fa733efda21e 100644 --- a/rts/configure.ac +++ b/rts/configure.ac @@ -23,8 +23,11 @@ dnl recently. AC_PREREQ([2.69]) AC_CONFIG_FILES([include/ghcplatform.h]) +AC_CONFIG_FILES([rts.buildinfo]) AC_CONFIG_HEADERS([include/ghcautoconf.h]) +AC_PROG_AWK + AC_ARG_WITH([compiler], [AS_HELP_STRING([--with-compiler=PATH], [Use a particular compiler available at PATH (default: ghc)])], @@ -463,49 +466,34 @@ GHC_IOMANAGER_DEFAULT_AC_DEFINE([IOManagerThreadedDefault], [threaded], GHC_IOMANAGER_DEFAULT_AC_DEFINE([IOManagerThreadedDefault], [threaded], [winio], [IOMGR_DEFAULT_THREADED_WINIO]) - -dnl ** Write config files -dnl -------------------------------------------------------------- - -AC_OUTPUT - dnl ###################################################################### dnl Generate external symbol flags (-Wl,-u...) dnl ###################################################################### dnl See Note [Undefined symbols in the RTS] -[ -symbolExtraDefs='' -if [ "$CABAL_FLAG_find_ptr" = 1 ]; then - symbolExtraDefs+=' -DFIND_PTR' +TEMP_FILE=`mktemp conftest.XXXXXX` || exit 1 + +cp $srcdir/external-symbols.list "$TEMP_FILE" + +if test "$CABAL_FLAG_find_ptr" = 1; then + echo findPtr >> "$TEMP_FILE" fi -cat $srcdir/external-symbols.list.in \ - | "$CC" $symbolExtraDefs -E -P -traditional -Iinclude - -o - \ - | sed -e '/^ *$/d' \ - > external-symbols.list \ - || exit 1 +if test "$HostOS_CPP" = "mingw32"; then + echo ghczminternal_GHCziInternalziEventziWindows_processRemoteCompletion_closure >> "$TEMP_FILE" +fi -if [ "$CABAL_FLAG_leading_underscore" = 1 ]; then - sedExpr='s/^(.*)$/ "-Wl,-u,_\1"/' +if test "$CABAL_FLAGS_leading_underscore" = 1; then + LDFLAGS="$LDFLAGS `echo; $AWK '{ print " -Wl,-u,_" $0 }' "$TEMP_FILE"`" else - sedExpr='s/^(.*)$/ "-Wl,-u,\1"/' + LDFLAGS="$LDFLAGS `echo; $AWK '{ print " -Wl,-u," $0 }' "$TEMP_FILE"`" fi -sed -E -e "${sedExpr}" external-symbols.list > external-symbols.flags -unset sedExpr -rm -f external-symbols.list -] -dnl ###################################################################### -dnl Generate build-info -dnl ###################################################################### +rm -rf "$TEMP_FILE" + +dnl -------------------------------------------------------------- +dnl ** Write config files +dnl -------------------------------------------------------------- -[ -cat $srcdir/rts.buildinfo.in \ - | "$CC" -E -P -traditional - -o - \ - | sed -e '/^ *$/d' \ - > rts.buildinfo \ - || exit 1 -rm -f external-symbols.flags -] +AC_OUTPUT diff --git a/rts/external-symbols.list.in b/rts/external-symbols.list similarity index 93% rename from rts/external-symbols.list.in rename to rts/external-symbols.list index 5afab9f4df5d..1a8e5f59b934 100644 --- a/rts/external-symbols.list.in +++ b/rts/external-symbols.list @@ -1,97 +1,83 @@ -#include "ghcautoconf.h" - -#if 0 -See Note [Undefined symbols in the RTS] -#endif - -#if mingw32_HOST_OS -ghczminternal_GHCziInternalziEventziWindows_processRemoteCompletion_closure -#endif - -#if FIND_PTR -findPtr -#endif - -ghczminternal_GHCziInternalziTopHandler_runIO_closure -ghczminternal_GHCziInternalziTopHandler_runNonIO_closure -ghczminternal_GHCziInternalziTuple_Z0T_closure -ghczminternal_GHCziInternalziTypes_True_closure -ghczminternal_GHCziInternalziTypes_False_closure -ghczminternal_GHCziInternalziPack_unpackCString_closure -ghczminternal_GHCziInternalziWeakziFinalizze_runFinalizzerBatch_closure -ghczminternal_GHCziInternalziIOziException_stackOverflow_closure -ghczminternal_GHCziInternalziIOziException_heapOverflow_closure +ghczminternal_GHCziInternalziConcziIO_ensureIOManagerIsRunning_closure +ghczminternal_GHCziInternalziConcziIO_interruptIOManager_closure +ghczminternal_GHCziInternalziConcziIO_ioManagerCapabilitiesChanged_closure +ghczminternal_GHCziInternalziConcziSignal_runHandlersPtr_closure +ghczminternal_GHCziInternalziConcziSync_runSparks_closure +ghczminternal_GHCziInternalziControlziExceptionziBase_nestedAtomically_closure +ghczminternal_GHCziInternalziControlziExceptionziBase_nonTermination_closure +ghczminternal_GHCziInternalziEventziThread_blockedOnBadFD_closure +ghczminternal_GHCziInternalziIOPort_doubleReadException_closure ghczminternal_GHCziInternalziIOziException_allocationLimitExceeded_closure ghczminternal_GHCziInternalziIOziException_blockedIndefinitelyOnMVar_closure ghczminternal_GHCziInternalziIOziException_blockedIndefinitelyOnSTM_closure ghczminternal_GHCziInternalziIOziException_cannotCompactFunction_closure -ghczminternal_GHCziInternalziIOziException_cannotCompactPinned_closure ghczminternal_GHCziInternalziIOziException_cannotCompactMutable_closure -ghczminternal_GHCziInternalziIOPort_doubleReadException_closure -ghczminternal_GHCziInternalziControlziExceptionziBase_nonTermination_closure -ghczminternal_GHCziInternalziControlziExceptionziBase_nestedAtomically_closure -ghczminternal_GHCziInternalziEventziThread_blockedOnBadFD_closure -ghczminternal_GHCziInternalziConcziSync_runSparks_closure -ghczminternal_GHCziInternalziConcziIO_ensureIOManagerIsRunning_closure -ghczminternal_GHCziInternalziConcziIO_interruptIOManager_closure -ghczminternal_GHCziInternalziConcziIO_ioManagerCapabilitiesChanged_closure -ghczminternal_GHCziInternalziConcziSignal_runHandlersPtr_closure +ghczminternal_GHCziInternalziIOziException_cannotCompactPinned_closure +ghczminternal_GHCziInternalziIOziException_heapOverflow_closure +ghczminternal_GHCziInternalziIOziException_stackOverflow_closure +ghczminternal_GHCziInternalziInt_I16zh_con_info +ghczminternal_GHCziInternalziInt_I32zh_con_info +ghczminternal_GHCziInternalziInt_I64zh_con_info +ghczminternal_GHCziInternalziInt_I8zh_con_info +ghczminternal_GHCziInternalziPack_unpackCString_closure +ghczminternal_GHCziInternalziPtr_FunPtr_con_info +ghczminternal_GHCziInternalziPtr_Ptr_con_info +ghczminternal_GHCziInternalziStable_StablePtr_con_info +ghczminternal_GHCziInternalziStackziCloneStack_StackSnapshot_closure ghczminternal_GHCziInternalziTopHandler_flushStdHandles_closure +ghczminternal_GHCziInternalziTopHandler_runIO_closure ghczminternal_GHCziInternalziTopHandler_runMainIO_closure +ghczminternal_GHCziInternalziTopHandler_runNonIO_closure +ghczminternal_GHCziInternalziTuple_Z0T_closure ghczminternal_GHCziInternalziTypes_Czh_con_info -ghczminternal_GHCziInternalziTypes_Izh_con_info -ghczminternal_GHCziInternalziTypes_Fzh_con_info ghczminternal_GHCziInternalziTypes_Dzh_con_info +ghczminternal_GHCziInternalziTypes_False_closure +ghczminternal_GHCziInternalziTypes_Fzh_con_info +ghczminternal_GHCziInternalziTypes_Izh_con_info +ghczminternal_GHCziInternalziTypes_True_closure ghczminternal_GHCziInternalziTypes_Wzh_con_info -ghczminternal_GHCziInternalziPtr_Ptr_con_info -ghczminternal_GHCziInternalziPtr_FunPtr_con_info -ghczminternal_GHCziInternalziInt_I8zh_con_info -ghczminternal_GHCziInternalziInt_I16zh_con_info -ghczminternal_GHCziInternalziInt_I32zh_con_info -ghczminternal_GHCziInternalziInt_I64zh_con_info -ghczminternal_GHCziInternalziWord_W8zh_con_info +ghczminternal_GHCziInternalziWeakziFinalizze_runFinalizzerBatch_closure ghczminternal_GHCziInternalziWord_W16zh_con_info ghczminternal_GHCziInternalziWord_W32zh_con_info ghczminternal_GHCziInternalziWord_W64zh_con_info -ghczminternal_GHCziInternalziStable_StablePtr_con_info -hs_atomic_add8 +ghczminternal_GHCziInternalziWord_W8zh_con_info hs_atomic_add16 hs_atomic_add32 hs_atomic_add64 -hs_atomic_sub8 -hs_atomic_sub16 -hs_atomic_sub32 -hs_atomic_sub64 -hs_atomic_and8 +hs_atomic_add8 hs_atomic_and16 hs_atomic_and32 hs_atomic_and64 -hs_atomic_nand8 +hs_atomic_and8 hs_atomic_nand16 hs_atomic_nand32 hs_atomic_nand64 -hs_atomic_or8 +hs_atomic_nand8 hs_atomic_or16 hs_atomic_or32 hs_atomic_or64 -hs_atomic_xor8 +hs_atomic_or8 +hs_atomic_sub16 +hs_atomic_sub32 +hs_atomic_sub64 +hs_atomic_sub8 hs_atomic_xor16 hs_atomic_xor32 hs_atomic_xor64 -hs_cmpxchg8 -hs_cmpxchg16 -hs_cmpxchg32 -hs_cmpxchg64 -hs_xchg8 -hs_xchg16 -hs_xchg32 -hs_xchg64 -hs_atomicread8 +hs_atomic_xor8 hs_atomicread16 hs_atomicread32 hs_atomicread64 -hs_atomicwrite8 +hs_atomicread8 hs_atomicwrite16 hs_atomicwrite32 hs_atomicwrite64 -ghczminternal_GHCziInternalziStackziCloneStack_StackSnapshot_closure +hs_atomicwrite8 +hs_cmpxchg16 +hs_cmpxchg32 +hs_cmpxchg64 +hs_cmpxchg8 +hs_xchg16 +hs_xchg32 +hs_xchg64 +hs_xchg8 diff --git a/rts/rts.buildinfo.in b/rts/rts.buildinfo.in index 4e8c9e540ab9..3dc6a2dd44d1 100644 --- a/rts/rts.buildinfo.in +++ b/rts/rts.buildinfo.in @@ -1,3 +1 @@ --- External symbols referenced by the RTS -ld-options: -#include "external-symbols.flags" +ld-options: @LDFLAGS@ diff --git a/rts/rts.cabal b/rts/rts.cabal index a662e67d79a8..5f0402efd8be 100644 --- a/rts/rts.cabal +++ b/rts/rts.cabal @@ -16,7 +16,7 @@ extra-source-files: config.guess config.sub configure.ac - external-symbols.list.in + external-symbols.list rts.buildinfo.in linker/ELFRelocs/AArch64.def linker/ELFRelocs/ARM.def From c1fc7611199a5c5aa59f09f14ed9d942a0137b09 Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Thu, 27 Feb 2025 08:28:37 +0800 Subject: [PATCH 23/84] refactor(rts/configure.ac): simplify config variables Note: this introduces some symbols in ghcautoconf.h --- rts/HeapStackCheck.cmm | 2 +- rts/RtsSymbols.c | 2 +- rts/RtsUtils.c | 4 +-- rts/TraverseHeapTest.c | 2 +- rts/configure.ac | 31 ++++++++++++++++++----- rts/include/Cmm.h | 6 ++--- rts/include/ghcautoconf.h.in | 33 +++++++++++++++++++++++++ rts/include/rts/storage/ClosureMacros.h | 2 +- rts/include/rts/storage/InfoTables.h | 30 +++++++++++----------- rts/include/stg/MiscClosures.h | 2 +- rts/rts.buildinfo.in | 1 + 11 files changed, 84 insertions(+), 31 deletions(-) diff --git a/rts/HeapStackCheck.cmm b/rts/HeapStackCheck.cmm index 5461f15c7a7d..8c0f407967f9 100644 --- a/rts/HeapStackCheck.cmm +++ b/rts/HeapStackCheck.cmm @@ -458,7 +458,7 @@ __stg_gc_fun /* explicit stack */ size = BITMAP_SIZE(StgFunInfoExtra_bitmap(info)); } else { if (type == ARG_GEN_BIG) { -#if defined(TABLES_NEXT_TO_CODE) +#if TABLES_NEXT_TO_CODE // bitmap field holds an offset size = StgLargeBitmap_size( TO_W_(StgFunInfoExtraRev_bitmap_offset(info)) diff --git a/rts/RtsSymbols.c b/rts/RtsSymbols.c index d678a1f761f3..981f0aba73af 100644 --- a/rts/RtsSymbols.c +++ b/rts/RtsSymbols.c @@ -279,7 +279,7 @@ extern char **environ; SymE_NeedsDataProto(ffi_type_uint8) \ SymE_NeedsDataProto(ffi_type_pointer) -#if defined(TABLES_NEXT_TO_CODE) +#if TABLES_NEXT_TO_CODE #define RTS_RET_SYMBOLS /* nothing */ #else #define RTS_RET_SYMBOLS \ diff --git a/rts/RtsUtils.c b/rts/RtsUtils.c index 7640d7cca817..c5705f292f10 100644 --- a/rts/RtsUtils.c +++ b/rts/RtsUtils.c @@ -378,8 +378,8 @@ void printRtsInfo(const RtsConfig rts_config) { // say the target is , unless we are talking about the host // platform of the compiler / ABI used by a compiler plugin. This is *not* // that, so I think a rename is in order to avoid confusion. - mkRtsInfoPair("Compiler unregisterised", GhcUnregisterised); - mkRtsInfoPair("Tables next to code", TablesNextToCode); + mkRtsInfoPair("Compiler unregisterised", GhcUnregisterised ? "yes" : "no"); + mkRtsInfoPair("Tables next to code", TABLES_NEXT_TO_CODE ? "yes" : "no"); mkRtsInfoPair("Flag -with-rtsopts", /* See #15261 */ rts_config.rts_opts != NULL ? rts_config.rts_opts : ""); selectIOManager(); /* resolve the io-manager, accounting for flags */ diff --git a/rts/TraverseHeapTest.c b/rts/TraverseHeapTest.c index fe92bbdc5be4..518edc21b781 100644 --- a/rts/TraverseHeapTest.c +++ b/rts/TraverseHeapTest.c @@ -26,7 +26,7 @@ struct node { }; // See INFO_PTR_TO_STRUCT in ClosureMacros.h -#if defined(TABLES_NEXT_TO_CODE) +#if TABLES_NEXT_TO_CODE #define INFO(ptr) ((StgInfoTable *)ptr + 1) #else #define INFO(ptr) ((StgInfoTable *)ptr) diff --git a/rts/configure.ac b/rts/configure.ac index fa733efda21e..05be3c4a1f45 100644 --- a/rts/configure.ac +++ b/rts/configure.ac @@ -56,6 +56,16 @@ if test -z "$GHC_VERSION"; then AC_MSG_ERROR([The specified compiler ($GHC) does not appear to be a valid GHC.]) fi +dnl NOTE: This is relative to what is being used to compile the rts, +dnl even if this is a new rts to be included in a new compiler version. +dnl tl;dr: this is going to be wrong in stage1 but will be correct in stage2. +AC_DEFINE_UNQUOTED([ProjectVersion], ["$GHC_VERSION"], [Version of GHC used to build this RTS]) + +dnl ** Rts way +dnl -------------------------------------------------------------- + +dnl FIXME Only used for display? +AC_DEFINE_UNQUOTED([RtsWay], ["FIXME"], [RtsWay]) AC_ARG_ENABLE(asserts-all-ways, [AS_HELP_STRING([--enable-asserts-all-ways], @@ -76,9 +86,7 @@ AC_CANONICAL_HOST dnl ** Do a build with tables next to code? dnl -------------------------------------------------------------- -AS_IF( - [test "$CABAL_FLAG_tables_next_to_code" = 1], - [AC_DEFINE([TABLES_NEXT_TO_CODE], [1], [Define to 1 if info tables are laid out next to code])]) +AC_DEFINE_UNQUOTED([TABLES_NEXT_TO_CODE], [$CABAL_FLAG_tables_next_to_code], [Define to 1 if info tables are laid out next to code]) dnl detect compiler (prefer gcc over clang) and set $CC (unless CC already set), dnl later CC is copied to CC_STAGE{1,2,3} @@ -105,10 +113,20 @@ GHC_CONVERT_PLATFORM_PARTS([build], [Build]) FPTOOLS_SET_PLATFORM_VARS([build],[Build]) FPTOOLS_SET_HASKELL_PLATFORM_VARS([Build]) +AC_DEFINE_UNQUOTED([BuildPlatform],["$BuildPlatform_CPP"],[BuildPlatform]) +AC_DEFINE_UNQUOTED([BuildArch],["$BuildArch_CPP"],[BuildArch]) +AC_DEFINE_UNQUOTED([BuildOS],["$BuildOS_CPP"],[BuildOS]) +AC_DEFINE_UNQUOTED([BuildVendor],["$BuildVendor_CPP"],[BuildVendor]) + GHC_CONVERT_PLATFORM_PARTS([host], [Host]) FPTOOLS_SET_PLATFORM_VARS([host], [Host]) FPTOOLS_SET_HASKELL_PLATFORM_VARS([Host]) +AC_DEFINE_UNQUOTED([HostPlatform],["$HostPlatform"],[HostPlatform]) +AC_DEFINE_UNQUOTED([HostArch],["$HostArch_CPP"],[HostArch]) +AC_DEFINE_UNQUOTED([HostOS],["$HostOS_CPP"],[HostOS]) +AC_DEFINE_UNQUOTED([HostVendor],["$HostVendor_CPP"],[HostVendor]) + GHC_SUBSECTIONS_VIA_SYMBOLS AS_IF([test x"${TargetHasSubsectionsViaSymbols}" = x"YES"], [AC_DEFINE([HAVE_SUBSECTIONS_VIA_SYMBOLS],[1], @@ -170,7 +188,6 @@ FP_CHECK_SIZEOF_AND_ALIGNMENT(uint32_t) FP_CHECK_SIZEOF_AND_ALIGNMENT(int64_t) FP_CHECK_SIZEOF_AND_ALIGNMENT(uint64_t) - FP_CHECK_FUNC([WinExec], [@%:@include ], [WinExec("",0)]) @@ -377,9 +394,11 @@ AS_IF( [test "$CABAL_FLAG_libnuma" = 1], [AC_CHECK_HEADERS([numa.h numaif.h])]) -dnl ** Do an unregisterised build? +dnl ** Is this an unregisterised build? dnl -------------------------------------------------------------- -AC_SUBST(CABAL_FLAG_unregisterised) + +dnl Only used for printing information +AC_DEFINE_UNQUOTED([GhcUnregisterised], [$CABAL_FLAG_unregisterised], [Is this an unregistered build?]) dnl ** I/O managers dnl -------------------------------------------------------------- diff --git a/rts/include/Cmm.h b/rts/include/Cmm.h index 2f42889bdea8..8f9468ac7dd5 100644 --- a/rts/include/Cmm.h +++ b/rts/include/Cmm.h @@ -121,13 +121,13 @@ name : bits8[] str; \ } \ -#if defined(TABLES_NEXT_TO_CODE) +#if TABLES_NEXT_TO_CODE #define RET_LBL(f) f##_info #else #define RET_LBL(f) f##_ret #endif -#if defined(TABLES_NEXT_TO_CODE) +#if TABLES_NEXT_TO_CODE #define ENTRY_LBL(f) f##_info #else #define ENTRY_LBL(f) f##_entry @@ -637,7 +637,7 @@ * depending on TABLES_NEXT_TO_CODE. So we define field access * macros which use the appropriate version here: */ -#if defined(TABLES_NEXT_TO_CODE) +#if TABLES_NEXT_TO_CODE /* * when TABLES_NEXT_TO_CODE, slow_apply is stored as an offset * instead of the normal pointer. diff --git a/rts/include/ghcautoconf.h.in b/rts/include/ghcautoconf.h.in index 4195344b866f..c5c9e50380d6 100644 --- a/rts/include/ghcautoconf.h.in +++ b/rts/include/ghcautoconf.h.in @@ -66,6 +66,18 @@ /* The alignment of a `void *'. */ #undef ALIGNMENT_VOID_P +/* BuildArch */ +#undef BuildArch + +/* BuildOS */ +#undef BuildOS + +/* BuildPlatform */ +#undef BuildPlatform + +/* BuildVendor */ +#undef BuildVendor + /* Define (to 1) if C compiler has an LLVM back end */ #undef CC_LLVM_BACKEND @@ -79,6 +91,9 @@ significant byte first */ #undef FLOAT_WORDS_BIGENDIAN +/* Is this an unregistered build? */ +#undef GhcUnregisterised + /* Has musttail */ #undef HAS_MUSTTAIL @@ -380,6 +395,18 @@ /* Define to 1 if 'vfork' works. */ #undef HAVE_WORKING_VFORK +/* HostArch */ +#undef HostArch + +/* HostOS */ +#undef HostOS + +/* HostPlatform */ +#undef HostPlatform + +/* HostVendor */ +#undef HostVendor + /* Define to 1 if the mio I/O manager should be built */ #undef IOMGR_BUILD_MIO @@ -435,9 +462,15 @@ /* Define to the version of this package. */ #undef PACKAGE_VERSION +/* Version of GHC used to build this RTS */ +#undef ProjectVersion + /* Use mmap in the runtime linker */ #undef RTS_LINKER_USE_MMAP +/* RtsWay */ +#undef RtsWay + /* The size of 'char', as computed by sizeof. */ #undef SIZEOF_CHAR diff --git a/rts/include/rts/storage/ClosureMacros.h b/rts/include/rts/storage/ClosureMacros.h index 1dcba95dd9a5..3f1785bb96ef 100644 --- a/rts/include/rts/storage/ClosureMacros.h +++ b/rts/include/rts/storage/ClosureMacros.h @@ -74,7 +74,7 @@ EXTERN_INLINE StgRetInfoTable *itbl_to_ret_itbl (const StgInfoTable *i); EXTERN_INLINE StgThunkInfoTable *itbl_to_thunk_itbl (const StgInfoTable *i); EXTERN_INLINE StgConInfoTable *itbl_to_con_itbl (const StgInfoTable *i); -#if defined(TABLES_NEXT_TO_CODE) +#if TABLES_NEXT_TO_CODE NO_WARN(-Warray-bounds, EXTERN_INLINE StgInfoTable *INFO_PTR_TO_STRUCT(const StgInfoTable *info) {return (StgInfoTable *)info - 1;} EXTERN_INLINE StgRetInfoTable *RET_INFO_PTR_TO_STRUCT(const StgInfoTable *info) {return (StgRetInfoTable *)info - 1;} diff --git a/rts/include/rts/storage/InfoTables.h b/rts/include/rts/storage/InfoTables.h index 4f4ad6c1635b..3681a53448ba 100644 --- a/rts/include/rts/storage/InfoTables.h +++ b/rts/include/rts/storage/InfoTables.h @@ -39,7 +39,7 @@ -------------------------------------------------------------------------- */ typedef struct { -#if !defined(TABLES_NEXT_TO_CODE) +#if !TABLES_NEXT_TO_CODE char *closure_type; char *closure_desc; #else @@ -145,7 +145,7 @@ typedef union { StgWord bitmap; /* word-sized bit pattern describing */ /* a stack frame: see below */ -#if !defined(TABLES_NEXT_TO_CODE) +#if !TABLES_NEXT_TO_CODE StgLargeBitmap* large_bitmap; /* pointer to large bitmap structure */ #else OFFSET_FIELD(large_bitmap_offset); /* offset from info table to large bitmap structure */ @@ -161,12 +161,12 @@ typedef union { // Note [SRTs] in GHC.Cmm.Info.Build. // // Specifically we define one of the following: -#if WORD_SIZE_IN_BITS == 64 && defined(TABLES_NEXT_TO_CODE) +#if WORD_SIZE_IN_BITS == 64 && TABLES_NEXT_TO_CODE // On 64-bit platforms using the small memory model we can fit a pointer // offset in half a word, so put the SRT offset in the info->srt field // directly. #define USE_INLINE_SRT_FIELD -#elif defined(TABLES_NEXT_TO_CODE) +#elif TABLES_NEXT_TO_CODE // Otherwise use the srt_offset field... #define USE_SRT_OFFSET #else @@ -188,7 +188,7 @@ typedef StgHalfWord StgSRTField; */ typedef struct StgInfoTable_ { -#if !defined(TABLES_NEXT_TO_CODE) +#if !TABLES_NEXT_TO_CODE StgFunPtr entry; /* pointer to the entry code */ #endif @@ -209,7 +209,7 @@ typedef struct StgInfoTable_ { - non-zero if there is an SRT, offset is in srt_offset */ -#if defined(TABLES_NEXT_TO_CODE) +#if TABLES_NEXT_TO_CODE StgCode code[]; #endif } *StgInfoTablePtr; // StgInfoTable defined in rts/Types.h @@ -266,7 +266,7 @@ typedef struct StgFunInfoExtraFwd_ { } StgFunInfoExtraFwd; typedef struct { -#if defined(TABLES_NEXT_TO_CODE) +#if TABLES_NEXT_TO_CODE StgFunInfoExtraRev f; StgInfoTable i; #else @@ -325,18 +325,18 @@ typedef struct StgThunkInfoTable_ { -------------------------------------------------------------------------- */ typedef struct StgConInfoTable_ { -#if !defined(TABLES_NEXT_TO_CODE) +#if !TABLES_NEXT_TO_CODE StgInfoTable i; #endif -#if defined(TABLES_NEXT_TO_CODE) +#if TABLES_NEXT_TO_CODE OFFSET_FIELD(con_desc); // the name of the data constructor // as: Package:Module.Name #else char *con_desc; #endif -#if defined(TABLES_NEXT_TO_CODE) +#if TABLES_NEXT_TO_CODE StgInfoTable i; #endif } StgConInfoTable; @@ -364,7 +364,7 @@ typedef struct StgConInfoTable_ { * GET_CON_DESC(info) * info must be a StgConInfoTable*. */ -#if defined(TABLES_NEXT_TO_CODE) +#if TABLES_NEXT_TO_CODE #define GET_CON_DESC(info) \ ((const char *)((StgWord)((info)+1) + ((info)->con_desc))) #else @@ -385,14 +385,14 @@ typedef struct StgConInfoTable_ { #define GET_FUN_SRT(info) ((info)->f.srt) #endif -#if defined(TABLES_NEXT_TO_CODE) +#if TABLES_NEXT_TO_CODE #define GET_LARGE_BITMAP(info) ((StgLargeBitmap*) (((StgWord) ((info)+1)) \ + (info)->layout.large_bitmap_offset)) #else #define GET_LARGE_BITMAP(info) ((info)->layout.large_bitmap) #endif -#if defined(TABLES_NEXT_TO_CODE) +#if TABLES_NEXT_TO_CODE #define GET_FUN_LARGE_BITMAP(info) ((StgLargeBitmap*) (((StgWord) ((info)+1)) \ + (info)->f.b.bitmap_offset)) #else @@ -402,12 +402,12 @@ typedef struct StgConInfoTable_ { /* * GET_PROF_TYPE, GET_PROF_DESC */ -#if defined(TABLES_NEXT_TO_CODE) +#if TABLES_NEXT_TO_CODE #define GET_PROF_TYPE(info) ((char *)((StgWord)((info)+1) + (info->prof.closure_type_off))) #else #define GET_PROF_TYPE(info) ((info)->prof.closure_type) #endif -#if defined(TABLES_NEXT_TO_CODE) +#if TABLES_NEXT_TO_CODE #define GET_PROF_DESC(info) ((char *)((StgWord)((info)+1) + (info->prof.closure_desc_off))) #else #define GET_PROF_DESC(info) ((info)->prof.closure_desc) diff --git a/rts/include/stg/MiscClosures.h b/rts/include/stg/MiscClosures.h index 799b1ecb2c4b..b02cf9dfba6d 100644 --- a/rts/include/stg/MiscClosures.h +++ b/rts/include/stg/MiscClosures.h @@ -35,7 +35,7 @@ # define RTS_FUN_DECL(f) extern DLL_IMPORT_RTS StgFunPtr f(void) #endif -#if defined(TABLES_NEXT_TO_CODE) +#if TABLES_NEXT_TO_CODE # define RTS_RET(f) RTS_INFO(f##_info) # define RTS_ENTRY(f) RTS_INFO(f##_info) # define RTS_FUN(f) RTS_FUN_INFO(f##_info) diff --git a/rts/rts.buildinfo.in b/rts/rts.buildinfo.in index 3dc6a2dd44d1..6128f5eb11f4 100644 --- a/rts/rts.buildinfo.in +++ b/rts/rts.buildinfo.in @@ -1 +1,2 @@ ld-options: @LDFLAGS@ +cc-options: @CPPFLAGS@ @CFLAGS@ From 567672b29802e39f9517340b3ccd9b582f26ca4f Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Thu, 27 Feb 2025 10:07:30 +0800 Subject: [PATCH 24/84] refactor(rts/configure.ac): checking for rts.cabal is more reliable --- rts/configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rts/configure.ac b/rts/configure.ac index 05be3c4a1f45..dd14dcc5701d 100644 --- a/rts/configure.ac +++ b/rts/configure.ac @@ -10,8 +10,8 @@ AC_INIT([GHC run-time system], [1.0.2], [libraries@haskell.org], [rts]) AC_CONFIG_MACRO_DIRS([../m4]) -# Safety check: Ensure that we are in the correct source directory. -AC_CONFIG_SRCDIR([include/rts/Constants.h]) +# Ensure that we are in the correct source directory. +AC_CONFIG_SRCDIR([rts.cabal]) dnl * We require autoconf version 2.69 due to dnl https://bugs.ruby-lang.org/issues/8179. Also see #14910. From 0cc3ba2ac6ae05ea00af0e04da1bc5e8d2181740 Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Thu, 20 Feb 2025 18:01:41 +0800 Subject: [PATCH 25/84] chore: re-enable shared executables --- cabal.project.stage1 | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/cabal.project.stage1 b/cabal.project.stage1 index f008ebe25873..42df158554c3 100644 --- a/cabal.project.stage1 +++ b/cabal.project.stage1 @@ -30,16 +30,18 @@ packages: ./utils/ghc-toolchain ./utils/ghc-toolchain/exe -benchmark: False +benchmarks: False tests: False +profiling: False + allow-boot-library-installs: True package * library-vanilla: True - shared: False - executable-profiling: False - executable-dynamic: False - executable-static: True + shared: True + -- executable-profiling: False + -- executable-dynamic: False + -- executable-static: True package ghc-boot-th flags: +bootstrap From c66ef863e6211413bd11c903f9a9084c44f6cada Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Thu, 27 Feb 2025 10:46:31 +0800 Subject: [PATCH 26/84] chore: normalise .gitmodules --- .gitmodules | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 9c72ac9d8846..349bb6cd7e96 100644 --- a/.gitmodules +++ b/.gitmodules @@ -103,15 +103,20 @@ [submodule "gmp-tarballs"] path = libraries/ghc-internal/gmp/gmp-tarballs url = https://gitlab.haskell.org/ghc/gmp-tarballs.git + ignore = untracked [submodule "libraries/exceptions"] path = libraries/exceptions url = https://gitlab.haskell.org/ghc/packages/exceptions.git + ignore = untracked [submodule "utils/hpc"] path = utils/hpc url = https://gitlab.haskell.org/hpc/hpc-bin.git + ignore = untracked [submodule "libraries/os-string"] path = libraries/os-string - url = https://gitlab.haskell.org/ghc/packages/os-string + url = https://gitlab.haskell.org/ghc/packages/os-string.git + ignore = untracked [submodule "libraries/file-io"] path = libraries/file-io url = https://gitlab.haskell.org/ghc/packages/file-io.git + ignore = untracked From 20ad77c57cf2ac6283599e0e520dd4520d81646d Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Fri, 28 Feb 2025 17:32:05 +0800 Subject: [PATCH 27/84] refactor(rts): generate derived constants in rts/configure.ac Co-Authored-By: Moritz Angermann --- libraries/Cabal | 2 +- rts/config.guess | 1812 ++++++++++++++++++++++++++++++++++++++++++ rts/config.sub | 1971 ++++++++++++++++++++++++++++++++++++++++++++++ rts/configure.ac | 64 +- rts/rts.cabal | 46 +- 5 files changed, 3872 insertions(+), 23 deletions(-) create mode 100755 rts/config.guess create mode 100755 rts/config.sub diff --git a/libraries/Cabal b/libraries/Cabal index 98242d4d81e3..513461732740 160000 --- a/libraries/Cabal +++ b/libraries/Cabal @@ -1 +1 @@ -Subproject commit 98242d4d81e38dd591e212f3a9df7f04215ad1c7 +Subproject commit 51346173274055d3e4085eb1a7162837d22b4845 diff --git a/rts/config.guess b/rts/config.guess new file mode 100755 index 000000000000..f9c22a043af4 --- /dev/null +++ b/rts/config.guess @@ -0,0 +1,1812 @@ +#!/usr/bin/sh +# Attempt to guess a canonical system name. +# Copyright 1992-2024 Free Software Foundation, Inc. + +# shellcheck disable=SC2006,SC2268 # see below for rationale + +timestamp='2024-01-01' + +# This file is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see . +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that +# program. This Exception is an additional permission under section 7 +# of the GNU General Public License, version 3 ("GPLv3"). +# +# Originally written by Per Bothner; maintained since 2000 by Ben Elliston. +# +# You can get the latest version of this script from: +# https://git.savannah.gnu.org/cgit/config.git/plain/config.guess +# +# Please send patches to . + + +# The "shellcheck disable" line above the timestamp inhibits complaints +# about features and limitations of the classic Bourne shell that were +# superseded or lifted in POSIX. However, this script identifies a wide +# variety of pre-POSIX systems that do not have POSIX shells at all, and +# even some reasonably current systems (Solaris 10 as case-in-point) still +# have a pre-POSIX /bin/sh. + + +me=`echo "$0" | sed -e 's,.*/,,'` + +usage="\ +Usage: $0 [OPTION] + +Output the configuration name of the system '$me' is run on. + +Options: + -h, --help print this help, then exit + -t, --time-stamp print date of last modification, then exit + -v, --version print version number, then exit + +Report bugs and patches to ." + +version="\ +GNU config.guess ($timestamp) + +Originally written by Per Bothner. +Copyright 1992-2024 Free Software Foundation, Inc. + +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + +help=" +Try '$me --help' for more information." + +# Parse command line +while test $# -gt 0 ; do + case $1 in + --time-stamp | --time* | -t ) + echo "$timestamp" ; exit ;; + --version | -v ) + echo "$version" ; exit ;; + --help | --h* | -h ) + echo "$usage"; exit ;; + -- ) # Stop option processing + shift; break ;; + - ) # Use stdin as input. + break ;; + -* ) + echo "$me: invalid option $1$help" >&2 + exit 1 ;; + * ) + break ;; + esac +done + +if test $# != 0; then + echo "$me: too many arguments$help" >&2 + exit 1 +fi + +# Just in case it came from the environment. +GUESS= + +# CC_FOR_BUILD -- compiler used by this script. Note that the use of a +# compiler to aid in system detection is discouraged as it requires +# temporary files to be created and, as you can see below, it is a +# headache to deal with in a portable fashion. + +# Historically, 'CC_FOR_BUILD' used to be named 'HOST_CC'. We still +# use 'HOST_CC' if defined, but it is deprecated. + +# Portable tmp directory creation inspired by the Autoconf team. + +tmp= +# shellcheck disable=SC2172 +trap 'test -z "$tmp" || rm -fr "$tmp"' 0 1 2 13 15 + +set_cc_for_build() { + # prevent multiple calls if $tmp is already set + test "$tmp" && return 0 + : "${TMPDIR=/tmp}" + # shellcheck disable=SC2039,SC3028 + { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || + { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir "$tmp" 2>/dev/null) ; } || + { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir "$tmp" 2>/dev/null) && echo "Warning: creating insecure temp directory" >&2 ; } || + { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } + dummy=$tmp/dummy + case ${CC_FOR_BUILD-},${HOST_CC-},${CC-} in + ,,) echo "int x;" > "$dummy.c" + for driver in cc gcc c89 c99 ; do + if ($driver -c -o "$dummy.o" "$dummy.c") >/dev/null 2>&1 ; then + CC_FOR_BUILD=$driver + break + fi + done + if test x"$CC_FOR_BUILD" = x ; then + CC_FOR_BUILD=no_compiler_found + fi + ;; + ,,*) CC_FOR_BUILD=$CC ;; + ,*,*) CC_FOR_BUILD=$HOST_CC ;; + esac +} + +# This is needed to find uname on a Pyramid OSx when run in the BSD universe. +# (ghazi@noc.rutgers.edu 1994-08-24) +if test -f /.attbin/uname ; then + PATH=$PATH:/.attbin ; export PATH +fi + +UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown +UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown +UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown +UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown + +case $UNAME_SYSTEM in +Linux|GNU|GNU/*) + LIBC=unknown + + set_cc_for_build + cat <<-EOF > "$dummy.c" + #if defined(__ANDROID__) + LIBC=android + #else + #include + #if defined(__UCLIBC__) + LIBC=uclibc + #elif defined(__dietlibc__) + LIBC=dietlibc + #elif defined(__GLIBC__) + LIBC=gnu + #elif defined(__LLVM_LIBC__) + LIBC=llvm + #else + #include + /* First heuristic to detect musl libc. */ + #ifdef __DEFINED_va_list + LIBC=musl + #endif + #endif + #endif + EOF + cc_set_libc=`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^LIBC' | sed 's, ,,g'` + eval "$cc_set_libc" + + # Second heuristic to detect musl libc. + if [ "$LIBC" = unknown ] && + command -v ldd >/dev/null && + ldd --version 2>&1 | grep -q ^musl; then + LIBC=musl + fi + + # If the system lacks a compiler, then just pick glibc. + # We could probably try harder. + if [ "$LIBC" = unknown ]; then + LIBC=gnu + fi + ;; +esac + +# Note: order is significant - the case branches are not exclusive. + +case $UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION in + *:NetBSD:*:*) + # NetBSD (nbsd) targets should (where applicable) match one or + # more of the tuples: *-*-netbsdelf*, *-*-netbsdaout*, + # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently + # switched to ELF, *-*-netbsd* would select the old + # object file format. This provides both forward + # compatibility and a consistent mechanism for selecting the + # object file format. + # + # Note: NetBSD doesn't particularly care about the vendor + # portion of the name. We always set it to "unknown". + UNAME_MACHINE_ARCH=`(uname -p 2>/dev/null || \ + /sbin/sysctl -n hw.machine_arch 2>/dev/null || \ + /usr/sbin/sysctl -n hw.machine_arch 2>/dev/null || \ + echo unknown)` + case $UNAME_MACHINE_ARCH in + aarch64eb) machine=aarch64_be-unknown ;; + armeb) machine=armeb-unknown ;; + arm*) machine=arm-unknown ;; + sh3el) machine=shl-unknown ;; + sh3eb) machine=sh-unknown ;; + sh5el) machine=sh5le-unknown ;; + earmv*) + arch=`echo "$UNAME_MACHINE_ARCH" | sed -e 's,^e\(armv[0-9]\).*$,\1,'` + endian=`echo "$UNAME_MACHINE_ARCH" | sed -ne 's,^.*\(eb\)$,\1,p'` + machine=${arch}${endian}-unknown + ;; + *) machine=$UNAME_MACHINE_ARCH-unknown ;; + esac + # The Operating System including object format, if it has switched + # to ELF recently (or will in the future) and ABI. + case $UNAME_MACHINE_ARCH in + earm*) + os=netbsdelf + ;; + arm*|i386|m68k|ns32k|sh3*|sparc|vax) + set_cc_for_build + if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep -q __ELF__ + then + # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout). + # Return netbsd for either. FIX? + os=netbsd + else + os=netbsdelf + fi + ;; + *) + os=netbsd + ;; + esac + # Determine ABI tags. + case $UNAME_MACHINE_ARCH in + earm*) + expr='s/^earmv[0-9]/-eabi/;s/eb$//' + abi=`echo "$UNAME_MACHINE_ARCH" | sed -e "$expr"` + ;; + esac + # The OS release + # Debian GNU/NetBSD machines have a different userland, and + # thus, need a distinct triplet. However, they do not need + # kernel version information, so it can be replaced with a + # suitable tag, in the style of linux-gnu. + case $UNAME_VERSION in + Debian*) + release='-gnu' + ;; + *) + release=`echo "$UNAME_RELEASE" | sed -e 's/[-_].*//' | cut -d. -f1,2` + ;; + esac + # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: + # contains redundant information, the shorter form: + # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. + GUESS=$machine-${os}${release}${abi-} + ;; + *:Bitrig:*:*) + UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'` + GUESS=$UNAME_MACHINE_ARCH-unknown-bitrig$UNAME_RELEASE + ;; + *:OpenBSD:*:*) + UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` + GUESS=$UNAME_MACHINE_ARCH-unknown-openbsd$UNAME_RELEASE + ;; + *:SecBSD:*:*) + UNAME_MACHINE_ARCH=`arch | sed 's/SecBSD.//'` + GUESS=$UNAME_MACHINE_ARCH-unknown-secbsd$UNAME_RELEASE + ;; + *:LibertyBSD:*:*) + UNAME_MACHINE_ARCH=`arch | sed 's/^.*BSD\.//'` + GUESS=$UNAME_MACHINE_ARCH-unknown-libertybsd$UNAME_RELEASE + ;; + *:MidnightBSD:*:*) + GUESS=$UNAME_MACHINE-unknown-midnightbsd$UNAME_RELEASE + ;; + *:ekkoBSD:*:*) + GUESS=$UNAME_MACHINE-unknown-ekkobsd$UNAME_RELEASE + ;; + *:SolidBSD:*:*) + GUESS=$UNAME_MACHINE-unknown-solidbsd$UNAME_RELEASE + ;; + *:OS108:*:*) + GUESS=$UNAME_MACHINE-unknown-os108_$UNAME_RELEASE + ;; + macppc:MirBSD:*:*) + GUESS=powerpc-unknown-mirbsd$UNAME_RELEASE + ;; + *:MirBSD:*:*) + GUESS=$UNAME_MACHINE-unknown-mirbsd$UNAME_RELEASE + ;; + *:Sortix:*:*) + GUESS=$UNAME_MACHINE-unknown-sortix + ;; + *:Twizzler:*:*) + GUESS=$UNAME_MACHINE-unknown-twizzler + ;; + *:Redox:*:*) + GUESS=$UNAME_MACHINE-unknown-redox + ;; + mips:OSF1:*.*) + GUESS=mips-dec-osf1 + ;; + alpha:OSF1:*:*) + # Reset EXIT trap before exiting to avoid spurious non-zero exit code. + trap '' 0 + case $UNAME_RELEASE in + *4.0) + UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` + ;; + *5.*) + UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` + ;; + esac + # According to Compaq, /usr/sbin/psrinfo has been available on + # OSF/1 and Tru64 systems produced since 1995. I hope that + # covers most systems running today. This code pipes the CPU + # types through head -n 1, so we only detect the type of CPU 0. + ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1` + case $ALPHA_CPU_TYPE in + "EV4 (21064)") + UNAME_MACHINE=alpha ;; + "EV4.5 (21064)") + UNAME_MACHINE=alpha ;; + "LCA4 (21066/21068)") + UNAME_MACHINE=alpha ;; + "EV5 (21164)") + UNAME_MACHINE=alphaev5 ;; + "EV5.6 (21164A)") + UNAME_MACHINE=alphaev56 ;; + "EV5.6 (21164PC)") + UNAME_MACHINE=alphapca56 ;; + "EV5.7 (21164PC)") + UNAME_MACHINE=alphapca57 ;; + "EV6 (21264)") + UNAME_MACHINE=alphaev6 ;; + "EV6.7 (21264A)") + UNAME_MACHINE=alphaev67 ;; + "EV6.8CB (21264C)") + UNAME_MACHINE=alphaev68 ;; + "EV6.8AL (21264B)") + UNAME_MACHINE=alphaev68 ;; + "EV6.8CX (21264D)") + UNAME_MACHINE=alphaev68 ;; + "EV6.9A (21264/EV69A)") + UNAME_MACHINE=alphaev69 ;; + "EV7 (21364)") + UNAME_MACHINE=alphaev7 ;; + "EV7.9 (21364A)") + UNAME_MACHINE=alphaev79 ;; + esac + # A Pn.n version is a patched version. + # A Vn.n version is a released version. + # A Tn.n version is a released field test version. + # A Xn.n version is an unreleased experimental baselevel. + # 1.2 uses "1.2" for uname -r. + OSF_REL=`echo "$UNAME_RELEASE" | sed -e 's/^[PVTX]//' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz` + GUESS=$UNAME_MACHINE-dec-osf$OSF_REL + ;; + Amiga*:UNIX_System_V:4.0:*) + GUESS=m68k-unknown-sysv4 + ;; + *:[Aa]miga[Oo][Ss]:*:*) + GUESS=$UNAME_MACHINE-unknown-amigaos + ;; + *:[Mm]orph[Oo][Ss]:*:*) + GUESS=$UNAME_MACHINE-unknown-morphos + ;; + *:OS/390:*:*) + GUESS=i370-ibm-openedition + ;; + *:z/VM:*:*) + GUESS=s390-ibm-zvmoe + ;; + *:OS400:*:*) + GUESS=powerpc-ibm-os400 + ;; + arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) + GUESS=arm-acorn-riscix$UNAME_RELEASE + ;; + arm*:riscos:*:*|arm*:RISCOS:*:*) + GUESS=arm-unknown-riscos + ;; + SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) + GUESS=hppa1.1-hitachi-hiuxmpp + ;; + Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) + # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. + case `(/bin/universe) 2>/dev/null` in + att) GUESS=pyramid-pyramid-sysv3 ;; + *) GUESS=pyramid-pyramid-bsd ;; + esac + ;; + NILE*:*:*:dcosx) + GUESS=pyramid-pyramid-svr4 + ;; + DRS?6000:unix:4.0:6*) + GUESS=sparc-icl-nx6 + ;; + DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) + case `/usr/bin/uname -p` in + sparc) GUESS=sparc-icl-nx7 ;; + esac + ;; + s390x:SunOS:*:*) + SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` + GUESS=$UNAME_MACHINE-ibm-solaris2$SUN_REL + ;; + sun4H:SunOS:5.*:*) + SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` + GUESS=sparc-hal-solaris2$SUN_REL + ;; + sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) + SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` + GUESS=sparc-sun-solaris2$SUN_REL + ;; + i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*) + GUESS=i386-pc-auroraux$UNAME_RELEASE + ;; + i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*) + set_cc_for_build + SUN_ARCH=i386 + # If there is a compiler, see if it is configured for 64-bit objects. + # Note that the Sun cc does not turn __LP64__ into 1 like gcc does. + # This test works for both compilers. + if test "$CC_FOR_BUILD" != no_compiler_found; then + if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \ + (CCOPTS="" $CC_FOR_BUILD -m64 -E - 2>/dev/null) | \ + grep IS_64BIT_ARCH >/dev/null + then + SUN_ARCH=x86_64 + fi + fi + SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` + GUESS=$SUN_ARCH-pc-solaris2$SUN_REL + ;; + sun4*:SunOS:6*:*) + # According to config.sub, this is the proper way to canonicalize + # SunOS6. Hard to guess exactly what SunOS6 will be like, but + # it's likely to be more like Solaris than SunOS4. + SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` + GUESS=sparc-sun-solaris3$SUN_REL + ;; + sun4*:SunOS:*:*) + case `/usr/bin/arch -k` in + Series*|S4*) + UNAME_RELEASE=`uname -v` + ;; + esac + # Japanese Language versions have a version number like '4.1.3-JL'. + SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/-/_/'` + GUESS=sparc-sun-sunos$SUN_REL + ;; + sun3*:SunOS:*:*) + GUESS=m68k-sun-sunos$UNAME_RELEASE + ;; + sun*:*:4.2BSD:*) + UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` + test "x$UNAME_RELEASE" = x && UNAME_RELEASE=3 + case `/bin/arch` in + sun3) + GUESS=m68k-sun-sunos$UNAME_RELEASE + ;; + sun4) + GUESS=sparc-sun-sunos$UNAME_RELEASE + ;; + esac + ;; + aushp:SunOS:*:*) + GUESS=sparc-auspex-sunos$UNAME_RELEASE + ;; + # The situation for MiNT is a little confusing. The machine name + # can be virtually everything (everything which is not + # "atarist" or "atariste" at least should have a processor + # > m68000). The system name ranges from "MiNT" over "FreeMiNT" + # to the lowercase version "mint" (or "freemint"). Finally + # the system name "TOS" denotes a system which is actually not + # MiNT. But MiNT is downward compatible to TOS, so this should + # be no problem. + atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) + GUESS=m68k-atari-mint$UNAME_RELEASE + ;; + atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) + GUESS=m68k-atari-mint$UNAME_RELEASE + ;; + *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) + GUESS=m68k-atari-mint$UNAME_RELEASE + ;; + milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) + GUESS=m68k-milan-mint$UNAME_RELEASE + ;; + hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) + GUESS=m68k-hades-mint$UNAME_RELEASE + ;; + *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) + GUESS=m68k-unknown-mint$UNAME_RELEASE + ;; + m68k:machten:*:*) + GUESS=m68k-apple-machten$UNAME_RELEASE + ;; + powerpc:machten:*:*) + GUESS=powerpc-apple-machten$UNAME_RELEASE + ;; + RISC*:Mach:*:*) + GUESS=mips-dec-mach_bsd4.3 + ;; + RISC*:ULTRIX:*:*) + GUESS=mips-dec-ultrix$UNAME_RELEASE + ;; + VAX*:ULTRIX*:*:*) + GUESS=vax-dec-ultrix$UNAME_RELEASE + ;; + 2020:CLIX:*:* | 2430:CLIX:*:*) + GUESS=clipper-intergraph-clix$UNAME_RELEASE + ;; + mips:*:*:UMIPS | mips:*:*:RISCos) + set_cc_for_build + sed 's/^ //' << EOF > "$dummy.c" +#ifdef __cplusplus +#include /* for printf() prototype */ + int main (int argc, char *argv[]) { +#else + int main (argc, argv) int argc; char *argv[]; { +#endif + #if defined (host_mips) && defined (MIPSEB) + #if defined (SYSTYPE_SYSV) + printf ("mips-mips-riscos%ssysv\\n", argv[1]); exit (0); + #endif + #if defined (SYSTYPE_SVR4) + printf ("mips-mips-riscos%ssvr4\\n", argv[1]); exit (0); + #endif + #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD) + printf ("mips-mips-riscos%sbsd\\n", argv[1]); exit (0); + #endif + #endif + exit (-1); + } +EOF + $CC_FOR_BUILD -o "$dummy" "$dummy.c" && + dummyarg=`echo "$UNAME_RELEASE" | sed -n 's/\([0-9]*\).*/\1/p'` && + SYSTEM_NAME=`"$dummy" "$dummyarg"` && + { echo "$SYSTEM_NAME"; exit; } + GUESS=mips-mips-riscos$UNAME_RELEASE + ;; + Motorola:PowerMAX_OS:*:*) + GUESS=powerpc-motorola-powermax + ;; + Motorola:*:4.3:PL8-*) + GUESS=powerpc-harris-powermax + ;; + Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*) + GUESS=powerpc-harris-powermax + ;; + Night_Hawk:Power_UNIX:*:*) + GUESS=powerpc-harris-powerunix + ;; + m88k:CX/UX:7*:*) + GUESS=m88k-harris-cxux7 + ;; + m88k:*:4*:R4*) + GUESS=m88k-motorola-sysv4 + ;; + m88k:*:3*:R3*) + GUESS=m88k-motorola-sysv3 + ;; + AViiON:dgux:*:*) + # DG/UX returns AViiON for all architectures + UNAME_PROCESSOR=`/usr/bin/uname -p` + if test "$UNAME_PROCESSOR" = mc88100 || test "$UNAME_PROCESSOR" = mc88110 + then + if test "$TARGET_BINARY_INTERFACE"x = m88kdguxelfx || \ + test "$TARGET_BINARY_INTERFACE"x = x + then + GUESS=m88k-dg-dgux$UNAME_RELEASE + else + GUESS=m88k-dg-dguxbcs$UNAME_RELEASE + fi + else + GUESS=i586-dg-dgux$UNAME_RELEASE + fi + ;; + M88*:DolphinOS:*:*) # DolphinOS (SVR3) + GUESS=m88k-dolphin-sysv3 + ;; + M88*:*:R3*:*) + # Delta 88k system running SVR3 + GUESS=m88k-motorola-sysv3 + ;; + XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) + GUESS=m88k-tektronix-sysv3 + ;; + Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) + GUESS=m68k-tektronix-bsd + ;; + *:IRIX*:*:*) + IRIX_REL=`echo "$UNAME_RELEASE" | sed -e 's/-/_/g'` + GUESS=mips-sgi-irix$IRIX_REL + ;; + ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. + GUESS=romp-ibm-aix # uname -m gives an 8 hex-code CPU id + ;; # Note that: echo "'`uname -s`'" gives 'AIX ' + i*86:AIX:*:*) + GUESS=i386-ibm-aix + ;; + ia64:AIX:*:*) + if test -x /usr/bin/oslevel ; then + IBM_REV=`/usr/bin/oslevel` + else + IBM_REV=$UNAME_VERSION.$UNAME_RELEASE + fi + GUESS=$UNAME_MACHINE-ibm-aix$IBM_REV + ;; + *:AIX:2:3) + if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then + set_cc_for_build + sed 's/^ //' << EOF > "$dummy.c" + #include + + main() + { + if (!__power_pc()) + exit(1); + puts("powerpc-ibm-aix3.2.5"); + exit(0); + } +EOF + if $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=`"$dummy"` + then + GUESS=$SYSTEM_NAME + else + GUESS=rs6000-ibm-aix3.2.5 + fi + elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then + GUESS=rs6000-ibm-aix3.2.4 + else + GUESS=rs6000-ibm-aix3.2 + fi + ;; + *:AIX:*:[4567]) + IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` + if /usr/sbin/lsattr -El "$IBM_CPU_ID" | grep ' POWER' >/dev/null 2>&1; then + IBM_ARCH=rs6000 + else + IBM_ARCH=powerpc + fi + if test -x /usr/bin/lslpp ; then + IBM_REV=`/usr/bin/lslpp -Lqc bos.rte.libc | \ + awk -F: '{ print $3 }' | sed s/[0-9]*$/0/` + else + IBM_REV=$UNAME_VERSION.$UNAME_RELEASE + fi + GUESS=$IBM_ARCH-ibm-aix$IBM_REV + ;; + *:AIX:*:*) + GUESS=rs6000-ibm-aix + ;; + ibmrt:4.4BSD:*|romp-ibm:4.4BSD:*) + GUESS=romp-ibm-bsd4.4 + ;; + ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and + GUESS=romp-ibm-bsd$UNAME_RELEASE # 4.3 with uname added to + ;; # report: romp-ibm BSD 4.3 + *:BOSX:*:*) + GUESS=rs6000-bull-bosx + ;; + DPX/2?00:B.O.S.:*:*) + GUESS=m68k-bull-sysv3 + ;; + 9000/[34]??:4.3bsd:1.*:*) + GUESS=m68k-hp-bsd + ;; + hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) + GUESS=m68k-hp-bsd4.4 + ;; + 9000/[34678]??:HP-UX:*:*) + HPUX_REV=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*.[0B]*//'` + case $UNAME_MACHINE in + 9000/31?) HP_ARCH=m68000 ;; + 9000/[34]??) HP_ARCH=m68k ;; + 9000/[678][0-9][0-9]) + if test -x /usr/bin/getconf; then + sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` + sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` + case $sc_cpu_version in + 523) HP_ARCH=hppa1.0 ;; # CPU_PA_RISC1_0 + 528) HP_ARCH=hppa1.1 ;; # CPU_PA_RISC1_1 + 532) # CPU_PA_RISC2_0 + case $sc_kernel_bits in + 32) HP_ARCH=hppa2.0n ;; + 64) HP_ARCH=hppa2.0w ;; + '') HP_ARCH=hppa2.0 ;; # HP-UX 10.20 + esac ;; + esac + fi + if test "$HP_ARCH" = ""; then + set_cc_for_build + sed 's/^ //' << EOF > "$dummy.c" + + #define _HPUX_SOURCE + #include + #include + + int main () + { + #if defined(_SC_KERNEL_BITS) + long bits = sysconf(_SC_KERNEL_BITS); + #endif + long cpu = sysconf (_SC_CPU_VERSION); + + switch (cpu) + { + case CPU_PA_RISC1_0: puts ("hppa1.0"); break; + case CPU_PA_RISC1_1: puts ("hppa1.1"); break; + case CPU_PA_RISC2_0: + #if defined(_SC_KERNEL_BITS) + switch (bits) + { + case 64: puts ("hppa2.0w"); break; + case 32: puts ("hppa2.0n"); break; + default: puts ("hppa2.0"); break; + } break; + #else /* !defined(_SC_KERNEL_BITS) */ + puts ("hppa2.0"); break; + #endif + default: puts ("hppa1.0"); break; + } + exit (0); + } +EOF + (CCOPTS="" $CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null) && HP_ARCH=`"$dummy"` + test -z "$HP_ARCH" && HP_ARCH=hppa + fi ;; + esac + if test "$HP_ARCH" = hppa2.0w + then + set_cc_for_build + + # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating + # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler + # generating 64-bit code. GNU and HP use different nomenclature: + # + # $ CC_FOR_BUILD=cc ./config.guess + # => hppa2.0w-hp-hpux11.23 + # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess + # => hppa64-hp-hpux11.23 + + if echo __LP64__ | (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | + grep -q __LP64__ + then + HP_ARCH=hppa2.0w + else + HP_ARCH=hppa64 + fi + fi + GUESS=$HP_ARCH-hp-hpux$HPUX_REV + ;; + ia64:HP-UX:*:*) + HPUX_REV=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*.[0B]*//'` + GUESS=ia64-hp-hpux$HPUX_REV + ;; + 3050*:HI-UX:*:*) + set_cc_for_build + sed 's/^ //' << EOF > "$dummy.c" + #include + int + main () + { + long cpu = sysconf (_SC_CPU_VERSION); + /* The order matters, because CPU_IS_HP_MC68K erroneously returns + true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct + results, however. */ + if (CPU_IS_PA_RISC (cpu)) + { + switch (cpu) + { + case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break; + case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break; + case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break; + default: puts ("hppa-hitachi-hiuxwe2"); break; + } + } + else if (CPU_IS_HP_MC68K (cpu)) + puts ("m68k-hitachi-hiuxwe2"); + else puts ("unknown-hitachi-hiuxwe2"); + exit (0); + } +EOF + $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=`"$dummy"` && + { echo "$SYSTEM_NAME"; exit; } + GUESS=unknown-hitachi-hiuxwe2 + ;; + 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:*) + GUESS=hppa1.1-hp-bsd + ;; + 9000/8??:4.3bsd:*:*) + GUESS=hppa1.0-hp-bsd + ;; + *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) + GUESS=hppa1.0-hp-mpeix + ;; + hp7??:OSF1:*:* | hp8?[79]:OSF1:*:*) + GUESS=hppa1.1-hp-osf + ;; + hp8??:OSF1:*:*) + GUESS=hppa1.0-hp-osf + ;; + i*86:OSF1:*:*) + if test -x /usr/sbin/sysversion ; then + GUESS=$UNAME_MACHINE-unknown-osf1mk + else + GUESS=$UNAME_MACHINE-unknown-osf1 + fi + ;; + parisc*:Lites*:*:*) + GUESS=hppa1.1-hp-lites + ;; + C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) + GUESS=c1-convex-bsd + ;; + C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) + if getsysinfo -f scalar_acc + then echo c32-convex-bsd + else echo c2-convex-bsd + fi + exit ;; + C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) + GUESS=c34-convex-bsd + ;; + C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) + GUESS=c38-convex-bsd + ;; + C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) + GUESS=c4-convex-bsd + ;; + CRAY*Y-MP:*:*:*) + CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` + GUESS=ymp-cray-unicos$CRAY_REL + ;; + CRAY*[A-Z]90:*:*:*) + echo "$UNAME_MACHINE"-cray-unicos"$UNAME_RELEASE" \ + | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ + -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ + -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*TS:*:*:*) + CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` + GUESS=t90-cray-unicos$CRAY_REL + ;; + CRAY*T3E:*:*:*) + CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` + GUESS=alphaev5-cray-unicosmk$CRAY_REL + ;; + CRAY*SV1:*:*:*) + CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` + GUESS=sv1-cray-unicos$CRAY_REL + ;; + *:UNICOS/mp:*:*) + CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` + GUESS=craynv-cray-unicosmp$CRAY_REL + ;; + F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) + FUJITSU_PROC=`uname -m | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz` + FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'` + FUJITSU_REL=`echo "$UNAME_RELEASE" | sed -e 's/ /_/'` + GUESS=${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL} + ;; + 5000:UNIX_System_V:4.*:*) + FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'` + FUJITSU_REL=`echo "$UNAME_RELEASE" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/ /_/'` + GUESS=sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL} + ;; + i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) + GUESS=$UNAME_MACHINE-pc-bsdi$UNAME_RELEASE + ;; + sparc*:BSD/OS:*:*) + GUESS=sparc-unknown-bsdi$UNAME_RELEASE + ;; + *:BSD/OS:*:*) + GUESS=$UNAME_MACHINE-unknown-bsdi$UNAME_RELEASE + ;; + arm:FreeBSD:*:*) + UNAME_PROCESSOR=`uname -p` + set_cc_for_build + if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep -q __ARM_PCS_VFP + then + FREEBSD_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` + GUESS=$UNAME_PROCESSOR-unknown-freebsd$FREEBSD_REL-gnueabi + else + FREEBSD_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` + GUESS=$UNAME_PROCESSOR-unknown-freebsd$FREEBSD_REL-gnueabihf + fi + ;; + *:FreeBSD:*:*) + UNAME_PROCESSOR=`uname -p` + case $UNAME_PROCESSOR in + amd64) + UNAME_PROCESSOR=x86_64 ;; + i386) + UNAME_PROCESSOR=i586 ;; + esac + FREEBSD_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` + GUESS=$UNAME_PROCESSOR-unknown-freebsd$FREEBSD_REL + ;; + i*:CYGWIN*:*) + GUESS=$UNAME_MACHINE-pc-cygwin + ;; + *:MINGW64*:*) + GUESS=$UNAME_MACHINE-pc-mingw64 + ;; + *:MINGW*:*) + GUESS=$UNAME_MACHINE-pc-mingw32 + ;; + *:MSYS*:*) + GUESS=$UNAME_MACHINE-pc-msys + ;; + i*:PW*:*) + GUESS=$UNAME_MACHINE-pc-pw32 + ;; + *:SerenityOS:*:*) + GUESS=$UNAME_MACHINE-pc-serenity + ;; + *:Interix*:*) + case $UNAME_MACHINE in + x86) + GUESS=i586-pc-interix$UNAME_RELEASE + ;; + authenticamd | genuineintel | EM64T) + GUESS=x86_64-unknown-interix$UNAME_RELEASE + ;; + IA64) + GUESS=ia64-unknown-interix$UNAME_RELEASE + ;; + esac ;; + i*:UWIN*:*) + GUESS=$UNAME_MACHINE-pc-uwin + ;; + amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) + GUESS=x86_64-pc-cygwin + ;; + prep*:SunOS:5.*:*) + SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` + GUESS=powerpcle-unknown-solaris2$SUN_REL + ;; + *:GNU:*:*) + # the GNU system + GNU_ARCH=`echo "$UNAME_MACHINE" | sed -e 's,[-/].*$,,'` + GNU_REL=`echo "$UNAME_RELEASE" | sed -e 's,/.*$,,'` + GUESS=$GNU_ARCH-unknown-$LIBC$GNU_REL + ;; + *:GNU/*:*:*) + # other systems with GNU libc and userland + GNU_SYS=`echo "$UNAME_SYSTEM" | sed 's,^[^/]*/,,' | tr "[:upper:]" "[:lower:]"` + GNU_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` + GUESS=$UNAME_MACHINE-unknown-$GNU_SYS$GNU_REL-$LIBC + ;; + x86_64:[Mm]anagarm:*:*|i?86:[Mm]anagarm:*:*) + GUESS="$UNAME_MACHINE-pc-managarm-mlibc" + ;; + *:[Mm]anagarm:*:*) + GUESS="$UNAME_MACHINE-unknown-managarm-mlibc" + ;; + *:Minix:*:*) + GUESS=$UNAME_MACHINE-unknown-minix + ;; + aarch64:Linux:*:*) + set_cc_for_build + CPU=$UNAME_MACHINE + LIBCABI=$LIBC + if test "$CC_FOR_BUILD" != no_compiler_found; then + ABI=64 + sed 's/^ //' << EOF > "$dummy.c" + #ifdef __ARM_EABI__ + #ifdef __ARM_PCS_VFP + ABI=eabihf + #else + ABI=eabi + #endif + #endif +EOF + cc_set_abi=`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^ABI' | sed 's, ,,g'` + eval "$cc_set_abi" + case $ABI in + eabi | eabihf) CPU=armv8l; LIBCABI=$LIBC$ABI ;; + esac + fi + GUESS=$CPU-unknown-linux-$LIBCABI + ;; + aarch64_be:Linux:*:*) + UNAME_MACHINE=aarch64_be + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + alpha:Linux:*:*) + case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' /proc/cpuinfo 2>/dev/null` in + EV5) UNAME_MACHINE=alphaev5 ;; + EV56) UNAME_MACHINE=alphaev56 ;; + PCA56) UNAME_MACHINE=alphapca56 ;; + PCA57) UNAME_MACHINE=alphapca56 ;; + EV6) UNAME_MACHINE=alphaev6 ;; + EV67) UNAME_MACHINE=alphaev67 ;; + EV68*) UNAME_MACHINE=alphaev68 ;; + esac + objdump --private-headers /bin/sh | grep -q ld.so.1 + if test "$?" = 0 ; then LIBC=gnulibc1 ; fi + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + arc:Linux:*:* | arceb:Linux:*:* | arc32:Linux:*:* | arc64:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + arm*:Linux:*:*) + set_cc_for_build + if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep -q __ARM_EABI__ + then + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + else + if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep -q __ARM_PCS_VFP + then + GUESS=$UNAME_MACHINE-unknown-linux-${LIBC}eabi + else + GUESS=$UNAME_MACHINE-unknown-linux-${LIBC}eabihf + fi + fi + ;; + avr32*:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + cris:Linux:*:*) + GUESS=$UNAME_MACHINE-axis-linux-$LIBC + ;; + crisv32:Linux:*:*) + GUESS=$UNAME_MACHINE-axis-linux-$LIBC + ;; + e2k:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + frv:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + hexagon:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + i*86:Linux:*:*) + GUESS=$UNAME_MACHINE-pc-linux-$LIBC + ;; + ia64:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + k1om:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + kvx:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + kvx:cos:*:*) + GUESS=$UNAME_MACHINE-unknown-cos + ;; + kvx:mbr:*:*) + GUESS=$UNAME_MACHINE-unknown-mbr + ;; + loongarch32:Linux:*:* | loongarch64:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + m32r*:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + m68*:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + mips:Linux:*:* | mips64:Linux:*:*) + set_cc_for_build + IS_GLIBC=0 + test x"${LIBC}" = xgnu && IS_GLIBC=1 + sed 's/^ //' << EOF > "$dummy.c" + #undef CPU + #undef mips + #undef mipsel + #undef mips64 + #undef mips64el + #if ${IS_GLIBC} && defined(_ABI64) + LIBCABI=gnuabi64 + #else + #if ${IS_GLIBC} && defined(_ABIN32) + LIBCABI=gnuabin32 + #else + LIBCABI=${LIBC} + #endif + #endif + + #if ${IS_GLIBC} && defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6 + CPU=mipsisa64r6 + #else + #if ${IS_GLIBC} && !defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6 + CPU=mipsisa32r6 + #else + #if defined(__mips64) + CPU=mips64 + #else + CPU=mips + #endif + #endif + #endif + + #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) + MIPS_ENDIAN=el + #else + #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) + MIPS_ENDIAN= + #else + MIPS_ENDIAN= + #endif + #endif +EOF + cc_set_vars=`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^CPU\|^MIPS_ENDIAN\|^LIBCABI'` + eval "$cc_set_vars" + test "x$CPU" != x && { echo "$CPU${MIPS_ENDIAN}-unknown-linux-$LIBCABI"; exit; } + ;; + mips64el:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + openrisc*:Linux:*:*) + GUESS=or1k-unknown-linux-$LIBC + ;; + or32:Linux:*:* | or1k*:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + padre:Linux:*:*) + GUESS=sparc-unknown-linux-$LIBC + ;; + parisc64:Linux:*:* | hppa64:Linux:*:*) + GUESS=hppa64-unknown-linux-$LIBC + ;; + parisc:Linux:*:* | hppa:Linux:*:*) + # Look for CPU level + case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in + PA7*) GUESS=hppa1.1-unknown-linux-$LIBC ;; + PA8*) GUESS=hppa2.0-unknown-linux-$LIBC ;; + *) GUESS=hppa-unknown-linux-$LIBC ;; + esac + ;; + ppc64:Linux:*:*) + GUESS=powerpc64-unknown-linux-$LIBC + ;; + ppc:Linux:*:*) + GUESS=powerpc-unknown-linux-$LIBC + ;; + ppc64le:Linux:*:*) + GUESS=powerpc64le-unknown-linux-$LIBC + ;; + ppcle:Linux:*:*) + GUESS=powerpcle-unknown-linux-$LIBC + ;; + riscv32:Linux:*:* | riscv32be:Linux:*:* | riscv64:Linux:*:* | riscv64be:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + s390:Linux:*:* | s390x:Linux:*:*) + GUESS=$UNAME_MACHINE-ibm-linux-$LIBC + ;; + sh64*:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + sh*:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + sparc:Linux:*:* | sparc64:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + tile*:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + vax:Linux:*:*) + GUESS=$UNAME_MACHINE-dec-linux-$LIBC + ;; + x86_64:Linux:*:*) + set_cc_for_build + CPU=$UNAME_MACHINE + LIBCABI=$LIBC + if test "$CC_FOR_BUILD" != no_compiler_found; then + ABI=64 + sed 's/^ //' << EOF > "$dummy.c" + #ifdef __i386__ + ABI=x86 + #else + #ifdef __ILP32__ + ABI=x32 + #endif + #endif +EOF + cc_set_abi=`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^ABI' | sed 's, ,,g'` + eval "$cc_set_abi" + case $ABI in + x86) CPU=i686 ;; + x32) LIBCABI=${LIBC}x32 ;; + esac + fi + GUESS=$CPU-pc-linux-$LIBCABI + ;; + xtensa*:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + i*86:DYNIX/ptx:4*:*) + # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. + # earlier versions are messed up and put the nodename in both + # sysname and nodename. + GUESS=i386-sequent-sysv4 + ;; + i*86:UNIX_SV:4.2MP:2.*) + # Unixware is an offshoot of SVR4, but it has its own version + # number series starting with 2... + # I am not positive that other SVR4 systems won't match this, + # I just have to hope. -- rms. + # Use sysv4.2uw... so that sysv4* matches it. + GUESS=$UNAME_MACHINE-pc-sysv4.2uw$UNAME_VERSION + ;; + i*86:OS/2:*:*) + # If we were able to find 'uname', then EMX Unix compatibility + # is probably installed. + GUESS=$UNAME_MACHINE-pc-os2-emx + ;; + i*86:XTS-300:*:STOP) + GUESS=$UNAME_MACHINE-unknown-stop + ;; + i*86:atheos:*:*) + GUESS=$UNAME_MACHINE-unknown-atheos + ;; + i*86:syllable:*:*) + GUESS=$UNAME_MACHINE-pc-syllable + ;; + i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*) + GUESS=i386-unknown-lynxos$UNAME_RELEASE + ;; + i*86:*DOS:*:*) + GUESS=$UNAME_MACHINE-pc-msdosdjgpp + ;; + i*86:*:4.*:*) + UNAME_REL=`echo "$UNAME_RELEASE" | sed 's/\/MP$//'` + if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then + GUESS=$UNAME_MACHINE-univel-sysv$UNAME_REL + else + GUESS=$UNAME_MACHINE-pc-sysv$UNAME_REL + fi + ;; + i*86:*:5:[678]*) + # UnixWare 7.x, OpenUNIX and OpenServer 6. + case `/bin/uname -X | grep "^Machine"` in + *486*) UNAME_MACHINE=i486 ;; + *Pentium) UNAME_MACHINE=i586 ;; + *Pent*|*Celeron) UNAME_MACHINE=i686 ;; + esac + GUESS=$UNAME_MACHINE-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} + ;; + i*86:*:3.2:*) + if test -f /usr/options/cb.name; then + UNAME_REL=`sed -n 's/.*Version //p' /dev/null >/dev/null ; then + UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')` + (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486 + (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \ + && UNAME_MACHINE=i586 + (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \ + && UNAME_MACHINE=i686 + (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \ + && UNAME_MACHINE=i686 + GUESS=$UNAME_MACHINE-pc-sco$UNAME_REL + else + GUESS=$UNAME_MACHINE-pc-sysv32 + fi + ;; + pc:*:*:*) + # Left here for compatibility: + # uname -m prints for DJGPP always 'pc', but it prints nothing about + # the processor, so we play safe by assuming i586. + # Note: whatever this is, it MUST be the same as what config.sub + # prints for the "djgpp" host, or else GDB configure will decide that + # this is a cross-build. + GUESS=i586-pc-msdosdjgpp + ;; + Intel:Mach:3*:*) + GUESS=i386-pc-mach3 + ;; + paragon:*:*:*) + GUESS=i860-intel-osf1 + ;; + i860:*:4.*:*) # i860-SVR4 + if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then + GUESS=i860-stardent-sysv$UNAME_RELEASE # Stardent Vistra i860-SVR4 + else # Add other i860-SVR4 vendors below as they are discovered. + GUESS=i860-unknown-sysv$UNAME_RELEASE # Unknown i860-SVR4 + fi + ;; + mini*:CTIX:SYS*5:*) + # "miniframe" + GUESS=m68010-convergent-sysv + ;; + mc68k:UNIX:SYSTEM5:3.51m) + GUESS=m68k-convergent-sysv + ;; + M680?0:D-NIX:5.3:*) + GUESS=m68k-diab-dnix + ;; + M68*:*:R3V[5678]*:*) + test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;; + 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0) + OS_REL='' + test -r /etc/.relid \ + && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && { echo i486-ncr-sysv4.3"$OS_REL"; exit; } + /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ + && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } ;; + 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && { echo i486-ncr-sysv4; exit; } ;; + NCR*:*:4.2:* | MPRAS*:*:4.2:*) + OS_REL='.3' + test -r /etc/.relid \ + && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && { echo i486-ncr-sysv4.3"$OS_REL"; exit; } + /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ + && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } + /bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \ + && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } ;; + m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) + GUESS=m68k-unknown-lynxos$UNAME_RELEASE + ;; + mc68030:UNIX_System_V:4.*:*) + GUESS=m68k-atari-sysv4 + ;; + TSUNAMI:LynxOS:2.*:*) + GUESS=sparc-unknown-lynxos$UNAME_RELEASE + ;; + rs6000:LynxOS:2.*:*) + GUESS=rs6000-unknown-lynxos$UNAME_RELEASE + ;; + PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*) + GUESS=powerpc-unknown-lynxos$UNAME_RELEASE + ;; + SM[BE]S:UNIX_SV:*:*) + GUESS=mips-dde-sysv$UNAME_RELEASE + ;; + RM*:ReliantUNIX-*:*:*) + GUESS=mips-sni-sysv4 + ;; + RM*:SINIX-*:*:*) + GUESS=mips-sni-sysv4 + ;; + *:SINIX-*:*:*) + if uname -p 2>/dev/null >/dev/null ; then + UNAME_MACHINE=`(uname -p) 2>/dev/null` + GUESS=$UNAME_MACHINE-sni-sysv4 + else + GUESS=ns32k-sni-sysv + fi + ;; + PENTIUM:*:4.0*:*) # Unisys 'ClearPath HMP IX 4000' SVR4/MP effort + # says + GUESS=i586-unisys-sysv4 + ;; + *:UNIX_System_V:4*:FTX*) + # From Gerald Hewes . + # How about differentiating between stratus architectures? -djm + GUESS=hppa1.1-stratus-sysv4 + ;; + *:*:*:FTX*) + # From seanf@swdc.stratus.com. + GUESS=i860-stratus-sysv4 + ;; + i*86:VOS:*:*) + # From Paul.Green@stratus.com. + GUESS=$UNAME_MACHINE-stratus-vos + ;; + *:VOS:*:*) + # From Paul.Green@stratus.com. + GUESS=hppa1.1-stratus-vos + ;; + mc68*:A/UX:*:*) + GUESS=m68k-apple-aux$UNAME_RELEASE + ;; + news*:NEWS-OS:6*:*) + GUESS=mips-sony-newsos6 + ;; + R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) + if test -d /usr/nec; then + GUESS=mips-nec-sysv$UNAME_RELEASE + else + GUESS=mips-unknown-sysv$UNAME_RELEASE + fi + ;; + BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. + GUESS=powerpc-be-beos + ;; + BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. + GUESS=powerpc-apple-beos + ;; + BePC:BeOS:*:*) # BeOS running on Intel PC compatible. + GUESS=i586-pc-beos + ;; + BePC:Haiku:*:*) # Haiku running on Intel PC compatible. + GUESS=i586-pc-haiku + ;; + ppc:Haiku:*:*) # Haiku running on Apple PowerPC + GUESS=powerpc-apple-haiku + ;; + *:Haiku:*:*) # Haiku modern gcc (not bound by BeOS compat) + GUESS=$UNAME_MACHINE-unknown-haiku + ;; + SX-4:SUPER-UX:*:*) + GUESS=sx4-nec-superux$UNAME_RELEASE + ;; + SX-5:SUPER-UX:*:*) + GUESS=sx5-nec-superux$UNAME_RELEASE + ;; + SX-6:SUPER-UX:*:*) + GUESS=sx6-nec-superux$UNAME_RELEASE + ;; + SX-7:SUPER-UX:*:*) + GUESS=sx7-nec-superux$UNAME_RELEASE + ;; + SX-8:SUPER-UX:*:*) + GUESS=sx8-nec-superux$UNAME_RELEASE + ;; + SX-8R:SUPER-UX:*:*) + GUESS=sx8r-nec-superux$UNAME_RELEASE + ;; + SX-ACE:SUPER-UX:*:*) + GUESS=sxace-nec-superux$UNAME_RELEASE + ;; + Power*:Rhapsody:*:*) + GUESS=powerpc-apple-rhapsody$UNAME_RELEASE + ;; + *:Rhapsody:*:*) + GUESS=$UNAME_MACHINE-apple-rhapsody$UNAME_RELEASE + ;; + arm64:Darwin:*:*) + GUESS=aarch64-apple-darwin$UNAME_RELEASE + ;; + *:Darwin:*:*) + UNAME_PROCESSOR=`uname -p` + case $UNAME_PROCESSOR in + unknown) UNAME_PROCESSOR=powerpc ;; + esac + if command -v xcode-select > /dev/null 2> /dev/null && \ + ! xcode-select --print-path > /dev/null 2> /dev/null ; then + # Avoid executing cc if there is no toolchain installed as + # cc will be a stub that puts up a graphical alert + # prompting the user to install developer tools. + CC_FOR_BUILD=no_compiler_found + else + set_cc_for_build + fi + if test "$CC_FOR_BUILD" != no_compiler_found; then + if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \ + (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ + grep IS_64BIT_ARCH >/dev/null + then + case $UNAME_PROCESSOR in + i386) UNAME_PROCESSOR=x86_64 ;; + powerpc) UNAME_PROCESSOR=powerpc64 ;; + esac + fi + # On 10.4-10.6 one might compile for PowerPC via gcc -arch ppc + if (echo '#ifdef __POWERPC__'; echo IS_PPC; echo '#endif') | \ + (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ + grep IS_PPC >/dev/null + then + UNAME_PROCESSOR=powerpc + fi + elif test "$UNAME_PROCESSOR" = i386 ; then + # uname -m returns i386 or x86_64 + UNAME_PROCESSOR=$UNAME_MACHINE + fi + GUESS=$UNAME_PROCESSOR-apple-darwin$UNAME_RELEASE + ;; + *:procnto*:*:* | *:QNX:[0123456789]*:*) + UNAME_PROCESSOR=`uname -p` + if test "$UNAME_PROCESSOR" = x86; then + UNAME_PROCESSOR=i386 + UNAME_MACHINE=pc + fi + GUESS=$UNAME_PROCESSOR-$UNAME_MACHINE-nto-qnx$UNAME_RELEASE + ;; + *:QNX:*:4*) + GUESS=i386-pc-qnx + ;; + NEO-*:NONSTOP_KERNEL:*:*) + GUESS=neo-tandem-nsk$UNAME_RELEASE + ;; + NSE-*:NONSTOP_KERNEL:*:*) + GUESS=nse-tandem-nsk$UNAME_RELEASE + ;; + NSR-*:NONSTOP_KERNEL:*:*) + GUESS=nsr-tandem-nsk$UNAME_RELEASE + ;; + NSV-*:NONSTOP_KERNEL:*:*) + GUESS=nsv-tandem-nsk$UNAME_RELEASE + ;; + NSX-*:NONSTOP_KERNEL:*:*) + GUESS=nsx-tandem-nsk$UNAME_RELEASE + ;; + *:NonStop-UX:*:*) + GUESS=mips-compaq-nonstopux + ;; + BS2000:POSIX*:*:*) + GUESS=bs2000-siemens-sysv + ;; + DS/*:UNIX_System_V:*:*) + GUESS=$UNAME_MACHINE-$UNAME_SYSTEM-$UNAME_RELEASE + ;; + *:Plan9:*:*) + # "uname -m" is not consistent, so use $cputype instead. 386 + # is converted to i386 for consistency with other x86 + # operating systems. + if test "${cputype-}" = 386; then + UNAME_MACHINE=i386 + elif test "x${cputype-}" != x; then + UNAME_MACHINE=$cputype + fi + GUESS=$UNAME_MACHINE-unknown-plan9 + ;; + *:TOPS-10:*:*) + GUESS=pdp10-unknown-tops10 + ;; + *:TENEX:*:*) + GUESS=pdp10-unknown-tenex + ;; + KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) + GUESS=pdp10-dec-tops20 + ;; + XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) + GUESS=pdp10-xkl-tops20 + ;; + *:TOPS-20:*:*) + GUESS=pdp10-unknown-tops20 + ;; + *:ITS:*:*) + GUESS=pdp10-unknown-its + ;; + SEI:*:*:SEIUX) + GUESS=mips-sei-seiux$UNAME_RELEASE + ;; + *:DragonFly:*:*) + DRAGONFLY_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` + GUESS=$UNAME_MACHINE-unknown-dragonfly$DRAGONFLY_REL + ;; + *:*VMS:*:*) + UNAME_MACHINE=`(uname -p) 2>/dev/null` + case $UNAME_MACHINE in + A*) GUESS=alpha-dec-vms ;; + I*) GUESS=ia64-dec-vms ;; + V*) GUESS=vax-dec-vms ;; + esac ;; + *:XENIX:*:SysV) + GUESS=i386-pc-xenix + ;; + i*86:skyos:*:*) + SKYOS_REL=`echo "$UNAME_RELEASE" | sed -e 's/ .*$//'` + GUESS=$UNAME_MACHINE-pc-skyos$SKYOS_REL + ;; + i*86:rdos:*:*) + GUESS=$UNAME_MACHINE-pc-rdos + ;; + i*86:Fiwix:*:*) + GUESS=$UNAME_MACHINE-pc-fiwix + ;; + *:AROS:*:*) + GUESS=$UNAME_MACHINE-unknown-aros + ;; + x86_64:VMkernel:*:*) + GUESS=$UNAME_MACHINE-unknown-esx + ;; + amd64:Isilon\ OneFS:*:*) + GUESS=x86_64-unknown-onefs + ;; + *:Unleashed:*:*) + GUESS=$UNAME_MACHINE-unknown-unleashed$UNAME_RELEASE + ;; + *:Ironclad:*:*) + GUESS=$UNAME_MACHINE-unknown-ironclad + ;; +esac + +# Do we have a guess based on uname results? +if test "x$GUESS" != x; then + echo "$GUESS" + exit +fi + +# No uname command or uname output not recognized. +set_cc_for_build +cat > "$dummy.c" < +#include +#endif +#if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__) +#if defined (vax) || defined (__vax) || defined (__vax__) || defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__) +#include +#if defined(_SIZE_T_) || defined(SIGLOST) +#include +#endif +#endif +#endif +main () +{ +#if defined (sony) +#if defined (MIPSEB) + /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, + I don't know.... */ + printf ("mips-sony-bsd\n"); exit (0); +#else +#include + printf ("m68k-sony-newsos%s\n", +#ifdef NEWSOS4 + "4" +#else + "" +#endif + ); exit (0); +#endif +#endif + +#if defined (NeXT) +#if !defined (__ARCHITECTURE__) +#define __ARCHITECTURE__ "m68k" +#endif + int version; + version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; + if (version < 4) + printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); + else + printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); + exit (0); +#endif + +#if defined (MULTIMAX) || defined (n16) +#if defined (UMAXV) + printf ("ns32k-encore-sysv\n"); exit (0); +#else +#if defined (CMU) + printf ("ns32k-encore-mach\n"); exit (0); +#else + printf ("ns32k-encore-bsd\n"); exit (0); +#endif +#endif +#endif + +#if defined (__386BSD__) + printf ("i386-pc-bsd\n"); exit (0); +#endif + +#if defined (sequent) +#if defined (i386) + printf ("i386-sequent-dynix\n"); exit (0); +#endif +#if defined (ns32000) + printf ("ns32k-sequent-dynix\n"); exit (0); +#endif +#endif + +#if defined (_SEQUENT_) + struct utsname un; + + uname(&un); + if (strncmp(un.version, "V2", 2) == 0) { + printf ("i386-sequent-ptx2\n"); exit (0); + } + if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ + printf ("i386-sequent-ptx1\n"); exit (0); + } + printf ("i386-sequent-ptx\n"); exit (0); +#endif + +#if defined (vax) +#if !defined (ultrix) +#include +#if defined (BSD) +#if BSD == 43 + printf ("vax-dec-bsd4.3\n"); exit (0); +#else +#if BSD == 199006 + printf ("vax-dec-bsd4.3reno\n"); exit (0); +#else + printf ("vax-dec-bsd\n"); exit (0); +#endif +#endif +#else + printf ("vax-dec-bsd\n"); exit (0); +#endif +#else +#if defined(_SIZE_T_) || defined(SIGLOST) + struct utsname un; + uname (&un); + printf ("vax-dec-ultrix%s\n", un.release); exit (0); +#else + printf ("vax-dec-ultrix\n"); exit (0); +#endif +#endif +#endif +#if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__) +#if defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__) +#if defined(_SIZE_T_) || defined(SIGLOST) + struct utsname *un; + uname (&un); + printf ("mips-dec-ultrix%s\n", un.release); exit (0); +#else + printf ("mips-dec-ultrix\n"); exit (0); +#endif +#endif +#endif + +#if defined (alliant) && defined (i860) + printf ("i860-alliant-bsd\n"); exit (0); +#endif + + exit (1); +} +EOF + +$CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null && SYSTEM_NAME=`"$dummy"` && + { echo "$SYSTEM_NAME"; exit; } + +# Apollos put the system type in the environment. +test -d /usr/apollo && { echo "$ISP-apollo-$SYSTYPE"; exit; } + +echo "$0: unable to guess system type" >&2 + +case $UNAME_MACHINE:$UNAME_SYSTEM in + mips:Linux | mips64:Linux) + # If we got here on MIPS GNU/Linux, output extra information. + cat >&2 <&2 <&2 </dev/null || echo unknown` +uname -r = `(uname -r) 2>/dev/null || echo unknown` +uname -s = `(uname -s) 2>/dev/null || echo unknown` +uname -v = `(uname -v) 2>/dev/null || echo unknown` + +/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null` +/bin/uname -X = `(/bin/uname -X) 2>/dev/null` + +hostinfo = `(hostinfo) 2>/dev/null` +/bin/universe = `(/bin/universe) 2>/dev/null` +/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null` +/bin/arch = `(/bin/arch) 2>/dev/null` +/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` +/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` + +UNAME_MACHINE = "$UNAME_MACHINE" +UNAME_RELEASE = "$UNAME_RELEASE" +UNAME_SYSTEM = "$UNAME_SYSTEM" +UNAME_VERSION = "$UNAME_VERSION" +EOF +fi + +exit 1 + +# Local variables: +# eval: (add-hook 'before-save-hook 'time-stamp) +# time-stamp-start: "timestamp='" +# time-stamp-format: "%:y-%02m-%02d" +# time-stamp-end: "'" +# End: diff --git a/rts/config.sub b/rts/config.sub new file mode 100755 index 000000000000..df5f563de2f2 --- /dev/null +++ b/rts/config.sub @@ -0,0 +1,1971 @@ +#!/usr/bin/sh +# Configuration validation subroutine script. +# Copyright 1992-2024 Free Software Foundation, Inc. + +# shellcheck disable=SC2006,SC2268 # see below for rationale + +timestamp='2024-01-01' + +# This file is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see . +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that +# program. This Exception is an additional permission under section 7 +# of the GNU General Public License, version 3 ("GPLv3"). + + +# Please send patches to . +# +# Configuration subroutine to validate and canonicalize a configuration type. +# Supply the specified configuration type as an argument. +# If it is invalid, we print an error message on stderr and exit with code 1. +# Otherwise, we print the canonical config type on stdout and succeed. + +# You can get the latest version of this script from: +# https://git.savannah.gnu.org/cgit/config.git/plain/config.sub + +# This file is supposed to be the same for all GNU packages +# and recognize all the CPU types, system types and aliases +# that are meaningful with *any* GNU software. +# Each package is responsible for reporting which valid configurations +# it does not support. The user should be able to distinguish +# a failure to support a valid configuration from a meaningless +# configuration. + +# The goal of this file is to map all the various variations of a given +# machine specification into a single specification in the form: +# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM +# or in some cases, the newer four-part form: +# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM +# It is wrong to echo any other type of specification. + +# The "shellcheck disable" line above the timestamp inhibits complaints +# about features and limitations of the classic Bourne shell that were +# superseded or lifted in POSIX. However, this script identifies a wide +# variety of pre-POSIX systems that do not have POSIX shells at all, and +# even some reasonably current systems (Solaris 10 as case-in-point) still +# have a pre-POSIX /bin/sh. + +me=`echo "$0" | sed -e 's,.*/,,'` + +usage="\ +Usage: $0 [OPTION] CPU-MFR-OPSYS or ALIAS + +Canonicalize a configuration name. + +Options: + -h, --help print this help, then exit + -t, --time-stamp print date of last modification, then exit + -v, --version print version number, then exit + +Report bugs and patches to ." + +version="\ +GNU config.sub ($timestamp) + +Copyright 1992-2024 Free Software Foundation, Inc. + +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + +help=" +Try '$me --help' for more information." + +# Parse command line +while test $# -gt 0 ; do + case $1 in + --time-stamp | --time* | -t ) + echo "$timestamp" ; exit ;; + --version | -v ) + echo "$version" ; exit ;; + --help | --h* | -h ) + echo "$usage"; exit ;; + -- ) # Stop option processing + shift; break ;; + - ) # Use stdin as input. + break ;; + -* ) + echo "$me: invalid option $1$help" >&2 + exit 1 ;; + + *local*) + # First pass through any local machine types. + echo "$1" + exit ;; + + * ) + break ;; + esac +done + +case $# in + 0) echo "$me: missing argument$help" >&2 + exit 1;; + 1) ;; + *) echo "$me: too many arguments$help" >&2 + exit 1;; +esac + +# Split fields of configuration type +# shellcheck disable=SC2162 +saved_IFS=$IFS +IFS="-" read field1 field2 field3 field4 <&2 + exit 1 + ;; + *-*-*-*) + basic_machine=$field1-$field2 + basic_os=$field3-$field4 + ;; + *-*-*) + # Ambiguous whether COMPANY is present, or skipped and KERNEL-OS is two + # parts + maybe_os=$field2-$field3 + case $maybe_os in + nto-qnx* | linux-* | uclinux-uclibc* \ + | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* \ + | netbsd*-eabi* | kopensolaris*-gnu* | cloudabi*-eabi* \ + | storm-chaos* | os2-emx* | rtmk-nova* | managarm-* \ + | windows-* ) + basic_machine=$field1 + basic_os=$maybe_os + ;; + android-linux) + basic_machine=$field1-unknown + basic_os=linux-android + ;; + *) + basic_machine=$field1-$field2 + basic_os=$field3 + ;; + esac + ;; + *-*) + # A lone config we happen to match not fitting any pattern + case $field1-$field2 in + decstation-3100) + basic_machine=mips-dec + basic_os= + ;; + *-*) + # Second component is usually, but not always the OS + case $field2 in + # Prevent following clause from handling this valid os + sun*os*) + basic_machine=$field1 + basic_os=$field2 + ;; + zephyr*) + basic_machine=$field1-unknown + basic_os=$field2 + ;; + # Manufacturers + dec* | mips* | sequent* | encore* | pc533* | sgi* | sony* \ + | att* | 7300* | 3300* | delta* | motorola* | sun[234]* \ + | unicom* | ibm* | next | hp | isi* | apollo | altos* \ + | convergent* | ncr* | news | 32* | 3600* | 3100* \ + | hitachi* | c[123]* | convex* | sun | crds | omron* | dg \ + | ultra | tti* | harris | dolphin | highlevel | gould \ + | cbm | ns | masscomp | apple | axis | knuth | cray \ + | microblaze* | sim | cisco \ + | oki | wec | wrs | winbond) + basic_machine=$field1-$field2 + basic_os= + ;; + *) + basic_machine=$field1 + basic_os=$field2 + ;; + esac + ;; + esac + ;; + *) + # Convert single-component short-hands not valid as part of + # multi-component configurations. + case $field1 in + 386bsd) + basic_machine=i386-pc + basic_os=bsd + ;; + a29khif) + basic_machine=a29k-amd + basic_os=udi + ;; + adobe68k) + basic_machine=m68010-adobe + basic_os=scout + ;; + alliant) + basic_machine=fx80-alliant + basic_os= + ;; + altos | altos3068) + basic_machine=m68k-altos + basic_os= + ;; + am29k) + basic_machine=a29k-none + basic_os=bsd + ;; + amdahl) + basic_machine=580-amdahl + basic_os=sysv + ;; + amiga) + basic_machine=m68k-unknown + basic_os= + ;; + amigaos | amigados) + basic_machine=m68k-unknown + basic_os=amigaos + ;; + amigaunix | amix) + basic_machine=m68k-unknown + basic_os=sysv4 + ;; + apollo68) + basic_machine=m68k-apollo + basic_os=sysv + ;; + apollo68bsd) + basic_machine=m68k-apollo + basic_os=bsd + ;; + aros) + basic_machine=i386-pc + basic_os=aros + ;; + aux) + basic_machine=m68k-apple + basic_os=aux + ;; + balance) + basic_machine=ns32k-sequent + basic_os=dynix + ;; + blackfin) + basic_machine=bfin-unknown + basic_os=linux + ;; + cegcc) + basic_machine=arm-unknown + basic_os=cegcc + ;; + convex-c1) + basic_machine=c1-convex + basic_os=bsd + ;; + convex-c2) + basic_machine=c2-convex + basic_os=bsd + ;; + convex-c32) + basic_machine=c32-convex + basic_os=bsd + ;; + convex-c34) + basic_machine=c34-convex + basic_os=bsd + ;; + convex-c38) + basic_machine=c38-convex + basic_os=bsd + ;; + cray) + basic_machine=j90-cray + basic_os=unicos + ;; + crds | unos) + basic_machine=m68k-crds + basic_os= + ;; + da30) + basic_machine=m68k-da30 + basic_os= + ;; + decstation | pmax | pmin | dec3100 | decstatn) + basic_machine=mips-dec + basic_os= + ;; + delta88) + basic_machine=m88k-motorola + basic_os=sysv3 + ;; + dicos) + basic_machine=i686-pc + basic_os=dicos + ;; + djgpp) + basic_machine=i586-pc + basic_os=msdosdjgpp + ;; + ebmon29k) + basic_machine=a29k-amd + basic_os=ebmon + ;; + es1800 | OSE68k | ose68k | ose | OSE) + basic_machine=m68k-ericsson + basic_os=ose + ;; + gmicro) + basic_machine=tron-gmicro + basic_os=sysv + ;; + go32) + basic_machine=i386-pc + basic_os=go32 + ;; + h8300hms) + basic_machine=h8300-hitachi + basic_os=hms + ;; + h8300xray) + basic_machine=h8300-hitachi + basic_os=xray + ;; + h8500hms) + basic_machine=h8500-hitachi + basic_os=hms + ;; + harris) + basic_machine=m88k-harris + basic_os=sysv3 + ;; + hp300 | hp300hpux) + basic_machine=m68k-hp + basic_os=hpux + ;; + hp300bsd) + basic_machine=m68k-hp + basic_os=bsd + ;; + hppaosf) + basic_machine=hppa1.1-hp + basic_os=osf + ;; + hppro) + basic_machine=hppa1.1-hp + basic_os=proelf + ;; + i386mach) + basic_machine=i386-mach + basic_os=mach + ;; + isi68 | isi) + basic_machine=m68k-isi + basic_os=sysv + ;; + m68knommu) + basic_machine=m68k-unknown + basic_os=linux + ;; + magnum | m3230) + basic_machine=mips-mips + basic_os=sysv + ;; + merlin) + basic_machine=ns32k-utek + basic_os=sysv + ;; + mingw64) + basic_machine=x86_64-pc + basic_os=mingw64 + ;; + mingw32) + basic_machine=i686-pc + basic_os=mingw32 + ;; + mingw32ce) + basic_machine=arm-unknown + basic_os=mingw32ce + ;; + monitor) + basic_machine=m68k-rom68k + basic_os=coff + ;; + morphos) + basic_machine=powerpc-unknown + basic_os=morphos + ;; + moxiebox) + basic_machine=moxie-unknown + basic_os=moxiebox + ;; + msdos) + basic_machine=i386-pc + basic_os=msdos + ;; + msys) + basic_machine=i686-pc + basic_os=msys + ;; + mvs) + basic_machine=i370-ibm + basic_os=mvs + ;; + nacl) + basic_machine=le32-unknown + basic_os=nacl + ;; + ncr3000) + basic_machine=i486-ncr + basic_os=sysv4 + ;; + netbsd386) + basic_machine=i386-pc + basic_os=netbsd + ;; + netwinder) + basic_machine=armv4l-rebel + basic_os=linux + ;; + news | news700 | news800 | news900) + basic_machine=m68k-sony + basic_os=newsos + ;; + news1000) + basic_machine=m68030-sony + basic_os=newsos + ;; + necv70) + basic_machine=v70-nec + basic_os=sysv + ;; + nh3000) + basic_machine=m68k-harris + basic_os=cxux + ;; + nh[45]000) + basic_machine=m88k-harris + basic_os=cxux + ;; + nindy960) + basic_machine=i960-intel + basic_os=nindy + ;; + mon960) + basic_machine=i960-intel + basic_os=mon960 + ;; + nonstopux) + basic_machine=mips-compaq + basic_os=nonstopux + ;; + os400) + basic_machine=powerpc-ibm + basic_os=os400 + ;; + OSE68000 | ose68000) + basic_machine=m68000-ericsson + basic_os=ose + ;; + os68k) + basic_machine=m68k-none + basic_os=os68k + ;; + paragon) + basic_machine=i860-intel + basic_os=osf + ;; + parisc) + basic_machine=hppa-unknown + basic_os=linux + ;; + psp) + basic_machine=mipsallegrexel-sony + basic_os=psp + ;; + pw32) + basic_machine=i586-unknown + basic_os=pw32 + ;; + rdos | rdos64) + basic_machine=x86_64-pc + basic_os=rdos + ;; + rdos32) + basic_machine=i386-pc + basic_os=rdos + ;; + rom68k) + basic_machine=m68k-rom68k + basic_os=coff + ;; + sa29200) + basic_machine=a29k-amd + basic_os=udi + ;; + sei) + basic_machine=mips-sei + basic_os=seiux + ;; + sequent) + basic_machine=i386-sequent + basic_os= + ;; + sps7) + basic_machine=m68k-bull + basic_os=sysv2 + ;; + st2000) + basic_machine=m68k-tandem + basic_os= + ;; + stratus) + basic_machine=i860-stratus + basic_os=sysv4 + ;; + sun2) + basic_machine=m68000-sun + basic_os= + ;; + sun2os3) + basic_machine=m68000-sun + basic_os=sunos3 + ;; + sun2os4) + basic_machine=m68000-sun + basic_os=sunos4 + ;; + sun3) + basic_machine=m68k-sun + basic_os= + ;; + sun3os3) + basic_machine=m68k-sun + basic_os=sunos3 + ;; + sun3os4) + basic_machine=m68k-sun + basic_os=sunos4 + ;; + sun4) + basic_machine=sparc-sun + basic_os= + ;; + sun4os3) + basic_machine=sparc-sun + basic_os=sunos3 + ;; + sun4os4) + basic_machine=sparc-sun + basic_os=sunos4 + ;; + sun4sol2) + basic_machine=sparc-sun + basic_os=solaris2 + ;; + sun386 | sun386i | roadrunner) + basic_machine=i386-sun + basic_os= + ;; + sv1) + basic_machine=sv1-cray + basic_os=unicos + ;; + symmetry) + basic_machine=i386-sequent + basic_os=dynix + ;; + t3e) + basic_machine=alphaev5-cray + basic_os=unicos + ;; + t90) + basic_machine=t90-cray + basic_os=unicos + ;; + toad1) + basic_machine=pdp10-xkl + basic_os=tops20 + ;; + tpf) + basic_machine=s390x-ibm + basic_os=tpf + ;; + udi29k) + basic_machine=a29k-amd + basic_os=udi + ;; + ultra3) + basic_machine=a29k-nyu + basic_os=sym1 + ;; + v810 | necv810) + basic_machine=v810-nec + basic_os=none + ;; + vaxv) + basic_machine=vax-dec + basic_os=sysv + ;; + vms) + basic_machine=vax-dec + basic_os=vms + ;; + vsta) + basic_machine=i386-pc + basic_os=vsta + ;; + vxworks960) + basic_machine=i960-wrs + basic_os=vxworks + ;; + vxworks68) + basic_machine=m68k-wrs + basic_os=vxworks + ;; + vxworks29k) + basic_machine=a29k-wrs + basic_os=vxworks + ;; + xbox) + basic_machine=i686-pc + basic_os=mingw32 + ;; + ymp) + basic_machine=ymp-cray + basic_os=unicos + ;; + *) + basic_machine=$1 + basic_os= + ;; + esac + ;; +esac + +# Decode 1-component or ad-hoc basic machines +case $basic_machine in + # Here we handle the default manufacturer of certain CPU types. It is in + # some cases the only manufacturer, in others, it is the most popular. + w89k) + cpu=hppa1.1 + vendor=winbond + ;; + op50n) + cpu=hppa1.1 + vendor=oki + ;; + op60c) + cpu=hppa1.1 + vendor=oki + ;; + ibm*) + cpu=i370 + vendor=ibm + ;; + orion105) + cpu=clipper + vendor=highlevel + ;; + mac | mpw | mac-mpw) + cpu=m68k + vendor=apple + ;; + pmac | pmac-mpw) + cpu=powerpc + vendor=apple + ;; + + # Recognize the various machine names and aliases which stand + # for a CPU type and a company and sometimes even an OS. + 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) + cpu=m68000 + vendor=att + ;; + 3b*) + cpu=we32k + vendor=att + ;; + bluegene*) + cpu=powerpc + vendor=ibm + basic_os=cnk + ;; + decsystem10* | dec10*) + cpu=pdp10 + vendor=dec + basic_os=tops10 + ;; + decsystem20* | dec20*) + cpu=pdp10 + vendor=dec + basic_os=tops20 + ;; + delta | 3300 | motorola-3300 | motorola-delta \ + | 3300-motorola | delta-motorola) + cpu=m68k + vendor=motorola + ;; + dpx2*) + cpu=m68k + vendor=bull + basic_os=sysv3 + ;; + encore | umax | mmax) + cpu=ns32k + vendor=encore + ;; + elxsi) + cpu=elxsi + vendor=elxsi + basic_os=${basic_os:-bsd} + ;; + fx2800) + cpu=i860 + vendor=alliant + ;; + genix) + cpu=ns32k + vendor=ns + ;; + h3050r* | hiux*) + cpu=hppa1.1 + vendor=hitachi + basic_os=hiuxwe2 + ;; + hp3k9[0-9][0-9] | hp9[0-9][0-9]) + cpu=hppa1.0 + vendor=hp + ;; + hp9k2[0-9][0-9] | hp9k31[0-9]) + cpu=m68000 + vendor=hp + ;; + hp9k3[2-9][0-9]) + cpu=m68k + vendor=hp + ;; + hp9k6[0-9][0-9] | hp6[0-9][0-9]) + cpu=hppa1.0 + vendor=hp + ;; + hp9k7[0-79][0-9] | hp7[0-79][0-9]) + cpu=hppa1.1 + vendor=hp + ;; + hp9k78[0-9] | hp78[0-9]) + # FIXME: really hppa2.0-hp + cpu=hppa1.1 + vendor=hp + ;; + hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893) + # FIXME: really hppa2.0-hp + cpu=hppa1.1 + vendor=hp + ;; + hp9k8[0-9][13679] | hp8[0-9][13679]) + cpu=hppa1.1 + vendor=hp + ;; + hp9k8[0-9][0-9] | hp8[0-9][0-9]) + cpu=hppa1.0 + vendor=hp + ;; + i*86v32) + cpu=`echo "$1" | sed -e 's/86.*/86/'` + vendor=pc + basic_os=sysv32 + ;; + i*86v4*) + cpu=`echo "$1" | sed -e 's/86.*/86/'` + vendor=pc + basic_os=sysv4 + ;; + i*86v) + cpu=`echo "$1" | sed -e 's/86.*/86/'` + vendor=pc + basic_os=sysv + ;; + i*86sol2) + cpu=`echo "$1" | sed -e 's/86.*/86/'` + vendor=pc + basic_os=solaris2 + ;; + j90 | j90-cray) + cpu=j90 + vendor=cray + basic_os=${basic_os:-unicos} + ;; + iris | iris4d) + cpu=mips + vendor=sgi + case $basic_os in + irix*) + ;; + *) + basic_os=irix4 + ;; + esac + ;; + miniframe) + cpu=m68000 + vendor=convergent + ;; + *mint | mint[0-9]* | *MiNT | *MiNT[0-9]*) + cpu=m68k + vendor=atari + basic_os=mint + ;; + news-3600 | risc-news) + cpu=mips + vendor=sony + basic_os=newsos + ;; + next | m*-next) + cpu=m68k + vendor=next + case $basic_os in + openstep*) + ;; + nextstep*) + ;; + ns2*) + basic_os=nextstep2 + ;; + *) + basic_os=nextstep3 + ;; + esac + ;; + np1) + cpu=np1 + vendor=gould + ;; + op50n-* | op60c-*) + cpu=hppa1.1 + vendor=oki + basic_os=proelf + ;; + pa-hitachi) + cpu=hppa1.1 + vendor=hitachi + basic_os=hiuxwe2 + ;; + pbd) + cpu=sparc + vendor=tti + ;; + pbb) + cpu=m68k + vendor=tti + ;; + pc532) + cpu=ns32k + vendor=pc532 + ;; + pn) + cpu=pn + vendor=gould + ;; + power) + cpu=power + vendor=ibm + ;; + ps2) + cpu=i386 + vendor=ibm + ;; + rm[46]00) + cpu=mips + vendor=siemens + ;; + rtpc | rtpc-*) + cpu=romp + vendor=ibm + ;; + sde) + cpu=mipsisa32 + vendor=sde + basic_os=${basic_os:-elf} + ;; + simso-wrs) + cpu=sparclite + vendor=wrs + basic_os=vxworks + ;; + tower | tower-32) + cpu=m68k + vendor=ncr + ;; + vpp*|vx|vx-*) + cpu=f301 + vendor=fujitsu + ;; + w65) + cpu=w65 + vendor=wdc + ;; + w89k-*) + cpu=hppa1.1 + vendor=winbond + basic_os=proelf + ;; + none) + cpu=none + vendor=none + ;; + leon|leon[3-9]) + cpu=sparc + vendor=$basic_machine + ;; + leon-*|leon[3-9]-*) + cpu=sparc + vendor=`echo "$basic_machine" | sed 's/-.*//'` + ;; + + *-*) + # shellcheck disable=SC2162 + saved_IFS=$IFS + IFS="-" read cpu vendor <&2 + exit 1 + ;; + esac + ;; +esac + +# Here we canonicalize certain aliases for manufacturers. +case $vendor in + digital*) + vendor=dec + ;; + commodore*) + vendor=cbm + ;; + *) + ;; +esac + +# Decode manufacturer-specific aliases for certain operating systems. + +if test x"$basic_os" != x +then + +# First recognize some ad-hoc cases, or perhaps split kernel-os, or else just +# set os. +obj= +case $basic_os in + gnu/linux*) + kernel=linux + os=`echo "$basic_os" | sed -e 's|gnu/linux|gnu|'` + ;; + os2-emx) + kernel=os2 + os=`echo "$basic_os" | sed -e 's|os2-emx|emx|'` + ;; + nto-qnx*) + kernel=nto + os=`echo "$basic_os" | sed -e 's|nto-qnx|qnx|'` + ;; + *-*) + # shellcheck disable=SC2162 + saved_IFS=$IFS + IFS="-" read kernel os <&2 + fi + ;; + *) + echo "Invalid configuration '$1': OS '$os' not recognized" 1>&2 + exit 1 + ;; +esac + +case $obj in + aout* | coff* | elf* | pe*) + ;; + '') + # empty is fine + ;; + *) + echo "Invalid configuration '$1': Machine code format '$obj' not recognized" 1>&2 + exit 1 + ;; +esac + +# Here we handle the constraint that a (synthetic) cpu and os are +# valid only in combination with each other and nowhere else. +case $cpu-$os in + # The "javascript-unknown-ghcjs" triple is used by GHC; we + # accept it here in order to tolerate that, but reject any + # variations. + javascript-ghcjs) + ;; + javascript-* | *-ghcjs) + echo "Invalid configuration '$1': cpu '$cpu' is not valid with os '$os$obj'" 1>&2 + exit 1 + ;; +esac + +# As a final step for OS-related things, validate the OS-kernel combination +# (given a valid OS), if there is a kernel. +case $kernel-$os-$obj in + linux-gnu*- | linux-android*- | linux-dietlibc*- | linux-llvm*- \ + | linux-mlibc*- | linux-musl*- | linux-newlib*- \ + | linux-relibc*- | linux-uclibc*- ) + ;; + uclinux-uclibc*- ) + ;; + managarm-mlibc*- | managarm-kernel*- ) + ;; + windows*-msvc*-) + ;; + -dietlibc*- | -llvm*- | -mlibc*- | -musl*- | -newlib*- | -relibc*- \ + | -uclibc*- ) + # These are just libc implementations, not actual OSes, and thus + # require a kernel. + echo "Invalid configuration '$1': libc '$os' needs explicit kernel." 1>&2 + exit 1 + ;; + -kernel*- ) + echo "Invalid configuration '$1': '$os' needs explicit kernel." 1>&2 + exit 1 + ;; + *-kernel*- ) + echo "Invalid configuration '$1': '$kernel' does not support '$os'." 1>&2 + exit 1 + ;; + *-msvc*- ) + echo "Invalid configuration '$1': '$os' needs 'windows'." 1>&2 + exit 1 + ;; + kfreebsd*-gnu*- | kopensolaris*-gnu*-) + ;; + vxworks-simlinux- | vxworks-simwindows- | vxworks-spe-) + ;; + nto-qnx*-) + ;; + os2-emx-) + ;; + *-eabi*- | *-gnueabi*-) + ;; + none--*) + # None (no kernel, i.e. freestanding / bare metal), + # can be paired with an machine code file format + ;; + -*-) + # Blank kernel with real OS is always fine. + ;; + --*) + # Blank kernel and OS with real machine code file format is always fine. + ;; + *-*-*) + echo "Invalid configuration '$1': Kernel '$kernel' not known to work with OS '$os'." 1>&2 + exit 1 + ;; +esac + +# Here we handle the case where we know the os, and the CPU type, but not the +# manufacturer. We pick the logical manufacturer. +case $vendor in + unknown) + case $cpu-$os in + *-riscix*) + vendor=acorn + ;; + *-sunos*) + vendor=sun + ;; + *-cnk* | *-aix*) + vendor=ibm + ;; + *-beos*) + vendor=be + ;; + *-hpux*) + vendor=hp + ;; + *-mpeix*) + vendor=hp + ;; + *-hiux*) + vendor=hitachi + ;; + *-unos*) + vendor=crds + ;; + *-dgux*) + vendor=dg + ;; + *-luna*) + vendor=omron + ;; + *-genix*) + vendor=ns + ;; + *-clix*) + vendor=intergraph + ;; + *-mvs* | *-opened*) + vendor=ibm + ;; + *-os400*) + vendor=ibm + ;; + s390-* | s390x-*) + vendor=ibm + ;; + *-ptx*) + vendor=sequent + ;; + *-tpf*) + vendor=ibm + ;; + *-vxsim* | *-vxworks* | *-windiss*) + vendor=wrs + ;; + *-aux*) + vendor=apple + ;; + *-hms*) + vendor=hitachi + ;; + *-mpw* | *-macos*) + vendor=apple + ;; + *-*mint | *-mint[0-9]* | *-*MiNT | *-MiNT[0-9]*) + vendor=atari + ;; + *-vos*) + vendor=stratus + ;; + esac + ;; +esac + +echo "$cpu-$vendor${kernel:+-$kernel}${os:+-$os}${obj:+-$obj}" +exit + +# Local variables: +# eval: (add-hook 'before-save-hook 'time-stamp) +# time-stamp-start: "timestamp='" +# time-stamp-format: "%:y-%02m-%02d" +# time-stamp-end: "'" +# End: diff --git a/rts/configure.ac b/rts/configure.ac index dd14dcc5701d..113ee1a01215 100644 --- a/rts/configure.ac +++ b/rts/configure.ac @@ -55,7 +55,7 @@ GHC_VERSION=`$GHC --numeric-version 2>/dev/null` if test -z "$GHC_VERSION"; then AC_MSG_ERROR([The specified compiler ($GHC) does not appear to be a valid GHC.]) fi - + dnl NOTE: This is relative to what is being used to compile the rts, dnl even if this is a new rts to be included in a new compiler version. dnl tl;dr: this is going to be wrong in stage1 but will be correct in stage2. @@ -511,6 +511,68 @@ fi rm -rf "$TEMP_FILE" +dnl -------------------------------------------------------------- +dnl Generate derived constants +dnl -------------------------------------------------------------- + +AC_ARG_VAR([NM], [Path to the nm program]) +AC_PATH_PROG([NM], nm) +if test -z "$NM"; then + AC_MSG_ERROR([Cannot find nm]) +fi + +AC_ARG_VAR([OBJDUMP], [Path to the objdump program]) +AC_PATH_PROG([OBJDUMP], objdump) +if test -z "$OBJDUMP"; then + AC_MSG_ERROR([Cannot find objdump]) +fi + +AC_ARG_VAR([DERIVE_CONSTANTS], [Path to the deriveConstants program]) +AC_PATH_PROG([DERIVE_CONSTANTS], deriveConstants) +if test -z "$DERIVE_CONSTANTS"; then + AC_MSG_ERROR([Cannot find deriveConstants]) +fi + +AC_CONFIG_COMMANDS([DerivedConstants.h],[ + dnl NOTE: dnl pass `-fcommon` to force symbols into the common section. If they end + dnl up in the ro data section `nm` won't list their size, and thus derivedConstants + dnl will fail. Recent clang (e.g. 16) will by default use `-fno-common`. + dnl + dnl FIXME: using a relative path here is TERRIBLE + dnl + $DERIVE_CONSTANTS \ + --gen-header \ + -o include/DerivedConstants.h \ + --target-os "$BuildOS_CPP" \ + --gcc-program "$CC" \ + --nm-program "$NM" \ + --objdump-program "$OBJDUMP" \ + --tmpdir "$PWD" \ + --gcc-flag "-Iinclude" \ + --gcc-flag "-I$srcdir" \ + --gcc-flag "-I$srcdir/include" \ + --gcc-flag "-I$srcdir/../rts-headers/include" +],[ + BuildOS_CPP=$BuildOS_CPP + CC=$CC + DERIVE_CONSTANTS=$DERIVE_CONSTANTS + NM=$NM + OBJDUMP=$OBJDUMP +]) + +AC_ARG_VAR([GENAPPLY], [Path to the genapply program]) +AC_PATH_PROG([GENAPPLY], genapply) +if test -z "$GENAPPLY"; then + AC_MSG_ERROR([Cannot find genapply]) +fi + +AC_CONFIG_COMMANDS([AutoApply.h],[ + $GENAPPLY include/DerivedConstants.h > AutoApply.cmm + $GENAPPLY include/DerivedConstants.h -V16 > AutoApply_V16.cmm + $GENAPPLY include/DerivedConstants.h -V32 > AutoApply_V32.cmm + $GENAPPLY include/DerivedConstants.h -V64 > AutoApply_V64.cmm +],[GENAPPLY=$GENAPPLY]) + dnl -------------------------------------------------------------- dnl ** Write config files dnl -------------------------------------------------------------- diff --git a/rts/rts.cabal b/rts/rts.cabal index 5f0402efd8be..5f11b270bf0e 100644 --- a/rts/rts.cabal +++ b/rts/rts.cabal @@ -338,10 +338,12 @@ library autogen-includes: ghcautoconf.h ghcplatform.h + DerivedConstants.h install-includes: ghcautoconf.h ghcplatform.h + DerivedConstants.h if arch(javascript) @@ -378,7 +380,6 @@ library install-includes: HsFFI.h MachDeps.h Rts.h RtsAPI.h Stg.h ghcconfig.h ghcplatform.h - DerivedConstants.h stg/MachRegsForHost.h stg/Types.h @@ -483,7 +484,6 @@ library install-includes: Cmm.h HsFFI.h MachDeps.h Jumps.h Rts.h RtsAPI.h RtsSymbols.h Stg.h ghcconfig.h ghcplatform.h -- ^ from include - DerivedConstants.h rts/EventLogConstants.h rts/EventTypes.h -- ^ generated @@ -554,34 +554,38 @@ library if !arch(x86_64) && !arch(aarch64) ld-options: -read_only_relocs warning - cmm-sources: Apply.cmm - Compact.cmm - ContinuationOps.cmm - Exception.cmm - HeapStackCheck.cmm - Jumps_D.cmm - Jumps_V16.cmm - PrimOps.cmm - StgMiscClosures.cmm - StgStartup.cmm - StgStdThunks.cmm - Updates.cmm - -- AutoApply is generated - AutoApply.cmm - AutoApply_V16.cmm + cmm-sources: + Apply.cmm + Compact.cmm + ContinuationOps.cmm + Exception.cmm + HeapStackCheck.cmm + Jumps_D.cmm + Jumps_V16.cmm + PrimOps.cmm + StgMiscClosures.cmm + StgStartup.cmm + StgStdThunks.cmm + Updates.cmm + + autogen-cmm-sources: + AutoApply.cmm + AutoApply_V16.cmm if arch(x86_64) cmm-sources: - AutoApply_V32.cmm (-mavx2) - AutoApply_V64.cmm (-mavx512f) Jumps_V32.cmm (-mavx2) Jumps_V64.cmm (-mavx512f) + autogen-cmm-sources: + AutoApply_V32.cmm (-mavx2) + AutoApply_V64.cmm (-mavx512f) else cmm-sources: - AutoApply_V32.cmm - AutoApply_V64.cmm Jumps_V32.cmm Jumps_V64.cmm + autogen-cmm-sources: + AutoApply_V32.cmm + AutoApply_V64.cmm -- we always link against libffi, even without libffi-adjustors extra-libraries: ffi From 7e6d727256b97f1e22f1d3c79612f7f7b7efc7b4 Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Fri, 28 Feb 2025 15:49:26 +0800 Subject: [PATCH 28/84] build: simple Makefile --- .github/workflows/ci-cabal-install.yml | 95 ++++++++------ Makefile | 172 +++++++++++++++++++++---- Makefile.orig | 30 +++++ 3 files changed, 238 insertions(+), 59 deletions(-) create mode 100644 Makefile.orig diff --git a/.github/workflows/ci-cabal-install.yml b/.github/workflows/ci-cabal-install.yml index 5f3e762cc087..1fa831e8f19a 100644 --- a/.github/workflows/ci-cabal-install.yml +++ b/.github/workflows/ci-cabal-install.yml @@ -1,4 +1,4 @@ -name: CI +name: CI mostly cabal-install # Trigger the workflow on push or pull request, but only for the master branch on: @@ -7,7 +7,8 @@ on: - opened - synchronize push: - branches: [master] + branches: + - master jobs: cabal: @@ -16,87 +17,107 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest] - ghc: ['9.8.4'] # bootstrapping compiler + os: + - ubuntu-latest + ghc: + - '9.8.4' # bootstrapping compiler steps: - uses: actions/checkout@v4 with: submodules: "recursive" - - uses: haskell/ghcup-setup@v1 - - - id: ghcup + - id: ghc-path + name: Set GHC install directory run: | - ghcup config set cache true - echo "basedir=$(ghcup whereis basedir)" >> $GITHUB_OUTPUT + DIR=${{ github.workspace }}/ghc-${{ matrix.ghc }} + echo "path=$DIR" >> $GITHUB_OUTPUT + echo "$DIR/bin" >> $GITHUB_PATH - - id: ghcup-cache - name: Cache GHCup basedir - uses: actions/cache@v4 + - id: cache-ghc + name: Restore bootstrap compiler + uses: actions/cache/restore@v4 with: - key: ghcup-basedir-${{ github.run_id }} - restore-keys: ghcup-basedir- - path: ${{ steps.ghcup.outputs.basedir }} + key: ${{ matrix.os }}-ghc-${{ matrix.ghc }} + path: ${{ steps.ghc-path.outputs.path }} - - run: | - ghcup install ghc --set ${{ matrix.ghc }} - ghcup install cabal --set + - if: steps.cache-ghc.outputs.cache-hit != 'true' + name: Install ghcup + uses: haskell/ghcup-setup@v1 + - if: steps.cache-ghc.outputs.cache-hit != 'true' + name: Install bootstrap compiler + run: | + ghcup install ghc ${{ matrix.ghc }} --isolate ${{ steps.ghc-path.output.path }} + ghcup install cabal latest --isolate ${{ steps.ghc-path.outputs.path }}/bin + - id: cabal-paths run: | cabal user-config init echo "store=$(cabal path --store-dir)" >> $GITHUB_OUTPUT echo "remote-repo-cache=$(cabal path --remote-repo-cache)" >> $GITHUB_OUTPUT - - name: Restore Hackage index + - name: Restore Hackage index and source packages uses: actions/cache/restore@v4 with: key: hackage-${{ github.run_id }} restore-keys: hackage- path: ${{ steps.cabal-paths.outputs.remote-repo-cache }} - - run: cabal update + - name: Restore cabal store + uses: actions/cache/restore@v4 + with: + key: store-${{ matrix.os }}-${{ matrix.ghc }}-${{ github.run_id }} + restore-keys: store-${{ matrix.os }}-${{ matrix.ghc }}- + path: ${{ steps.cabal-paths.outputs.store }} - name: Restore build artifacts uses: actions/cache/restore@v4 with: - key: ${{ matrix.os }}-${{ matrix.ghc }}-${{ github.run_id }} - restore-keys: ${{ matrix.os }}-${{ matrix.ghc }}- - path: | - ${{ steps.cabal-paths.outputs.store }} - libraries/Cabal/dist-newstyle - _build + key: build-${{ matrix.os }}-${{ matrix.ghc }}-${{ github.run_id }} + restore-keys: build-${{ matrix.os }}-${{ matrix.ghc }}- + path: _build _stage0 _stage1 + + - name: Update Hackage index + run: cabal update - name: Build stage1 run: make stage1 + - name: Build stage1-rts + run: make stage1-rts + - name: Upload artifacts uses: actions/upload-artifact@v4 with: name: stage1 path: _stage1 - - name: Save GHCup cache + - name: Save build artifacts uses: actions/cache/save@v4 if: always() with: - key: ghcup-${{ github.run_id }} - path: ${{ steps.ghcup.outputs.cachedir }} + key: build-${{ matrix.os }}-${{ matrix.ghc }}-${{ github.run_id }} + path: _build _stage0 _stage1 - - name: Save Hackage index + - name: Save cabal store + uses: actions/cache/save@v4 + if: always() + with: + key: store-${{ matrix.os }}-${{ matrix.ghc }}-${{ github.run_id }} + path: ${{ steps.cabal-paths.outputs.store }} + + - name: Save Hackage index and source packages uses: actions/cache/save@v4 if: always() with: key: hackage-${{ github.run_id }} path: ${{ steps.cabal-paths.outputs.remote-repo-cache }} - - name: Save build artifacts - if: always() + - name: Save bootstrap compiler uses: actions/cache/save@v4 + if: steps.cache-ghc.outputs.cache-hit != 'true' with: - key: ${{ matrix.os }}-${{ matrix.ghc }}-${{ github.run_id }} - path: | - ${{ steps.cabal-paths.outputs.store }} - libraries/Cabal/dist-newstyle - _build + key: ${{ matrix.os }}-ghc-${{ matrix.ghc }} + path: ${{ steps.ghc-path.outputs.path }} + diff --git a/Makefile b/Makefile index d07edfae6fe9..ee311518a536 100644 --- a/Makefile +++ b/Makefile @@ -1,30 +1,158 @@ -export CABAL := $(shell cabal update 2>&1 >/dev/null && cabal list-bin -v0 --project-dir libraries/Cabal cabal-install:exe:cabal) +SHELL := bash +.ONESHELL: +.SHELLFLAGS := -eu -o pipefail -c +.DELETE_ON_ERROR: +MAKEFLAGS += --warn-undefined-variables +MAKEFLAGS += --no-builtin-rules -CPUS=$(shell mk/detect-cpu-count.sh) +CABAL0 ?= cabal +CABAL ?= _stage0/bin/cabal +GHC ?= ghc -# Use CPU cores + 1 if not already set -THREADS=${THREADS:-$((CPUS + 1))} +define LIB = +BOLD_RED='\033[1;31m' +RESET='\033[0m' -all: $(CABAL) ./booted - GHC=ghc-9.8.4 ./Build.hs +log() { + echo -e "$${BOLD_RED}+$${RESET} $$@" >&2 + "$$@" +} +endef -cabal: $(CABAL) +%/configure : %/configure.ac + @$(LIB) + log autoreconf $(@D) -$(CABAL): - cabal build --project-dir libraries/Cabal cabal-install:exe:cabal +CABAL_FLAGS += --store-dir $(OUT)/store --logs-dir $(OUT)/logs -./booted: - ./boot - touch $@ +CABAL_INSTALL_FLAGS += --builddir $(OUT)/build +CABAL_INSTALL_FLAGS += --with-compiler $(GHC) +CABAL_INSTALL_FLAGS += --installdir $(OUT)/bin +CABAL_INSTALL_FLAGS += --overwrite-policy=always +# If we copy the executables then ghc will recognise _stage1 as topdir (rather than a path in the store) +CABAL_INSTALL_FLAGS += --install-method=copy -clean: - rm -f ./booted - rm -rf _build +CABAL_INSTALL = $(CABAL) $(CABAL_FLAGS) install $(CABAL_INSTALL_FLAGS) + +cabal: _stage0/bin/cabal + +_stage0/bin/cabal: OUT ?= $(abspath _stage0) +_stage0/bin/cabal: CABAL=$(CABAL0) +_stage0/bin/cabal: + @$(LIB) + log mkdir -p $(@D) + log $(CABAL_INSTALL) --project-dir libraries/Cabal --project-file cabal.release.project cabal-install:exe:cabal + + +STAGE1_EXE = ghc ghc-toolchain-bin deriveConstants genprimopcode genapply +STAGE1_BIN := $(addprefix _stage1/bin/,$(STAGE1_EXE)) + +$(STAGE1_BIN) &: OUT ?= $(abspath _stage1) +$(STAGE1_BIN) &: $(CABAL) + @$(LIB) + log mkdir -p $(@D) + log $(CABAL_INSTALL) --project-file cabal.project.stage1 $(addprefix exe:,$(STAGE1_EXE)) + +_stage1/lib/settings: + @$(LIB) + + # Write here only the settings **actually read** by GHC. + # ghc --info will complete the output with other details + # known internally (like the project version) + + mkdir -p $(@D) + cat > $@ <<-'EOF' + [ ("C compiler command","cc") + , ("C compiler flags","") + , ("C++ compiler command","c++") + , ("C++ compiler flags","") + , ("C compiler link flags","") + , ("C compiler supports -no-pie","YES") + , ("CPP command","cpp") + , ("CPP flags","-E") + , ("Haskell CPP command","cpp") + , ("Haskell CPP flags","-undef -traditional") + , ("JavaScript CPP command","cpp") + , ("JavaScript CPP flags","-CC -Wno-unicode -nostdinc") + , ("C-- CPP command","cpp") + , ("C-- CPP flags","") + , ("C-- CPP supports -g0","YES") + , ("ld supports compact unwind","NO") + , ("ld supports filelist","NO") + , ("ld supports single module","NO") + , ("ld is GNU ld","YES") + , ("Merge objects command","ld.gold") + , ("Merge objects flags","-r") + , ("Merge objects supports response files","YES") + , ("ar command","ar") + , ("ar flags","q") + , ("ar supports at file","YES") + , ("ar supports -L","NO") + , ("ranlib command","ranlib") + , ("otool command","") + , ("install_name_tool command","") + , ("windres command","/bin/false") + , ("unlit command","$$topdir/../bin/unlit") + , ("cross compiling","NO") + , ("target platform string","x86_64-unknown-linux") + , ("target os","OSLinux") + , ("target arch","ArchX86_64") + , ("target word size","8") + , ("target word big endian","NO") + , ("target has GNU nonexec stack","YES") + , ("target has .ident directive","YES") + , ("target has subsections via symbols","NO") + , ("target has libm","NO") + , ("Unregisterised","NO") + , ("LLVM target","x86_64-unknown-linux-gnu") + , ("LLVM llc command","llc") + , ("LLVM opt command","opt") + , ("LLVM llvm-as command","llvm-as") + , ("Use inplace MinGW toolchain","NO") + , ("target RTS linker only supports shared libraries","NO") + , ("Use interpreter","YES") + , ("Support SMP","YES") + , ("RTS ways","") + , ("Tables next to code","YES") + , ("Leading underscore","NO") + , ("Use LibFFI","NO") + , ("RTS expects libdw","NO") + , ("Relative Global Package DB","") + , ("base unit-id","") + ] + EOF + +stage1: _stage1/bin/ghc _stage1/lib/settings + +stage1-rts: CABAL = _stage0/bin/cabal +stage1-rts: OUT ?= $(abspath _stage1-rts) +stage1-rts: _stage0/bin/cabal stage1 rts/configure libraries/ghc-internal/configure + @$(LIB) + + flags=( \ + --with-compiler $(abspath _stage1/bin/ghc) \ + --prefix "$(OUT)" \ + --package-db "$(OUT)/lib/package.conf.d" \ + ) + mkdir -p $(OUT)/lib/package.conf.d + + pushd rts-fs || exit + log ../$(CABAL) act-as-setup --build-type=Simple -- configure --builddir "$(OUT)/dist/rts-fs" "$${flags[@]}" + log ../$(CABAL) act-as-setup --build-type=Simple -- build --builddir "$(OUT)/dist/rts-fs" + log ../$(CABAL) act-as-setup --build-type=Simple -- install --builddir "$(OUT)/dist/rts-fs" + popd + + pushd rts-headers || exit + log ../$(CABAL) act-as-setup --build-type=Simple -- configure --builddir "$(OUT)/dist/rts-headers" "$${flags[@]}" + log ../$(CABAL) act-as-setup --build-type=Simple -- build --builddir "$(OUT)/dist/rts-headers" + log ../$(CABAL) act-as-setup --build-type=Simple -- install --builddir "$(OUT)/dist/rts-headers" + popd + + export DERIVE_CONSTANTS=$(abspath _stage1/bin/deriveConstants) + export GENAPPLY=$(abspath _stage1/bin/genapply) + pushd rts || exit + log ../$(CABAL) act-as-setup --build-type=Configure -- configure --builddir "$(OUT)/dist/rts" -v "$${flags[@]}" + log ../$(CABAL) act-as-setup --build-type=Configure -- build --builddir "$(OUT)/dist/rts" -v + log ../$(CABAL) act-as-setup --build-type=Configure -- install --builddir "$(OUT)/dist/rts" -v + popd -test: all - echo "using THREADS=${THREADS}" >&2 - TEST_HC=`pwd`/_build/bindist/bin/ghc \ - METRICS_FILE=`pwd`/_build/test-perf.csv \ - SUMMARY_FILE=`pwd`/_build/test-summary.txt \ - JUNIT_FILE=`pwd`/_build/test-junit.xml \ - make -C testsuite/tests test THREADS=${THREADS} diff --git a/Makefile.orig b/Makefile.orig new file mode 100644 index 000000000000..d07edfae6fe9 --- /dev/null +++ b/Makefile.orig @@ -0,0 +1,30 @@ +export CABAL := $(shell cabal update 2>&1 >/dev/null && cabal list-bin -v0 --project-dir libraries/Cabal cabal-install:exe:cabal) + +CPUS=$(shell mk/detect-cpu-count.sh) + +# Use CPU cores + 1 if not already set +THREADS=${THREADS:-$((CPUS + 1))} + +all: $(CABAL) ./booted + GHC=ghc-9.8.4 ./Build.hs + +cabal: $(CABAL) + +$(CABAL): + cabal build --project-dir libraries/Cabal cabal-install:exe:cabal + +./booted: + ./boot + touch $@ + +clean: + rm -f ./booted + rm -rf _build + +test: all + echo "using THREADS=${THREADS}" >&2 + TEST_HC=`pwd`/_build/bindist/bin/ghc \ + METRICS_FILE=`pwd`/_build/test-perf.csv \ + SUMMARY_FILE=`pwd`/_build/test-summary.txt \ + JUNIT_FILE=`pwd`/_build/test-junit.xml \ + make -C testsuite/tests test THREADS=${THREADS} From 27dc5cde77b3f741be9790b39d0735b6d83aa76c Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Thu, 27 Feb 2025 17:38:32 +0800 Subject: [PATCH 29/84] feat(ghc-toolchain): add otool and install_name_tool --- utils/ghc-toolchain/exe/Main.hs | 24 +++++++++++++++++++ .../ghc-toolchain/src/GHC/Toolchain/Target.hs | 6 +++++ 2 files changed, 30 insertions(+) diff --git a/utils/ghc-toolchain/exe/Main.hs b/utils/ghc-toolchain/exe/Main.hs index 09f009f554a1..6c328e3f6498 100644 --- a/utils/ghc-toolchain/exe/Main.hs +++ b/utils/ghc-toolchain/exe/Main.hs @@ -55,6 +55,8 @@ data Opts = Opts , optReadelf :: ProgOpt , optMergeObjs :: ProgOpt , optWindres :: ProgOpt + , optOtool :: ProgOpt + , optInstallNameTool :: ProgOpt -- Note we don't actually configure LD into anything but -- see #23857 and #22550 for the very unfortunate story. , optLd :: ProgOpt @@ -103,6 +105,8 @@ emptyOpts = Opts , optReadelf = po0 , optMergeObjs = po0 , optWindres = po0 + , optOtool = po0 + , optInstallNameTool = po0 , optLd = po0 , optUnregisterised = Nothing , optTablesNextToCode = Nothing @@ -131,6 +135,8 @@ _optNm = Lens optNm (\x o -> o {optNm=x}) _optReadelf = Lens optReadelf (\x o -> o {optReadelf=x}) _optMergeObjs = Lens optMergeObjs (\x o -> o {optMergeObjs=x}) _optWindres = Lens optWindres (\x o -> o {optWindres=x}) +_optOtool = Lens optOtool (\x o -> o {optOtool =x}) +_optInstallNameTool = Lens optInstallNameTool (\x o -> o {optInstallNameTool=x}) _optLd = Lens optLd (\x o -> o {optLd= x}) _optTriple :: Lens Opts (Maybe String) @@ -192,6 +198,8 @@ options = , progOpts "readelf" "readelf utility" _optReadelf , progOpts "merge-objs" "linker for merging objects" _optMergeObjs , progOpts "windres" "windres utility" _optWindres + , progOpts "otool" "otool utility" _optOtool + , progOpts "install-name-tool" "install_name_tool utility" _optOtool , progOpts "ld" "linker" _optLd ] where @@ -456,6 +464,20 @@ mkTarget opts = do return (Just windres) _ -> return Nothing + otool <- + case archOS_OS archOs of + OSDarwin -> do + otool <- findProgram "otool" (optOtool opts) ["otool"] + return (Just otool) + _ -> return Nothing + + install_name_tool <- + case archOS_OS archOs of + OSDarwin -> do + install_name_tool <- findProgram "install_name_tool" (optInstallNameTool opts) ["install_name_tool"] + return (Just install_name_tool) + _ -> return Nothing + -- various other properties of the platform tgtWordSize <- checkWordSize cc tgtEndianness <- checkEndianness cc @@ -493,6 +515,8 @@ mkTarget opts = do , tgtNm = nm , tgtMergeObjs = mergeObjs , tgtWindres = windres + , tgtOtool = otool + , tgtInstallNameTool = install_name_tool , tgtWordSize , tgtEndianness , tgtUnregisterised diff --git a/utils/ghc-toolchain/src/GHC/Toolchain/Target.hs b/utils/ghc-toolchain/src/GHC/Toolchain/Target.hs index ec95db46f9da..e1ffd71c7b5d 100644 --- a/utils/ghc-toolchain/src/GHC/Toolchain/Target.hs +++ b/utils/ghc-toolchain/src/GHC/Toolchain/Target.hs @@ -74,6 +74,10 @@ data Target = Target -- Windows-specific tools , tgtWindres :: Maybe Program + + -- Mac specific + , tgtOtool:: Maybe Program + , tgtInstallNameTool :: Maybe Program } deriving (Read, Eq, Ord) @@ -122,5 +126,7 @@ instance Show Target where , ", tgtNm = " ++ show tgtNm , ", tgtMergeObjs = " ++ show tgtMergeObjs , ", tgtWindres = " ++ show tgtWindres + , ", tgtOtool = " ++ show tgtOtool + , ", tgtInstallNameTool = " ++ show tgtInstallNameTool , "}" ] From 80d8600e5519e474de424446fc2269c52fbb6c26 Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Fri, 28 Feb 2025 15:46:28 +0800 Subject: [PATCH 30/84] build: use ghc-toolchain for settings Co-Authored-By: Moritz Angermann --- Makefile | 79 ++++++++++---------------------------------------------- 1 file changed, 13 insertions(+), 66 deletions(-) diff --git a/Makefile b/Makefile index ee311518a536..d041dda57864 100644 --- a/Makefile +++ b/Makefile @@ -53,74 +53,21 @@ $(STAGE1_BIN) &: $(CABAL) log mkdir -p $(@D) log $(CABAL_INSTALL) --project-file cabal.project.stage1 $(addprefix exe:,$(STAGE1_EXE)) -_stage1/lib/settings: +TARGET := $(shell cc -dumpmachine) + +# FIXME: why do they all claim ("target has subsections via symbols","NO") for +# macOS? 9.8 seems to claim this as well. This seems wrong and will severely +# impact dead-stripability if ghc does not emit subsection via symbols. wtf. +# I remain that `ghc-toolchain` is a bad tool and should just be a configure +# script for ghc-bin producing a `settings` file according to a passed +# `--target`. I also think most of the settins file values should have sensible +# defaults: install_name_tool = install_name_tool, ... that do not need to be +# explicitly listed in the settings file unless you want to override them. + +_stage1/lib/settings: _stage1/bin/ghc-toolchain-bin @$(LIB) - - # Write here only the settings **actually read** by GHC. - # ghc --info will complete the output with other details - # known internally (like the project version) - mkdir -p $(@D) - cat > $@ <<-'EOF' - [ ("C compiler command","cc") - , ("C compiler flags","") - , ("C++ compiler command","c++") - , ("C++ compiler flags","") - , ("C compiler link flags","") - , ("C compiler supports -no-pie","YES") - , ("CPP command","cpp") - , ("CPP flags","-E") - , ("Haskell CPP command","cpp") - , ("Haskell CPP flags","-undef -traditional") - , ("JavaScript CPP command","cpp") - , ("JavaScript CPP flags","-CC -Wno-unicode -nostdinc") - , ("C-- CPP command","cpp") - , ("C-- CPP flags","") - , ("C-- CPP supports -g0","YES") - , ("ld supports compact unwind","NO") - , ("ld supports filelist","NO") - , ("ld supports single module","NO") - , ("ld is GNU ld","YES") - , ("Merge objects command","ld.gold") - , ("Merge objects flags","-r") - , ("Merge objects supports response files","YES") - , ("ar command","ar") - , ("ar flags","q") - , ("ar supports at file","YES") - , ("ar supports -L","NO") - , ("ranlib command","ranlib") - , ("otool command","") - , ("install_name_tool command","") - , ("windres command","/bin/false") - , ("unlit command","$$topdir/../bin/unlit") - , ("cross compiling","NO") - , ("target platform string","x86_64-unknown-linux") - , ("target os","OSLinux") - , ("target arch","ArchX86_64") - , ("target word size","8") - , ("target word big endian","NO") - , ("target has GNU nonexec stack","YES") - , ("target has .ident directive","YES") - , ("target has subsections via symbols","NO") - , ("target has libm","NO") - , ("Unregisterised","NO") - , ("LLVM target","x86_64-unknown-linux-gnu") - , ("LLVM llc command","llc") - , ("LLVM opt command","opt") - , ("LLVM llvm-as command","llvm-as") - , ("Use inplace MinGW toolchain","NO") - , ("target RTS linker only supports shared libraries","NO") - , ("Use interpreter","YES") - , ("Support SMP","YES") - , ("RTS ways","") - , ("Tables next to code","YES") - , ("Leading underscore","NO") - , ("Use LibFFI","NO") - , ("RTS expects libdw","NO") - , ("Relative Global Package DB","") - , ("base unit-id","") - ] - EOF + log _stage1/bin/ghc-toolchain-bin --cc=cc --cxx=c++ --output-settings -t $(TARGET) -o $@ stage1: _stage1/bin/ghc _stage1/lib/settings From 15bdbdccaf1752162a7aa82f03b1e22fae227b84 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Thu, 27 Feb 2025 20:30:25 +0900 Subject: [PATCH 31/84] ci: adds cross-platform build support/ci via nix --- .envrc | 7 +++++ .github/workflows/nix-based.yml | 48 +++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 .envrc create mode 100644 .github/workflows/nix-based.yml diff --git a/.envrc b/.envrc new file mode 100644 index 000000000000..665d43906d7c --- /dev/null +++ b/.envrc @@ -0,0 +1,7 @@ +# Check if nix-direnv is already loaded; if not, source it +if ! has nix_direnv_reload; then + source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.0/direnvrc" "sha256-+IuxtJIDzJIlHDAxyzr7M2S3FD +zSd/BNfZe+ntXje0=" +fi + +# Use the specified flake to enter the Nix development environment +use flake github:input-output-hk/devx#ghc98-minimal-ghc \ No newline at end of file diff --git a/.github/workflows/nix-based.yml b/.github/workflows/nix-based.yml new file mode 100644 index 000000000000..d6329800bcf0 --- /dev/null +++ b/.github/workflows/nix-based.yml @@ -0,0 +1,48 @@ +name: CI (with nix) + +# Trigger the workflow on push or pull request, but only for the master branch +on: + pull_request: + types: + - opened + - synchronize + push: + branches: [master] + +defaults: + run: + shell: devx {0} + +jobs: + cabal: + name: ${{ matrix.os }} / ghc ${{ matrix.ghc }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-latest + - macos-latest + ghc: + - ghc98 # bootstrapping compiler + + steps: + - uses: actions/checkout@v4 + with: + submodules: "recursive" + + - name: Build + uses: input-output-hk/actions/devx@latest + with: + platform: ${{ matrix.os == 'ubuntu-latest' && 'x86_64-linux' || 'aarch64-darwin' }} + compiler-nix-name: ${{ matrix.ghc }} + minimal: true + ghc: true + + - run: cabal update + + - name: Build stage1 + run: make stage1 + + - name: Build stage1-rts + run: make stage1-rts From 91b238ef40db7cc714b829ac702cc6f069c69eca Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Fri, 28 Feb 2025 17:06:32 +0800 Subject: [PATCH 32/84] refactor: use cabal main exes rather than act-as-setup --- Makefile | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index d041dda57864..ec4bbe149790 100644 --- a/Makefile +++ b/Makefile @@ -36,13 +36,15 @@ CABAL_INSTALL = $(CABAL) $(CABAL_FLAGS) install $(CABAL_INSTALL_FLAGS) cabal: _stage0/bin/cabal -_stage0/bin/cabal: OUT ?= $(abspath _stage0) -_stage0/bin/cabal: CABAL=$(CABAL0) -_stage0/bin/cabal: +CABAL_EXE = cabal cabal-main-simple cabal-main-configure +CABAL_BIN := $(addprefix _stage0/bin/,$(CABAL_EXE)) + +$(CABAL_BIN) &: OUT ?= $(abspath _stage0) +$(CABAL_BIN) &: CABAL=$(CABAL0) +$(CABAL_BIN) &: @$(LIB) log mkdir -p $(@D) - log $(CABAL_INSTALL) --project-dir libraries/Cabal --project-file cabal.release.project cabal-install:exe:cabal - + log $(CABAL_INSTALL) --project-dir libraries/Cabal --project-file cabal.release.project $(addprefix exe:,$(CABAL_EXE)) STAGE1_EXE = ghc ghc-toolchain-bin deriveConstants genprimopcode genapply STAGE1_BIN := $(addprefix _stage1/bin/,$(STAGE1_EXE)) @@ -73,7 +75,7 @@ stage1: _stage1/bin/ghc _stage1/lib/settings stage1-rts: CABAL = _stage0/bin/cabal stage1-rts: OUT ?= $(abspath _stage1-rts) -stage1-rts: _stage0/bin/cabal stage1 rts/configure libraries/ghc-internal/configure +stage1-rts: _stage0/bin/cabal-main-simple _stage0/bin/cabal-main-configure _stage1/bin/ghc _stage1/bin/deriveConstants _stage1/bin/genapply rts/configure @$(LIB) flags=( \ @@ -84,22 +86,22 @@ stage1-rts: _stage0/bin/cabal stage1 rts/configure libraries/ghc-internal/config mkdir -p $(OUT)/lib/package.conf.d pushd rts-fs || exit - log ../$(CABAL) act-as-setup --build-type=Simple -- configure --builddir "$(OUT)/dist/rts-fs" "$${flags[@]}" - log ../$(CABAL) act-as-setup --build-type=Simple -- build --builddir "$(OUT)/dist/rts-fs" - log ../$(CABAL) act-as-setup --build-type=Simple -- install --builddir "$(OUT)/dist/rts-fs" + log ../_stage0/bin/cabal-main-simple configure --builddir "$(OUT)/dist/rts-fs" "$${flags[@]}" + log ../_stage0/bin/cabal-main-simple build --builddir "$(OUT)/dist/rts-fs" + log ../_stage0/bin/cabal-main-simple install --builddir "$(OUT)/dist/rts-fs" popd pushd rts-headers || exit - log ../$(CABAL) act-as-setup --build-type=Simple -- configure --builddir "$(OUT)/dist/rts-headers" "$${flags[@]}" - log ../$(CABAL) act-as-setup --build-type=Simple -- build --builddir "$(OUT)/dist/rts-headers" - log ../$(CABAL) act-as-setup --build-type=Simple -- install --builddir "$(OUT)/dist/rts-headers" + log ../_stage0/bin/cabal-main-simple configure --builddir "$(OUT)/dist/rts-headers" "$${flags[@]}" + log ../_stage0/bin/cabal-main-simple build --builddir "$(OUT)/dist/rts-headers" + log ../_stage0/bin/cabal-main-simple install --builddir "$(OUT)/dist/rts-headers" popd export DERIVE_CONSTANTS=$(abspath _stage1/bin/deriveConstants) export GENAPPLY=$(abspath _stage1/bin/genapply) pushd rts || exit - log ../$(CABAL) act-as-setup --build-type=Configure -- configure --builddir "$(OUT)/dist/rts" -v "$${flags[@]}" - log ../$(CABAL) act-as-setup --build-type=Configure -- build --builddir "$(OUT)/dist/rts" -v - log ../$(CABAL) act-as-setup --build-type=Configure -- install --builddir "$(OUT)/dist/rts" -v + log ../_stage0/bin/cabal-main-configure configure --builddir "$(OUT)/dist/rts" -v "$${flags[@]}" + log ../_stage0/bin/cabal-main-configure build --builddir "$(OUT)/dist/rts" -v + log ../_stage0/bin/cabal-main-configure install --builddir "$(OUT)/dist/rts" -v popd From 7554a21a93ba5e762a13fd6de7cb394afdee3f55 Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Fri, 28 Feb 2025 21:16:03 +0800 Subject: [PATCH 33/84] ci: use original makefile for ci.yml --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 869442a1b5f7..d1b141e44879 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -69,7 +69,7 @@ jobs: _build - name: Build patched cabal - run: make cabal + run: make -f Makefile.orig cabal - # This runs autoconf also in the subdirectories run: autoreconf -v @@ -78,7 +78,7 @@ jobs: env: CC: gcc CXX: g++ - run: make + run: make -f Makefile.orig - name: Upload artifacts uses: actions/upload-artifact@v4 From bc6ff15550be1c26555eb3df4c6774a829dfc210 Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Fri, 28 Feb 2025 21:27:20 +0800 Subject: [PATCH 34/84] WIP --- Makefile | 105 +++++++++++++++++++++++++++++++------- cabal.project.stage1 | 4 -- cabal.project.stage1-boot | 89 ++++++++++++++++++++++++++++++++ cabal.project.stage1-rts | 4 ++ cabal.project.stage2 | 32 ++++++++++++ 5 files changed, 212 insertions(+), 22 deletions(-) create mode 100644 cabal.project.stage1-boot create mode 100644 cabal.project.stage1-rts create mode 100644 cabal.project.stage2 diff --git a/Makefile b/Makefile index ec4bbe149790..75803af5ff34 100644 --- a/Makefile +++ b/Makefile @@ -25,19 +25,22 @@ endef CABAL_FLAGS += --store-dir $(OUT)/store --logs-dir $(OUT)/logs -CABAL_INSTALL_FLAGS += --builddir $(OUT)/build -CABAL_INSTALL_FLAGS += --with-compiler $(GHC) +CABAL_BUILD_FLAGS += --builddir $(OUT)/build +CABAL_BUILD_FLAGS += --with-compiler $(GHC) + +CABAL_BUILD = $(CABAL) $(CABAL_FLAGS) build $(CABAL_BUILD_FLAGS) + CABAL_INSTALL_FLAGS += --installdir $(OUT)/bin CABAL_INSTALL_FLAGS += --overwrite-policy=always # If we copy the executables then ghc will recognise _stage1 as topdir (rather than a path in the store) CABAL_INSTALL_FLAGS += --install-method=copy -CABAL_INSTALL = $(CABAL) $(CABAL_FLAGS) install $(CABAL_INSTALL_FLAGS) +CABAL_INSTALL = $(CABAL) $(CABAL_FLAGS) install $(CABAL_BUILD_FLAGS) $(CABAL_INSTALL_FLAGS) cabal: _stage0/bin/cabal CABAL_EXE = cabal cabal-main-simple cabal-main-configure -CABAL_BIN := $(addprefix _stage0/bin/,$(CABAL_EXE)) +CABAL_BIN = $(addprefix _stage0/bin/,$(CABAL_EXE)) $(CABAL_BIN) &: OUT ?= $(abspath _stage0) $(CABAL_BIN) &: CABAL=$(CABAL0) @@ -47,7 +50,7 @@ $(CABAL_BIN) &: log $(CABAL_INSTALL) --project-dir libraries/Cabal --project-file cabal.release.project $(addprefix exe:,$(CABAL_EXE)) STAGE1_EXE = ghc ghc-toolchain-bin deriveConstants genprimopcode genapply -STAGE1_BIN := $(addprefix _stage1/bin/,$(STAGE1_EXE)) +STAGE1_BIN = $(addprefix _stage1/bin/,$(STAGE1_EXE)) $(STAGE1_BIN) &: OUT ?= $(abspath _stage1) $(STAGE1_BIN) &: $(CABAL) @@ -73,35 +76,101 @@ _stage1/lib/settings: _stage1/bin/ghc-toolchain-bin stage1: _stage1/bin/ghc _stage1/lib/settings +# +# TODO: We cannot build the rts with cabal-install because we are passing +# to deriveConstants the headers in rts-headers via a relative path. +# cabal-install's install command makes a source distribution before building +# and this breaks the relative path. The solution is to move the call to +# derivedConstants into Setup.hs where we have access to the installed +# packagedb. I had a version of this then it looked too complex and I moved back +# to configure.ac. +# +# stage1-rts: CABAL = _stage0/bin/cabal +# stage1-rts: GHC = $(abspath _stage1/bin/ghc) +# stage1-rts: OUT ?= $(abspath _stage1-rts) +# stage1-rts: _stage0/bin/cabal _stage1/bin/ghc _stage1/bin/deriveConstants _stage1/bin/genapply rts/configure +# @$(LIB) +# # for rts/configure +# export DERIVE_CONSTANTS=$(abspath _stage1/bin/deriveConstants) +# export GENAPPLY=$(abspath _stage1/bin/genapply) +# log $(CABAL_INSTALL) --lib --package-env $(OUT) --project-file cabal.project.stage1-rts all + stage1-rts: CABAL = _stage0/bin/cabal +stage1-rts: CABAL_CONFIG_FLAGS += --with-compiler $(abspath _stage1/bin/ghc) +stage1-rts: CABAL_CONFIG_FLAGS += --prefix $(OUT) +stage1-rts: CABAL_CONFIG_FLAGS += --package-db $(OUT)/lib/package.conf.d stage1-rts: OUT ?= $(abspath _stage1-rts) stage1-rts: _stage0/bin/cabal-main-simple _stage0/bin/cabal-main-configure _stage1/bin/ghc _stage1/bin/deriveConstants _stage1/bin/genapply rts/configure @$(LIB) - - flags=( \ - --with-compiler $(abspath _stage1/bin/ghc) \ - --prefix "$(OUT)" \ - --package-db "$(OUT)/lib/package.conf.d" \ - ) mkdir -p $(OUT)/lib/package.conf.d + # for rts/configure + export DERIVE_CONSTANTS=$(abspath _stage1/bin/deriveConstants) + export GENAPPLY=$(abspath _stage1/bin/genapply) + pushd rts-fs || exit - log ../_stage0/bin/cabal-main-simple configure --builddir "$(OUT)/dist/rts-fs" "$${flags[@]}" + log ../_stage0/bin/cabal-main-simple configure --builddir "$(OUT)/dist/rts-fs" $(CABAL_CONFIG_FLAGS) log ../_stage0/bin/cabal-main-simple build --builddir "$(OUT)/dist/rts-fs" log ../_stage0/bin/cabal-main-simple install --builddir "$(OUT)/dist/rts-fs" popd pushd rts-headers || exit - log ../_stage0/bin/cabal-main-simple configure --builddir "$(OUT)/dist/rts-headers" "$${flags[@]}" + log ../_stage0/bin/cabal-main-simple configure --builddir "$(OUT)/dist/rts-headers" $(CABAL_CONFIG_FLAGS) log ../_stage0/bin/cabal-main-simple build --builddir "$(OUT)/dist/rts-headers" log ../_stage0/bin/cabal-main-simple install --builddir "$(OUT)/dist/rts-headers" popd - export DERIVE_CONSTANTS=$(abspath _stage1/bin/deriveConstants) - export GENAPPLY=$(abspath _stage1/bin/genapply) pushd rts || exit - log ../_stage0/bin/cabal-main-configure configure --builddir "$(OUT)/dist/rts" -v "$${flags[@]}" - log ../_stage0/bin/cabal-main-configure build --builddir "$(OUT)/dist/rts" -v - log ../_stage0/bin/cabal-main-configure install --builddir "$(OUT)/dist/rts" -v + log ../_stage0/bin/cabal-main-configure configure --builddir "$(OUT)/dist/rts" $(CABAL_CONFIG_FLAGS) + log ../_stage0/bin/cabal-main-configure build --builddir "$(OUT)/dist/rts" + log ../_stage0/bin/cabal-main-configure install --builddir "$(OUT)/dist/rts" popd +_stage1-boot/src/compiler/GHC/Builtin/primops.txt: compiler/GHC/Builtin/primops.txt.pp + @$(LIB) + mkdir -p $(@D) + log cc -E -undef -traditional -P -x c $< >$@ + +_stage1-boot/src/ghc-internal/ghc-internal.cabal: + @$(LIB) + rm -rf $(@D) + mkdir -p $(@D) + cp -r libraries/ghc-internal/* $(@D) + +_stage1-boot/src/ghc-internal/src/GHC/Internal/Prim.hs: _stage1-boot/src/compiler/GHC/Builtin/primops.txt | _stage1-boot/src/ghc-internal/ghc-internal.cabal + @$(LIB) + mkdir -p $(@D) + log _stage1/bin/genprimopcode --make-haskell-source < $< > $@ + +_stage1-boot/src/ghc-internal/src/GHC/Internal/PrimopWrappers.hs: _stage1-boot/src/compiler/GHC/Builtin/primops.txt | _stage1-boot/src/ghc-internal/ghc-internal.cabal + @$(LIB) + mkdir -p $(@D) + log _stage1/bin/genprimopcode --make-haskell-wrappers < $< > $@ + +_stage1-boot/src/ghc-internal/.stamp: _stage1-boot/src/ghc-internal/ghc-internal.cabal +_stage1-boot/src/ghc-internal/.stamp: _stage1-boot/src/ghc-internal/src/GHC/Internal/Prim.hs +_stage1-boot/src/ghc-internal/.stamp: _stage1-boot/src/ghc-internal/src/GHC/Internal/PrimopWrappers.hs + +# targets +STAGE1_BOOT_TARGETS = rts ghc-internal ghc-experimental ghc-compact base stm system-cxx-std-lib +# shallow compat packages over ghc-internal +STAGE1_BOOT_TARGETS += ghc-prim ghc-bignum integer-gmp template-haskell +# target dependencies +STAGE1_BOOT_TARGETS += ghc-boot-th pretty +# other boot libraries used by tests +STAGE1_BOOT_TARGETS += array binary bytestring Cabal Cabal-syntax containers deepseq directory exceptions file-io filepath hpc mtl os-string parsec process semaphore-compat text time transformers +STAGE1_BOOT_TARGETS += unix +# FIXME: we'd have to install Win32 for Windows target. Maybe --libs could install dependencies too.. +# ghc related +STAGE1_BOOT_TARGETS += ghc-boot ghc-heap ghc-platform ghc-toolchain ghci ghc + +stage1-boot: CABAL = _stage0/bin/cabal +stage1-boot: GHC = $(abspath _stage1/bin/ghc) +stage1-boot: OUT ?= $(abspath _stage1-boot) +stage1-boot: _stage0/bin/cabal _stage1/bin/ghc _stage1-boot/src/ghc-internal/.stamp _stage1-boot/src/ghc-internal/configure + @$(LIB) + # for rts/configure + export DERIVE_CONSTANTS=$(abspath _stage1/bin/deriveConstants) + export GENAPPLY=$(abspath _stage1/bin/genapply) + log $(CABAL_INSTALL) --lib --package-env $(OUT) --project-file cabal.project.stage1-boot $(STAGE1_BOOT_TARGETS) + diff --git a/cabal.project.stage1 b/cabal.project.stage1 index 42df158554c3..6db48ef9bb09 100644 --- a/cabal.project.stage1 +++ b/cabal.project.stage1 @@ -1,7 +1,3 @@ --- aka cabal.project-ghc --- NOTE: this should be in sync with stage1_project in Build.hs until we merge them --- (except some packages paths) - packages: ./compiler ./ghc diff --git a/cabal.project.stage1-boot b/cabal.project.stage1-boot new file mode 100644 index 000000000000..7167b6ccaa26 --- /dev/null +++ b/cabal.project.stage1-boot @@ -0,0 +1,89 @@ +allow-boot-library-installs: True +active-repositories: :none + +benchmarks: False +tests: False + +packages: + ./compiler + ./ghc + ./rts + ./rts-headers + ./rts-fs + ./libraries/array + ./libraries/base + ./libraries/binary + ./libraries/bytestring + ./libraries/Cabal/Cabal + ./libraries/Cabal/Cabal-syntax + ./libraries/containers/containers + ./libraries/deepseq + ./libraries/directory + ./libraries/exceptions + ./libraries/file-io + ./libraries/filepath + ./libraries/ghc-bignum + ./libraries/ghc-boot + ./libraries/ghc-boot-th + ./libraries/ghc-compact + ./libraries/ghc-experimental + ./libraries/ghc-heap + ./libraries/ghci + -- ./libraries/ghc-internal + _stage1-boot/src/ghc-internal + ./libraries/ghc-platform + ./libraries/ghc-prim + ./libraries/haskeline + ./libraries/hpc + ./libraries/integer-gmp + ./libraries/mtl + ./libraries/os-string + ./libraries/parsec + ./libraries/pretty + ./libraries/process + ./libraries/semaphore-compat + ./libraries/stm + ./libraries/system-cxx-std-lib + ./libraries/template-haskell + ./libraries/terminfo + ./libraries/text + ./libraries/time + ./libraries/transformers + ./libraries/unix + ./libraries/Win32 + ./libraries/xhtml + ./utils/deriveConstants + ./utils/genprimopcode + ./utils/ghc-pkg + ./utils/ghc-toolchain + ./utils/hsc2hs + ./utils/unlit + https://hackage.haskell.org/package/alex-3.5.2.0/alex-3.5.2.0.tar.gz + https://hackage.haskell.org/package/happy-2.1.5/happy-2.1.5.tar.gz + https://hackage.haskell.org/package/happy-lib-2.1.5/happy-lib-2.1.5.tar.gz + -- https://hackage.haskell.org/package/os-string-2.0.7/os-string-2.0.7.tar.gz + -- https://hackage.haskell.org/package/process-1.6.25.0/process-1.6.25.0.tar.gz + -- https://hackage.haskell.org/package/time-1.14/time-1.14.tar.gz + -- https://hackage.haskell.org/package/unix-2.8.6.0/unix-2.8.6.0.tar.gz + +package hsc2hs + flags: +in-ghc-tree + +package ghc + -- build-tool-depends: require genprimopcode, etc. used by Setup.hs + -- internal-interpreter: otherwise our compiler has the internal + -- interpreter but not the boot library we install + -- FIXME: we should really install the lib we used to build stage2 + flags: +build-tool-depends +internal-interpreter + +package ghci + flags: +internal-interpreter + +package ghc-internal + -- FIXME: make our life easier for now by using the native bignum backend + flags: +bignum-native + +package text + -- FIXME: avoid having to deal with system-cxx-std-lib fake package for now + flags: -simdutf + diff --git a/cabal.project.stage1-rts b/cabal.project.stage1-rts new file mode 100644 index 000000000000..c667a87c9c9c --- /dev/null +++ b/cabal.project.stage1-rts @@ -0,0 +1,4 @@ +packages: + rts + rts-fs + rts-headers diff --git a/cabal.project.stage2 b/cabal.project.stage2 new file mode 100644 index 000000000000..4dbec5feb898 --- /dev/null +++ b/cabal.project.stage2 @@ -0,0 +1,32 @@ +packages: + ./ghc + -- https://hackage.haskell.org/package/directory-1.3.9.0/directory-1.3.9.0.tar.gz + -- ./libraries/file-io + -- ./libraries/filepath + -- ./libraries/ghc-platform + -- ./libraries/ghc-boot + -- ./libraries/ghc-boot-th + -- ./libraries/ghc-heap + -- ./libraries/ghci + -- https://hackage.haskell.org/package/os-string-2.0.7/os-string-2.0.7.tar.gz + -- https://hackage.haskell.org/package/process-1.6.25.0/process-1.6.25.0.tar.gz + -- ./libraries/semaphore-compat + -- https://hackage.haskell.org/package/time-1.14/time-1.14.tar.gz + -- https://hackage.haskell.org/package/unix-2.8.6.0/unix-2.8.6.0.tar.gz + -- ./libraries/Win32 + ./utils/ghc-pkg + -- ./utils/hsc2hs + -- ./utils/unlit + -- ./utils/ghc-toolchain + -- ./utils/ghc-toolchain/exe + +benchmarks: False +profiling: False +tests: False + +package ghc-bin + -- FIXME: we don't support the threaded rts way yet + flags: +internal-interpreter -threaded + +package hsc2hs + flags: +in-ghc-tree From 1b12e5b410bc8adb00863b977fdb69a4c3807ad7 Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Wed, 26 Feb 2025 11:26:17 +0800 Subject: [PATCH 35/84] wip: rts derived constants --- rts/Setup.hs | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++ rts/rts.cabal | 6 ++++- 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 rts/Setup.hs diff --git a/rts/Setup.hs b/rts/Setup.hs new file mode 100644 index 000000000000..e6647cb67268 --- /dev/null +++ b/rts/Setup.hs @@ -0,0 +1,69 @@ +{-# OPTIONS_GHC -Wall #-} + +import Data.Map.Strict qualified as Map +import Distribution.Simple +import Distribution.Simple.LocalBuildInfo +import Distribution.Simple.PackageIndex +import Distribution.Simple.Program (Program, gccProgram, programPath, requireProgram, runProgram, simpleProgram) +import Distribution.Simple.Setup +import Distribution.Types.BuildInfo as BI +import Distribution.Types.InstalledPackageInfo as IPI +import Distribution.Types.Library +import Distribution.Types.PackageDescription +import Distribution.Verbosity (normal) + +nmProgram :: Program +nmProgram = simpleProgram "nm" + +objdumpProgram :: Program +objdumpProgram = simpleProgram "objdump" + +deriveConstantsProgram :: Program +deriveConstantsProgram = simpleProgram "deriveConstants" + +main :: IO () +main = + defaultMainWithHooks + autoconfUserHooks + { postConf = \args flags pd lbi -> do + postConf autoconfUserHooks args flags pd lbi + + let verbosity = fromFlagOrDefault normal (configVerbosity flags) + let progdb = withPrograms lbi + (nm, _progdb) <- requireProgram verbosity nmProgram progdb + (objdump, _progdb) <- requireProgram verbosity objdumpProgram progdb + (gcc, _progdb) <- requireProgram verbosity gccProgram progdb + (deriveConstants, _progdb) <- requireProgram verbosity deriveConstantsProgram progdb + + -- Include dirs for this package + let thisIncDirs = foldMap (BI.includeDirs . libBuildInfo) (allLibraries pd) + + -- \^ Include dirs for dependencies + let depsIncDirs = + [ incdir + | Just clbis <- [Map.lookup (CLibName defaultLibName) (componentNameMap lbi)] + , clbi <- clbis + , (unitId, _) <- componentPackageDeps clbi + , Just ipi <- [lookupUnitId (installedPkgs lbi) unitId] + , incdir <- IPI.includeDirs ipi + ] + + + runProgram verbosity deriveConstants $ + [ "--gen-header" + , "-o" + , "include/DerivedConstants.h" + , "--target-os" + , "linux" + , "--gcc-program" + , programPath gcc + , "--nm-program" + , programPath nm + , "--objdump-program" + , programPath objdump + , "--tmpdir" + , buildDir lbi + ] + ++ foldMap (\i -> ["--gcc-flag", "-I" ++ i]) thisIncDirs + ++ foldMap (\incdir -> ["--gcc-flag", "-I" ++ incdir]) depsIncDirs + } diff --git a/rts/rts.cabal b/rts/rts.cabal index 5f11b270bf0e..9a7c1d49532b 100644 --- a/rts/rts.cabal +++ b/rts/rts.cabal @@ -9,7 +9,7 @@ description: that cannot be written in Haskell itself. license: BSD-3-Clause maintainer: glasgow-haskell-users@haskell.org -build-type: Configure +build-type: Custom extra-source-files: configure @@ -325,6 +325,10 @@ flag thread-sanitizer default: False manual: True +custom-setup + setup-depends: + base, Cabal, Cabal-syntax, mtl, transformers + library -- rts is a wired in package and -- expects the unit-id to be From 64db5c658556b73c7b20dfc82570b9e19422fcfc Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Sat, 1 Mar 2025 00:22:49 +0800 Subject: [PATCH 36/84] WIP --- .github/workflows/ci-cabal-install.yml | 11 ++- Makefile | 97 ++++++++++++++------------ cabal.project.stage1-boot | 3 - cabal.project.stage1-rts | 6 ++ hie.yaml | 13 ++++ rts/Setup.hs | 20 ++++-- rts/configure.ac | 62 ---------------- rts/include/ghcautoconf.h.in | 18 ----- rts/rts.cabal | 2 +- 9 files changed, 91 insertions(+), 141 deletions(-) diff --git a/.github/workflows/ci-cabal-install.yml b/.github/workflows/ci-cabal-install.yml index 1fa831e8f19a..313d7aa5dbb7 100644 --- a/.github/workflows/ci-cabal-install.yml +++ b/.github/workflows/ci-cabal-install.yml @@ -76,16 +76,13 @@ jobs: with: key: build-${{ matrix.os }}-${{ matrix.ghc }}-${{ github.run_id }} restore-keys: build-${{ matrix.os }}-${{ matrix.ghc }}- - path: _build _stage0 _stage1 + path: _build _stage0 _stage1 _stage1-rts _stage1-boot - name: Update Hackage index run: cabal update - - name: Build stage1 - run: make stage1 - - - name: Build stage1-rts - run: make stage1-rts + - name: Build + run: make - name: Upload artifacts uses: actions/upload-artifact@v4 @@ -98,7 +95,7 @@ jobs: if: always() with: key: build-${{ matrix.os }}-${{ matrix.ghc }}-${{ github.run_id }} - path: _build _stage0 _stage1 + path: _build _stage0 _stage1 _stage1-rts _stage1-boot - name: Save cabal store uses: actions/cache/save@v4 diff --git a/Makefile b/Makefile index 75803af5ff34..1a1bdf5e867e 100644 --- a/Makefile +++ b/Makefile @@ -5,9 +5,11 @@ SHELL := bash MAKEFLAGS += --warn-undefined-variables MAKEFLAGS += --no-builtin-rules +all: stage1-boot + CABAL0 ?= cabal CABAL ?= _stage0/bin/cabal -GHC ?= ghc +GHC0 ?= ghc define LIB = BOLD_RED='\033[1;31m' @@ -76,56 +78,65 @@ _stage1/lib/settings: _stage1/bin/ghc-toolchain-bin stage1: _stage1/bin/ghc _stage1/lib/settings -# -# TODO: We cannot build the rts with cabal-install because we are passing -# to deriveConstants the headers in rts-headers via a relative path. -# cabal-install's install command makes a source distribution before building -# and this breaks the relative path. The solution is to move the call to -# derivedConstants into Setup.hs where we have access to the installed -# packagedb. I had a version of this then it looked too complex and I moved back -# to configure.ac. -# -# stage1-rts: CABAL = _stage0/bin/cabal -# stage1-rts: GHC = $(abspath _stage1/bin/ghc) -# stage1-rts: OUT ?= $(abspath _stage1-rts) -# stage1-rts: _stage0/bin/cabal _stage1/bin/ghc _stage1/bin/deriveConstants _stage1/bin/genapply rts/configure -# @$(LIB) -# # for rts/configure -# export DERIVE_CONSTANTS=$(abspath _stage1/bin/deriveConstants) -# export GENAPPLY=$(abspath _stage1/bin/genapply) -# log $(CABAL_INSTALL) --lib --package-env $(OUT) --project-file cabal.project.stage1-rts all - -stage1-rts: CABAL = _stage0/bin/cabal -stage1-rts: CABAL_CONFIG_FLAGS += --with-compiler $(abspath _stage1/bin/ghc) -stage1-rts: CABAL_CONFIG_FLAGS += --prefix $(OUT) -stage1-rts: CABAL_CONFIG_FLAGS += --package-db $(OUT)/lib/package.conf.d -stage1-rts: OUT ?= $(abspath _stage1-rts) -stage1-rts: _stage0/bin/cabal-main-simple _stage0/bin/cabal-main-configure _stage1/bin/ghc _stage1/bin/deriveConstants _stage1/bin/genapply rts/configure +_stage1-rts/lib/package.conf.d/rts-fs-1.0.0.0.conf: _stage0/bin/cabal-main-simple @$(LIB) - mkdir -p $(OUT)/lib/package.conf.d - - # for rts/configure - export DERIVE_CONSTANTS=$(abspath _stage1/bin/deriveConstants) - export GENAPPLY=$(abspath _stage1/bin/genapply) + mkdir -p "$(@D)/lib/package.conf.d" pushd rts-fs || exit - log ../_stage0/bin/cabal-main-simple configure --builddir "$(OUT)/dist/rts-fs" $(CABAL_CONFIG_FLAGS) + log ../_stage0/bin/cabal-main-simple configure --builddir "$(OUT)/dist/rts-fs" $(CABAL_CONFIG_FLAGS) --ipid=$(notdir $(@:%.conf=%)) log ../_stage0/bin/cabal-main-simple build --builddir "$(OUT)/dist/rts-fs" log ../_stage0/bin/cabal-main-simple install --builddir "$(OUT)/dist/rts-fs" popd +_stage1-rts/lib/package.conf.d/rts-headers-1.0.0.0.conf: _stage0/bin/cabal-main-simple + @$(LIB) + mkdir -p "$(@D)" + pushd rts-headers || exit - log ../_stage0/bin/cabal-main-simple configure --builddir "$(OUT)/dist/rts-headers" $(CABAL_CONFIG_FLAGS) + log ../_stage0/bin/cabal-main-simple configure --builddir "$(OUT)/dist/rts-headers" $(CABAL_CONFIG_FLAGS) --ipid=$(notdir $(@:%.conf=%)) log ../_stage0/bin/cabal-main-simple build --builddir "$(OUT)/dist/rts-headers" log ../_stage0/bin/cabal-main-simple install --builddir "$(OUT)/dist/rts-headers" popd +# NOTE: The bootstrap is particularly annoying in this step. +# +# rts has a custom config so we need a Cabal to compile Setup.hs, but we cannot +# use the new compiler (not even stage1) for this because we do not have the rts +# yet (as we are just preparing to build it). +# +# We cut the know by using the version of Cabal we had built with the stage0 compiler. +# NOTE: the requirement _stage0/bin/cabal is representative of the fact that we had built the library +# + +# _stage0/bin/cabal as evidence that we have build cabal +_stage1-rts/dist/rts/Setup: .EXTRA_PREREQS=_stage0/bin/cabal +_stage1-rts/dist/rts/Setup: rts/Setup.hs + @$(LIB) + # FIXME I am using the store as a package db, its path is not quite fixed as it + # relies on the bootstrap compiler id + mkdir -p $(@D) + log $(GHC0) -clear-package-db -global-package-db -package-db _stage0/store/*/package.db -o $@ $< + +_stage1-rts/lib/package.conf.d/rts-1.0.0.0.conf: _stage1/bin/ghc rts/configure _stage1-rts/lib/package.conf.d/rts-fs-1.0.0.0.conf _stage1-rts/lib/package.conf.d/rts-headers-1.0.0.0.conf _stage1-rts/dist/rts/Setup _stage1/bin/deriveConstants _stage1/bin/genapply + @$(LIB) + mkdir -p "$(@D)/lib/package.conf.d" + + # for rts setup to find derivedConstants and genApply + export PATH=$(abspath _stage1/bin):$$PATH + pushd rts || exit - log ../_stage0/bin/cabal-main-configure configure --builddir "$(OUT)/dist/rts" $(CABAL_CONFIG_FLAGS) - log ../_stage0/bin/cabal-main-configure build --builddir "$(OUT)/dist/rts" - log ../_stage0/bin/cabal-main-configure install --builddir "$(OUT)/dist/rts" + log ../_stage1-rts/dist/rts/Setup configure --builddir "$(OUT)/dist/rts" $(CABAL_CONFIG_FLAGS) --ipid=$(notdir $(@:%.conf=%)) + log ../_stage1-rts/dist/rts/Setup build --builddir "$(OUT)/dist/rts" + log ../_stage1-rts/dist/rts/Setup install --builddir "$(OUT)/dist/rts" popd +stage1-rts: GHC = _stage1/bin/ghc +stage1-rts: CABAL_CONFIG_FLAGS += -v --with-compiler $(abspath _stage1/bin/ghc) +stage1-rts: CABAL_CONFIG_FLAGS += --prefix $(OUT) +stage1-rts: CABAL_CONFIG_FLAGS += --package-db $(OUT)/lib/package.conf.d +stage1-rts: OUT ?= $(abspath _stage1-rts) +stage1-rts: $(addprefix _stage1-rts/lib/package.conf.d/,rts-1.0.0.0.conf rts-fs-1.0.0.0.conf rts-headers-1.0.0.0.conf) + _stage1-boot/src/compiler/GHC/Builtin/primops.txt: compiler/GHC/Builtin/primops.txt.pp @$(LIB) mkdir -p $(@D) @@ -147,12 +158,13 @@ _stage1-boot/src/ghc-internal/src/GHC/Internal/PrimopWrappers.hs: _stage1-boot/s mkdir -p $(@D) log _stage1/bin/genprimopcode --make-haskell-wrappers < $< > $@ -_stage1-boot/src/ghc-internal/.stamp: _stage1-boot/src/ghc-internal/ghc-internal.cabal -_stage1-boot/src/ghc-internal/.stamp: _stage1-boot/src/ghc-internal/src/GHC/Internal/Prim.hs -_stage1-boot/src/ghc-internal/.stamp: _stage1-boot/src/ghc-internal/src/GHC/Internal/PrimopWrappers.hs +_stage1-boot/src/ghc-internal/.ready: _stage1-boot/src/ghc-internal/ghc-internal.cabal +_stage1-boot/src/ghc-internal/.ready: _stage1-boot/src/ghc-internal/src/GHC/Internal/Prim.hs +_stage1-boot/src/ghc-internal/.ready: _stage1-boot/src/ghc-internal/src/GHC/Internal/PrimopWrappers.hs +_stage1-boot/src/ghc-internal/.ready: _stage1-boot/src/ghc-internal/configure # targets -STAGE1_BOOT_TARGETS = rts ghc-internal ghc-experimental ghc-compact base stm system-cxx-std-lib +STAGE1_BOOT_TARGETS = ghc-internal ghc-experimental ghc-compact base stm system-cxx-std-lib # shallow compat packages over ghc-internal STAGE1_BOOT_TARGETS += ghc-prim ghc-bignum integer-gmp template-haskell # target dependencies @@ -167,10 +179,9 @@ STAGE1_BOOT_TARGETS += ghc-boot ghc-heap ghc-platform ghc-toolchain ghci ghc stage1-boot: CABAL = _stage0/bin/cabal stage1-boot: GHC = $(abspath _stage1/bin/ghc) stage1-boot: OUT ?= $(abspath _stage1-boot) -stage1-boot: _stage0/bin/cabal _stage1/bin/ghc _stage1-boot/src/ghc-internal/.stamp _stage1-boot/src/ghc-internal/configure +stage1-boot: _stage0/bin/cabal _stage1/bin/ghc _stage1-boot/src/ghc-internal/.ready stage1-rts @$(LIB) # for rts/configure export DERIVE_CONSTANTS=$(abspath _stage1/bin/deriveConstants) export GENAPPLY=$(abspath _stage1/bin/genapply) - log $(CABAL_INSTALL) --lib --package-env $(OUT) --project-file cabal.project.stage1-boot $(STAGE1_BOOT_TARGETS) - + log $(CABAL_INSTALL) --lib --package-db=$(abspath _stage1-rts/lib/package.conf.d) --package-env $(OUT) --project-file cabal.project.stage1-boot Cabal diff --git a/cabal.project.stage1-boot b/cabal.project.stage1-boot index 7167b6ccaa26..e345b5fe8397 100644 --- a/cabal.project.stage1-boot +++ b/cabal.project.stage1-boot @@ -7,9 +7,6 @@ tests: False packages: ./compiler ./ghc - ./rts - ./rts-headers - ./rts-fs ./libraries/array ./libraries/base ./libraries/binary diff --git a/cabal.project.stage1-rts b/cabal.project.stage1-rts index c667a87c9c9c..f056d7cffc34 100644 --- a/cabal.project.stage1-rts +++ b/cabal.project.stage1-rts @@ -1,3 +1,9 @@ +allow-boot-library-installs: True +-- active-repositories: :none + +benchmarks: False +tests: False + packages: rts rts-fs diff --git a/hie.yaml b/hie.yaml index 91c6758cca54..b80d4d764cb5 100644 --- a/hie.yaml +++ b/hie.yaml @@ -12,6 +12,19 @@ cradle: cradle: direct: arguments: [] + - path: ./rts/Setup.hs + config: + cradle: + direct: + arguments: + - -clear-package-db + - -global-package-db + - -package-db _stage0/store/ghc-9.8.4-6626/package.db + # - -package base + # - -package Cabal + # - -package Cabal-syntax + # - -package mtl + # - -package transformers - path: . config: cradle: {bios: {program: "./hadrian/hie-bios"}} diff --git a/rts/Setup.hs b/rts/Setup.hs index e6647cb67268..fe5cdf3af8da 100644 --- a/rts/Setup.hs +++ b/rts/Setup.hs @@ -10,7 +10,10 @@ import Distribution.Types.BuildInfo as BI import Distribution.Types.InstalledPackageInfo as IPI import Distribution.Types.Library import Distribution.Types.PackageDescription +import Distribution.Utils.Path (interpretSymbolicPathCWD, (), makeRelativePathEx) import Distribution.Verbosity (normal) +import System.Directory (getCurrentDirectory) +import System.Info (os) nmProgram :: Program nmProgram = simpleProgram "nm" @@ -27,9 +30,10 @@ main = autoconfUserHooks { postConf = \args flags pd lbi -> do postConf autoconfUserHooks args flags pd lbi - + let verbosity = fromFlagOrDefault normal (configVerbosity flags) - let progdb = withPrograms lbi + progdb = withPrograms lbi + (nm, _progdb) <- requireProgram verbosity nmProgram progdb (objdump, _progdb) <- requireProgram verbosity objdumpProgram progdb (gcc, _progdb) <- requireProgram verbosity gccProgram progdb @@ -48,13 +52,13 @@ main = , incdir <- IPI.includeDirs ipi ] - + getCurrentDirectory >>= putStrLn runProgram verbosity deriveConstants $ [ "--gen-header" , "-o" - , "include/DerivedConstants.h" + , interpretSymbolicPathCWD (buildDir lbi makeRelativePathEx "include/DerivedConstants.h") , "--target-os" - , "linux" + , os , "--gcc-program" , programPath gcc , "--nm-program" @@ -62,8 +66,10 @@ main = , "--objdump-program" , programPath objdump , "--tmpdir" - , buildDir lbi + , interpretSymbolicPathCWD (buildDir lbi) + , "--gcc-flag" + , "-I" ++ interpretSymbolicPathCWD (buildDir lbi makeRelativePathEx "include") ] - ++ foldMap (\i -> ["--gcc-flag", "-I" ++ i]) thisIncDirs + ++ foldMap ((\i -> ["--gcc-flag", "-I" ++ i]) . interpretSymbolicPathCWD) thisIncDirs ++ foldMap (\incdir -> ["--gcc-flag", "-I" ++ incdir]) depsIncDirs } diff --git a/rts/configure.ac b/rts/configure.ac index 113ee1a01215..dd571759fe71 100644 --- a/rts/configure.ac +++ b/rts/configure.ac @@ -511,68 +511,6 @@ fi rm -rf "$TEMP_FILE" -dnl -------------------------------------------------------------- -dnl Generate derived constants -dnl -------------------------------------------------------------- - -AC_ARG_VAR([NM], [Path to the nm program]) -AC_PATH_PROG([NM], nm) -if test -z "$NM"; then - AC_MSG_ERROR([Cannot find nm]) -fi - -AC_ARG_VAR([OBJDUMP], [Path to the objdump program]) -AC_PATH_PROG([OBJDUMP], objdump) -if test -z "$OBJDUMP"; then - AC_MSG_ERROR([Cannot find objdump]) -fi - -AC_ARG_VAR([DERIVE_CONSTANTS], [Path to the deriveConstants program]) -AC_PATH_PROG([DERIVE_CONSTANTS], deriveConstants) -if test -z "$DERIVE_CONSTANTS"; then - AC_MSG_ERROR([Cannot find deriveConstants]) -fi - -AC_CONFIG_COMMANDS([DerivedConstants.h],[ - dnl NOTE: dnl pass `-fcommon` to force symbols into the common section. If they end - dnl up in the ro data section `nm` won't list their size, and thus derivedConstants - dnl will fail. Recent clang (e.g. 16) will by default use `-fno-common`. - dnl - dnl FIXME: using a relative path here is TERRIBLE - dnl - $DERIVE_CONSTANTS \ - --gen-header \ - -o include/DerivedConstants.h \ - --target-os "$BuildOS_CPP" \ - --gcc-program "$CC" \ - --nm-program "$NM" \ - --objdump-program "$OBJDUMP" \ - --tmpdir "$PWD" \ - --gcc-flag "-Iinclude" \ - --gcc-flag "-I$srcdir" \ - --gcc-flag "-I$srcdir/include" \ - --gcc-flag "-I$srcdir/../rts-headers/include" -],[ - BuildOS_CPP=$BuildOS_CPP - CC=$CC - DERIVE_CONSTANTS=$DERIVE_CONSTANTS - NM=$NM - OBJDUMP=$OBJDUMP -]) - -AC_ARG_VAR([GENAPPLY], [Path to the genapply program]) -AC_PATH_PROG([GENAPPLY], genapply) -if test -z "$GENAPPLY"; then - AC_MSG_ERROR([Cannot find genapply]) -fi - -AC_CONFIG_COMMANDS([AutoApply.h],[ - $GENAPPLY include/DerivedConstants.h > AutoApply.cmm - $GENAPPLY include/DerivedConstants.h -V16 > AutoApply_V16.cmm - $GENAPPLY include/DerivedConstants.h -V32 > AutoApply_V32.cmm - $GENAPPLY include/DerivedConstants.h -V64 > AutoApply_V64.cmm -],[GENAPPLY=$GENAPPLY]) - dnl -------------------------------------------------------------- dnl ** Write config files dnl -------------------------------------------------------------- diff --git a/rts/include/ghcautoconf.h.in b/rts/include/ghcautoconf.h.in index c5c9e50380d6..306a20c29c9c 100644 --- a/rts/include/ghcautoconf.h.in +++ b/rts/include/ghcautoconf.h.in @@ -444,24 +444,6 @@ /* Define to 1 if we need -latomic for sub-word atomic operations. */ #undef NEED_ATOMIC_LIB -/* Define to the address where bug reports for this package should be sent. */ -#undef PACKAGE_BUGREPORT - -/* Define to the full name of this package. */ -#undef PACKAGE_NAME - -/* Define to the full name and version of this package. */ -#undef PACKAGE_STRING - -/* Define to the one symbol short name of this package. */ -#undef PACKAGE_TARNAME - -/* Define to the home page for this package. */ -#undef PACKAGE_URL - -/* Define to the version of this package. */ -#undef PACKAGE_VERSION - /* Version of GHC used to build this RTS */ #undef ProjectVersion diff --git a/rts/rts.cabal b/rts/rts.cabal index 9a7c1d49532b..d68ebb8c4a14 100644 --- a/rts/rts.cabal +++ b/rts/rts.cabal @@ -348,6 +348,7 @@ library ghcautoconf.h ghcplatform.h DerivedConstants.h + stg/MachRegsForHost.h if arch(javascript) @@ -384,7 +385,6 @@ library install-includes: HsFFI.h MachDeps.h Rts.h RtsAPI.h Stg.h ghcconfig.h ghcplatform.h - stg/MachRegsForHost.h stg/Types.h else From 8dd977e308784121f480c4f8625b5e557522b04f Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Sat, 1 Mar 2025 00:28:10 +0800 Subject: [PATCH 37/84] ci: remove ci.yml --- .github/workflows/ci.yml | 124 --------------------------------------- 1 file changed, 124 deletions(-) delete mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index d1b141e44879..000000000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,124 +0,0 @@ -name: CI - -# Trigger the workflow on push or pull request, but only for the master branch -on: - pull_request: - types: - - opened - - synchronize - push: - branches: [master] - -jobs: - cabal: - name: ${{ matrix.os }} / ghc ${{ matrix.ghc }} - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest] - ghc: ['9.8.4'] # bootstrapping compiler - - steps: - - uses: actions/checkout@v4 - with: - submodules: "recursive" - - - uses: haskell/ghcup-setup@v1 - - - id: ghcup - run: | - ghcup config set cache true - echo "basedir=$(ghcup whereis basedir)" >> $GITHUB_OUTPUT - - - id: ghcup-cache - name: Cache GHCup basedir - uses: actions/cache@v4 - with: - key: ghcup-basedir-${{ github.run_id }} - restore-keys: ghcup-basedir- - path: ${{ steps.ghcup.outputs.basedir }} - - - run: | - ghcup install ghc --set ${{ matrix.ghc }} - ghcup install cabal --set - - - id: cabal-paths - run: | - cabal user-config init - echo "store=$(cabal path --store-dir)" >> $GITHUB_OUTPUT - echo "remote-repo-cache=$(cabal path --remote-repo-cache)" >> $GITHUB_OUTPUT - - - name: Restore Hackage index - uses: actions/cache/restore@v4 - with: - key: hackage-${{ github.run_id }} - restore-keys: hackage- - path: ${{ steps.cabal-paths.outputs.remote-repo-cache }} - - - run: cabal update - - - name: Restore build artifacts - uses: actions/cache/restore@v4 - with: - key: ${{ matrix.os }}-${{ matrix.ghc }}-${{ github.run_id }} - restore-keys: ${{ matrix.os }}-${{ matrix.ghc }}- - path: | - ${{ steps.cabal-paths.outputs.store }} - libraries/Cabal/dist-newstyle - _build - - - name: Build patched cabal - run: make -f Makefile.orig cabal - - - # This runs autoconf also in the subdirectories - run: autoreconf -v - - - name: Build the bindist - env: - CC: gcc - CXX: g++ - run: make -f Makefile.orig - - - name: Upload artifacts - uses: actions/upload-artifact@v4 - with: - name: bindist - path: _build/bindist - - - name: Run the testsuite - run: make test - - - name: Upload test results - uses: actions/upload-artifact@v4 - if: ${{ !cancelled() }} # upload test results even if the testsuite failed to pass - with: - name: testsuite-results - path: | - _build/test-perf.csv - _build/test-summary.txt - _build/test-junit.xml - - - name: Save GHCup cache - uses: actions/cache/save@v4 - if: always() - with: - key: ghcup-${{ github.run_id }} - path: ${{ steps.ghcup.outputs.cachedir }} - - - name: Save Hackage index - uses: actions/cache/save@v4 - if: always() - with: - key: hackage-${{ github.run_id }} - path: ${{ steps.cabal-paths.outputs.remote-repo-cache }} - - - name: Save build artifacts - if: always() - uses: actions/cache/save@v4 - with: - key: ${{ matrix.os }}-${{ matrix.ghc }}-${{ github.run_id }} - path: | - ${{ steps.cabal-paths.outputs.store }} - libraries/Cabal/dist-newstyle - _build From 4a41678385d85d7f99c85b2c323f9f34afecbbf9 Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Sat, 1 Mar 2025 00:34:04 +0800 Subject: [PATCH 38/84] WIP --- Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 1a1bdf5e867e..6be22bf01aaa 100644 --- a/Makefile +++ b/Makefile @@ -45,6 +45,7 @@ CABAL_EXE = cabal cabal-main-simple cabal-main-configure CABAL_BIN = $(addprefix _stage0/bin/,$(CABAL_EXE)) $(CABAL_BIN) &: OUT ?= $(abspath _stage0) +$(CABAL_BIN) &: override GHC=$(GHC0) $(CABAL_BIN) &: CABAL=$(CABAL0) $(CABAL_BIN) &: @$(LIB) @@ -55,6 +56,7 @@ STAGE1_EXE = ghc ghc-toolchain-bin deriveConstants genprimopcode genapply STAGE1_BIN = $(addprefix _stage1/bin/,$(STAGE1_EXE)) $(STAGE1_BIN) &: OUT ?= $(abspath _stage1) +$(STAGE1_BIN) &: override GHC=$(GHC0) $(STAGE1_BIN) &: $(CABAL) @$(LIB) log mkdir -p $(@D) @@ -130,8 +132,8 @@ _stage1-rts/lib/package.conf.d/rts-1.0.0.0.conf: _stage1/bin/ghc rts/configure _ log ../_stage1-rts/dist/rts/Setup install --builddir "$(OUT)/dist/rts" popd -stage1-rts: GHC = _stage1/bin/ghc -stage1-rts: CABAL_CONFIG_FLAGS += -v --with-compiler $(abspath _stage1/bin/ghc) +stage1-rts: GHC = $(abspath _stage1/bin/ghc) +stage1-rts: CABAL_CONFIG_FLAGS += -v --with-compiler $(GHC) stage1-rts: CABAL_CONFIG_FLAGS += --prefix $(OUT) stage1-rts: CABAL_CONFIG_FLAGS += --package-db $(OUT)/lib/package.conf.d stage1-rts: OUT ?= $(abspath _stage1-rts) From 904621f3f018a78b0434aeb2d491c27c21a2e384 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Sat, 1 Mar 2025 11:52:47 +0900 Subject: [PATCH 39/84] We need `-fcommon`. --- rts/Setup.hs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rts/Setup.hs b/rts/Setup.hs index fe5cdf3af8da..bf494ed31a5d 100644 --- a/rts/Setup.hs +++ b/rts/Setup.hs @@ -69,6 +69,11 @@ main = , interpretSymbolicPathCWD (buildDir lbi) , "--gcc-flag" , "-I" ++ interpretSymbolicPathCWD (buildDir lbi makeRelativePathEx "include") + -- pass `-fcommon` to force symbols into the common section. If they + -- end up in the ro data section `nm` won't list their size, and thus + -- derivedConstants will fail. Recent clang (e.g. 16) will by default + -- use `-fno-common`. + , "--gcc-flag", "-fcommon" ] ++ foldMap ((\i -> ["--gcc-flag", "-I" ++ i]) . interpretSymbolicPathCWD) thisIncDirs ++ foldMap (\incdir -> ["--gcc-flag", "-I" ++ incdir]) depsIncDirs From 9e1901830908196b20b339b397dd957363975138 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Sat, 1 Mar 2025 17:58:28 +0900 Subject: [PATCH 40/84] Adding HADRIAN_SETTINGS. --- HADRIAN_SETTINGS | 7 +++++++ Makefile | 1 + 2 files changed, 8 insertions(+) create mode 100644 HADRIAN_SETTINGS diff --git a/HADRIAN_SETTINGS b/HADRIAN_SETTINGS new file mode 100644 index 000000000000..db71ed753b0c --- /dev/null +++ b/HADRIAN_SETTINGS @@ -0,0 +1,7 @@ +[ ("cProjectGitCommitId", "0000000000000000000000000000000000000000") +, ("cProjectVersion", "9.13") +, ("cProjectVersionInt", "913") +, ("cProjectPatchLevel", "0") +, ("cProjectPatchLevel1", "0") +, ("cProjectPatchLevel2", "0") +] \ No newline at end of file diff --git a/Makefile b/Makefile index 6be22bf01aaa..ef720e6c6ec5 100644 --- a/Makefile +++ b/Makefile @@ -60,6 +60,7 @@ $(STAGE1_BIN) &: override GHC=$(GHC0) $(STAGE1_BIN) &: $(CABAL) @$(LIB) log mkdir -p $(@D) + export HADRIAN_SETTINGS=$(abspath HADRIAN_SETTINGS) log $(CABAL_INSTALL) --project-file cabal.project.stage1 $(addprefix exe:,$(STAGE1_EXE)) TARGET := $(shell cc -dumpmachine) From 5b55c2bb26d809ceb31c36a51409e9073045e12d Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Sat, 1 Mar 2025 17:59:46 +0900 Subject: [PATCH 41/84] Fixup ghcversion.h generation All of these are strings. show will add extra quotes. Thus leading to __GLASGOW_HASKELL__ being "" (including the quotes, and any comparions will fail as we are comparing "XYZ" < ABC. --- compiler/GHC/SysTools/Cpp.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/GHC/SysTools/Cpp.hs b/compiler/GHC/SysTools/Cpp.hs index 0059d2122781..810ad4e75160 100644 --- a/compiler/GHC/SysTools/Cpp.hs +++ b/compiler/GHC/SysTools/Cpp.hs @@ -268,7 +268,7 @@ getGhcVersionIncludeFlags dflags logger tmpfs = do -- the user has provided an explicit `ghcversion.h` file to use. Just path -> do found <- doesFileExist path - unless found $ + unless found $ throwGhcExceptionIO (InstallationError ("ghcversion.h missing; tried: " ++ path)) return ["-include", path] Nothing -> do @@ -282,11 +282,11 @@ getGhcVersionIncludeFlags dflags logger tmpfs = do ghcVersionH :: String ghcVersionH = concat - ["#define __GLASGOW_HASKELL__ ", show cProjectVersionInt, "\n" - ,"#define __GLASGOW_HASKELL_FULL_VERSION__ ", show cProjectVersion, "\n" + ["#define __GLASGOW_HASKELL__ ", cProjectVersionInt, "\n" + ,"#define __GLASGOW_HASKELL_FULL_VERSION__ \"", cProjectVersion, "\"\n" ,"\n" - ,"#define __GLASGOW_HASKELL_PATCHLEVEL1__ ", show cProjectPatchLevel1, "\n" - ,"#define __GLASGOW_HASKELL_PATCHLEVEL2__ ", show cProjectPatchLevel2, "\n" + ,"#define __GLASGOW_HASKELL_PATCHLEVEL1__ ", cProjectPatchLevel1, "\n" + ,"#define __GLASGOW_HASKELL_PATCHLEVEL2__ ", cProjectPatchLevel2, "\n" ,"\n" ,"#define MIN_VERSION_GLASGOW_HASKELL(ma,mi,pl1,pl2) ( \\\n" ," ((ma)*100+(mi)) < __GLASGOW_HASKELL__ || \\\n" From b65ea4b9b882389659e40251c61887b0403f659e Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Sat, 1 Mar 2025 20:19:11 +0900 Subject: [PATCH 42/84] fixup! Adding HADRIAN_SETTINGS. --- HADRIAN_SETTINGS | 4 +++- Makefile | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/HADRIAN_SETTINGS b/HADRIAN_SETTINGS index db71ed753b0c..5256177d6c0c 100644 --- a/HADRIAN_SETTINGS +++ b/HADRIAN_SETTINGS @@ -1,4 +1,6 @@ -[ ("cProjectGitCommitId", "0000000000000000000000000000000000000000") +[ ("hostPlatformArch", "ArchAArch64") +, ("hostPlatformOS", "OSDarwin") +, ("cProjectGitCommitId", "0000000000000000000000000000000000000000") , ("cProjectVersion", "9.13") , ("cProjectVersionInt", "913") , ("cProjectPatchLevel", "0") diff --git a/Makefile b/Makefile index ef720e6c6ec5..c3e1b6762dac 100644 --- a/Makefile +++ b/Makefile @@ -60,7 +60,7 @@ $(STAGE1_BIN) &: override GHC=$(GHC0) $(STAGE1_BIN) &: $(CABAL) @$(LIB) log mkdir -p $(@D) - export HADRIAN_SETTINGS=$(abspath HADRIAN_SETTINGS) + log export HADRIAN_SETTINGS="$$(cat ./HADRIAN_SETTINGS)" log $(CABAL_INSTALL) --project-file cabal.project.stage1 $(addprefix exe:,$(STAGE1_EXE)) TARGET := $(shell cc -dumpmachine) From 78d1f26628059e7ef055da7a4329c71e221daf84 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Sun, 2 Mar 2025 12:11:41 +0900 Subject: [PATCH 43/84] Allow the rts to have dependencies. --- compiler/GHC/Linker/ExtraObj.hs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/compiler/GHC/Linker/ExtraObj.hs b/compiler/GHC/Linker/ExtraObj.hs index a26a31eed7c3..db0fe4f2ab1d 100644 --- a/compiler/GHC/Linker/ExtraObj.hs +++ b/compiler/GHC/Linker/ExtraObj.hs @@ -63,8 +63,17 @@ mkExtraObj logger tmpfs dflags unit_state extn xs -- we're compiling C or assembler. When compiling C, we pass the usual -- set of include directories and PIC flags. cOpts = map Option (picCCOpts dflags) - ++ map (FileOption "-I" . ST.unpack) - (unitIncludeDirs $ unsafeLookupUnit unit_state rtsUnit) + ++ map (FileOption "-I") + (collectIncludeDirs $ depClosure unit_state [unsafeLookupUnit unit_state rtsUnit]) + depClosure :: UnitState -> [UnitInfo] -> [UnitInfo] + depClosure us initial = go [] initial + where + go seen [] = seen + go seen (ui:uis) + | ui `elem` seen = go seen uis + | otherwise = + let deps = map (unsafeLookupUnitId us) (unitDepends ui) + in go (ui:seen) (deps ++ uis) -- When linking a binary, we need to create a C main() function that -- starts everything off. This used to be compiled statically as part From 9dcb67a278c0b6e2fb18268c7a26c553885cce65 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Sun, 2 Mar 2025 12:20:12 +0900 Subject: [PATCH 44/84] Depend on settings for the rts (for now) --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c3e1b6762dac..70721612c90f 100644 --- a/Makefile +++ b/Makefile @@ -120,7 +120,7 @@ _stage1-rts/dist/rts/Setup: rts/Setup.hs mkdir -p $(@D) log $(GHC0) -clear-package-db -global-package-db -package-db _stage0/store/*/package.db -o $@ $< -_stage1-rts/lib/package.conf.d/rts-1.0.0.0.conf: _stage1/bin/ghc rts/configure _stage1-rts/lib/package.conf.d/rts-fs-1.0.0.0.conf _stage1-rts/lib/package.conf.d/rts-headers-1.0.0.0.conf _stage1-rts/dist/rts/Setup _stage1/bin/deriveConstants _stage1/bin/genapply +_stage1-rts/lib/package.conf.d/rts-1.0.0.0.conf: _stage1/lib/settings _stage1/bin/ghc rts/configure _stage1-rts/lib/package.conf.d/rts-fs-1.0.0.0.conf _stage1-rts/lib/package.conf.d/rts-headers-1.0.0.0.conf _stage1-rts/dist/rts/Setup _stage1/bin/deriveConstants _stage1/bin/genapply @$(LIB) mkdir -p "$(@D)/lib/package.conf.d" From 9babaeefd86bad8bfafb5c86d7e90e084af0f60a Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Sun, 2 Mar 2025 12:20:38 +0900 Subject: [PATCH 45/84] We need ghc-pkg --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 70721612c90f..2aaf3cf86d7f 100644 --- a/Makefile +++ b/Makefile @@ -52,7 +52,7 @@ $(CABAL_BIN) &: log mkdir -p $(@D) log $(CABAL_INSTALL) --project-dir libraries/Cabal --project-file cabal.release.project $(addprefix exe:,$(CABAL_EXE)) -STAGE1_EXE = ghc ghc-toolchain-bin deriveConstants genprimopcode genapply +STAGE1_EXE = ghc ghc-pkg ghc-toolchain-bin deriveConstants genprimopcode genapply STAGE1_BIN = $(addprefix _stage1/bin/,$(STAGE1_EXE)) $(STAGE1_BIN) &: OUT ?= $(abspath _stage1) @@ -135,6 +135,8 @@ _stage1-rts/lib/package.conf.d/rts-1.0.0.0.conf: _stage1/lib/settings _stage1/bi stage1-rts: GHC = $(abspath _stage1/bin/ghc) stage1-rts: CABAL_CONFIG_FLAGS += -v --with-compiler $(GHC) +stage1-rts: GHCPKG = $(abspath _stage1/bin/ghc-pkg) +stage1-rts: CABAL_CONFIG_FLAGS += --with-hc-pkg $(GHCPKG) stage1-rts: CABAL_CONFIG_FLAGS += --prefix $(OUT) stage1-rts: CABAL_CONFIG_FLAGS += --package-db $(OUT)/lib/package.conf.d stage1-rts: OUT ?= $(abspath _stage1-rts) From db90da3bd7cefbb375d2697729f3aad36b52a104 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Sun, 2 Mar 2025 13:38:48 +0900 Subject: [PATCH 46/84] Build in parallel --- cabal.project.stage1 | 3 +++ cabal.project.stage1-boot | 2 ++ cabal.project.stage1-rts | 3 +++ cabal.project.stage2 | 3 +++ 4 files changed, 11 insertions(+) diff --git a/cabal.project.stage1 b/cabal.project.stage1 index 6db48ef9bb09..e97e5e086545 100644 --- a/cabal.project.stage1 +++ b/cabal.project.stage1 @@ -51,3 +51,6 @@ allow-newer: ghc-boot-th constraints: -- FIXME: template-haskell 2.23 is too recent when booting with 9.8.4 template-haskell <= 2.22 + +program-options + ghc-options: -fhide-source-paths -j \ No newline at end of file diff --git a/cabal.project.stage1-boot b/cabal.project.stage1-boot index e345b5fe8397..3188b7c89361 100644 --- a/cabal.project.stage1-boot +++ b/cabal.project.stage1-boot @@ -84,3 +84,5 @@ package text -- FIXME: avoid having to deal with system-cxx-std-lib fake package for now flags: -simdutf +program-options + ghc-options: -fhide-source-paths -j \ No newline at end of file diff --git a/cabal.project.stage1-rts b/cabal.project.stage1-rts index f056d7cffc34..db4f2f7d6b72 100644 --- a/cabal.project.stage1-rts +++ b/cabal.project.stage1-rts @@ -8,3 +8,6 @@ packages: rts rts-fs rts-headers + +program-options + ghc-options: -fhide-source-paths -j \ No newline at end of file diff --git a/cabal.project.stage2 b/cabal.project.stage2 index 4dbec5feb898..87382021c69d 100644 --- a/cabal.project.stage2 +++ b/cabal.project.stage2 @@ -30,3 +30,6 @@ package ghc-bin package hsc2hs flags: +in-ghc-tree + +program-options + ghc-options: -fhide-source-paths -j \ No newline at end of file From eb9aeca4302e48a5717eb02c3ce774530f918323 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Sun, 2 Mar 2025 21:03:04 +0900 Subject: [PATCH 47/84] bump cabal reference --- libraries/Cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/Cabal b/libraries/Cabal index 513461732740..367c5c61c361 160000 --- a/libraries/Cabal +++ b/libraries/Cabal @@ -1 +1 @@ -Subproject commit 51346173274055d3e4085eb1a7162837d22b4845 +Subproject commit 367c5c61c361bf4b4d814eeff494d322840e64cb From 39957fb35fbe7ab810965ca301f026109d04a976 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Mon, 3 Mar 2025 08:39:59 +0900 Subject: [PATCH 48/84] Add genapply to the rts:Setup --- rts/Setup.hs | 21 +++++++++++++++++++-- rts/rts.cabal | 2 +- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/rts/Setup.hs b/rts/Setup.hs index bf494ed31a5d..8e10a7bbb326 100644 --- a/rts/Setup.hs +++ b/rts/Setup.hs @@ -4,7 +4,7 @@ import Data.Map.Strict qualified as Map import Distribution.Simple import Distribution.Simple.LocalBuildInfo import Distribution.Simple.PackageIndex -import Distribution.Simple.Program (Program, gccProgram, programPath, requireProgram, runProgram, simpleProgram) +import Distribution.Simple.Program (Program, gccProgram, programPath, requireProgram, runProgram, getProgramOutput, simpleProgram) import Distribution.Simple.Setup import Distribution.Types.BuildInfo as BI import Distribution.Types.InstalledPackageInfo as IPI @@ -24,6 +24,9 @@ objdumpProgram = simpleProgram "objdump" deriveConstantsProgram :: Program deriveConstantsProgram = simpleProgram "deriveConstants" +genapplyProgram :: Program +genapplyProgram = simpleProgram "genapply" + main :: IO () main = defaultMainWithHooks @@ -38,6 +41,7 @@ main = (objdump, _progdb) <- requireProgram verbosity objdumpProgram progdb (gcc, _progdb) <- requireProgram verbosity gccProgram progdb (deriveConstants, _progdb) <- requireProgram verbosity deriveConstantsProgram progdb + (genapply, _progdb) <- requireProgram verbosity genapplyProgram progdb -- Include dirs for this package let thisIncDirs = foldMap (BI.includeDirs . libBuildInfo) (allLibraries pd) @@ -52,11 +56,15 @@ main = , incdir <- IPI.includeDirs ipi ] + let derivedConstantsH = interpretSymbolicPathCWD (buildDir lbi makeRelativePathEx "include/DerivedConstants.h") + + -- The fact that we can't just run some pre-gen shell script is really annoying. + -- why does everything need to be haskell? getCurrentDirectory >>= putStrLn runProgram verbosity deriveConstants $ [ "--gen-header" , "-o" - , interpretSymbolicPathCWD (buildDir lbi makeRelativePathEx "include/DerivedConstants.h") + , derivedConstantsH , "--target-os" , os , "--gcc-program" @@ -77,4 +85,13 @@ main = ] ++ foldMap ((\i -> ["--gcc-flag", "-I" ++ i]) . interpretSymbolicPathCWD) thisIncDirs ++ foldMap (\incdir -> ["--gcc-flag", "-I" ++ incdir]) depsIncDirs + getProgramOutput verbosity genapply [derivedConstantsH] + >>= writeFile (interpretSymbolicPathCWD (buildDir lbi makeRelativePathEx "AutoApply.cmm")) + getProgramOutput verbosity genapply [derivedConstantsH, "-V16"] + >>= writeFile (interpretSymbolicPathCWD (buildDir lbi makeRelativePathEx "AutoApply_V16.cmm")) + getProgramOutput verbosity genapply [derivedConstantsH, "-V32"] + >>= writeFile (interpretSymbolicPathCWD (buildDir lbi makeRelativePathEx "AutoApply_V32.cmm")) + getProgramOutput verbosity genapply [derivedConstantsH, "-V64"] + >>= writeFile (interpretSymbolicPathCWD (buildDir lbi makeRelativePathEx "AutoApply_V64.cmm")) + } diff --git a/rts/rts.cabal b/rts/rts.cabal index d68ebb8c4a14..79d737a672b3 100644 --- a/rts/rts.cabal +++ b/rts/rts.cabal @@ -558,7 +558,7 @@ library if !arch(x86_64) && !arch(aarch64) ld-options: -read_only_relocs warning - cmm-sources: + cmm-sources: Apply.cmm Compact.cmm ContinuationOps.cmm From 2252dc12646d5ed1532773a9d041f494c9763ad9 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Mon, 3 Mar 2025 09:32:21 +0900 Subject: [PATCH 49/84] fixup! feat(ghc-toolchain): add otool and install_name_tool --- utils/ghc-toolchain/exe/Main.hs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/utils/ghc-toolchain/exe/Main.hs b/utils/ghc-toolchain/exe/Main.hs index 6c328e3f6498..7876b70abdba 100644 --- a/utils/ghc-toolchain/exe/Main.hs +++ b/utils/ghc-toolchain/exe/Main.hs @@ -199,7 +199,7 @@ options = , progOpts "merge-objs" "linker for merging objects" _optMergeObjs , progOpts "windres" "windres utility" _optWindres , progOpts "otool" "otool utility" _optOtool - , progOpts "install-name-tool" "install_name_tool utility" _optOtool + , progOpts "install-name-tool" "install_name_tool utility" _optInstallNameTool , progOpts "ld" "linker" _optLd ] where @@ -562,9 +562,9 @@ targetToSettings tgt@Target{..} = , ("ar supports at file", arSupportsAtFile') , ("ar supports -L", arSupportsDashL') , ("ranlib command", ranlibPath) - , ("otool command", otool_cmd) - , ("install_name_tool command", install_name_cmd) - , ("windres command", (maybe "/bin/false" prgPath tgtWindres)) -- TODO: /bin/false is not available on many distributions by default, but we keep it as it were before the ghc-toolchain patch. Fix-me. + , ("otool command", maybe "otool" prgPath tgtOtool) + , ("install_name_tool command", maybe "install_name_tool" prgPath tgtInstallNameTool) + , ("windres command", maybe "/bin/false" prgPath tgtWindres) -- TODO: /bin/false is not available on many distributions by default, but we keep it as it were before the ghc-toolchain patch. Fix-me. , ("unlit command", "$topdir/../bin/unlit") -- FIXME , ("cross compiling", yesNo False) -- FIXME: why do we need this settings at all? , ("target platform string", targetPlatformTriple tgt) @@ -600,8 +600,6 @@ targetToSettings tgt@Target{..} = wordSize = show (wordSize2Bytes tgtWordSize) isBigEndian = yesNo $ (\case BigEndian -> True; LittleEndian -> False) tgtEndianness - otool_cmd = "" -- FIXME - install_name_cmd = "" -- FIXME has_libm = "NO" -- FIXME llc_cmd = "llc" -- FIXME llvm_opt_cmd = "opt" -- FIXME From fe8662718d93583fa75b7ad3e580afa9c1836ded Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Fri, 21 Mar 2025 11:40:00 +0900 Subject: [PATCH 50/84] Move ghcversion into the rts, and pass the defines from GHC. --- compiler/GHC/SysTools/Cpp.hs | 32 +++++++------------------------- rts/rts.cabal | 2 ++ 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/compiler/GHC/SysTools/Cpp.hs b/compiler/GHC/SysTools/Cpp.hs index 810ad4e75160..bde91f6d17be 100644 --- a/compiler/GHC/SysTools/Cpp.hs +++ b/compiler/GHC/SysTools/Cpp.hs @@ -272,31 +272,13 @@ getGhcVersionIncludeFlags dflags logger tmpfs = do throwGhcExceptionIO (InstallationError ("ghcversion.h missing; tried: " ++ path)) return ["-include", path] Nothing -> do - macro_stub <- newTempName logger tmpfs (tmpDir dflags) TFL_CurrentModule "h" - writeFile macro_stub ghcVersionH - return ["-include", macro_stub] - --- --------------------------------------------------------------------------- --- ghcversion.h - -ghcVersionH :: String -ghcVersionH = - concat - ["#define __GLASGOW_HASKELL__ ", cProjectVersionInt, "\n" - ,"#define __GLASGOW_HASKELL_FULL_VERSION__ \"", cProjectVersion, "\"\n" - ,"\n" - ,"#define __GLASGOW_HASKELL_PATCHLEVEL1__ ", cProjectPatchLevel1, "\n" - ,"#define __GLASGOW_HASKELL_PATCHLEVEL2__ ", cProjectPatchLevel2, "\n" - ,"\n" - ,"#define MIN_VERSION_GLASGOW_HASKELL(ma,mi,pl1,pl2) ( \\\n" - ," ((ma)*100+(mi)) < __GLASGOW_HASKELL__ || \\\n" - ," ((ma)*100+(mi)) == __GLASGOW_HASKELL__ \\\n" - ," && (pl1) < __GLASGOW_HASKELL_PATCHLEVEL1__ || \\\n" - ," ((ma)*100+(mi)) == __GLASGOW_HASKELL__ \\\n" - ," && (pl1) == __GLASGOW_HASKELL_PATCHLEVEL1__ \\\n" - ," && (pl2) <= __GLASGOW_HASKELL_PATCHLEVEL2__ )\n" - ,"\n\n" - ] + return $ ["-include", ""] + ++ map (\(k, v) -> "-D" ++ k ++ "=" ++ v) + [ ("__GLASGOW_HASKELL__", cProjectVersionInt) + , ("__GLASGOW_HASKELL_FULL_VERSION__", cProjectVersion) + , ("__GLASGOW_HASKELL_PATCHLEVEL1__", cProjectPatchLevel1) + , ("__GLASGOW_HASKELL_PATCHLEVEL2__", cProjectPatchLevel2) + ] applyCDefs :: DefunctionalizedCDefs -> Logger -> DynFlags -> IO [String] applyCDefs NoCDefs _ _ = return [] diff --git a/rts/rts.cabal b/rts/rts.cabal index 79d737a672b3..09a7fab5ecb6 100644 --- a/rts/rts.cabal +++ b/rts/rts.cabal @@ -61,6 +61,7 @@ extra-source-files: include/ghcautoconf.h.in include/ghcplatform.h.in include/ghcconfig.h + include/ghcversion.h include/HsFFI.h include/MachDeps.h include/rts/Adjustor.h @@ -347,6 +348,7 @@ library install-includes: ghcautoconf.h ghcplatform.h + ghcversion.h DerivedConstants.h stg/MachRegsForHost.h From 1ea0645d700d8bac08f6528bbf6066b6c75cd08d Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Fri, 21 Mar 2025 11:40:28 +0900 Subject: [PATCH 51/84] Make rts.setup properly declare it's setup-depends --- rts/rts.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rts/rts.cabal b/rts/rts.cabal index 09a7fab5ecb6..d1c73bf768e8 100644 --- a/rts/rts.cabal +++ b/rts/rts.cabal @@ -328,7 +328,7 @@ flag thread-sanitizer custom-setup setup-depends: - base, Cabal, Cabal-syntax, mtl, transformers + base, Cabal > 3.14.0.0, Cabal-syntax >= 3.15.0.0, mtl, transformers, containers, directory library -- rts is a wired in package and From 361ca980d7af1ebb117f89288d38e791acf28827 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Fri, 21 Mar 2025 11:46:59 +0900 Subject: [PATCH 52/84] Set the default value for Relative Global Package DB --- utils/ghc-toolchain/exe/Main.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/ghc-toolchain/exe/Main.hs b/utils/ghc-toolchain/exe/Main.hs index 7876b70abdba..0a036ae55a15 100644 --- a/utils/ghc-toolchain/exe/Main.hs +++ b/utils/ghc-toolchain/exe/Main.hs @@ -590,7 +590,7 @@ targetToSettings tgt@Target{..} = , ("Leading underscore", (yesNo tgtSymbolsHaveLeadingUnderscore)) , ("Use LibFFI", yesNo tgtUseLibffiForAdjustors) , ("RTS expects libdw", yesNo False) -- FIXME - , ("Relative Global Package DB", "") + , ("Relative Global Package DB", "package.conf.d") , ("base unit-id", "") ] where From 2e0d1dd37a424d32bee71ecb2c9e9d8ea2136e5e Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Fri, 21 Mar 2025 12:26:36 +0900 Subject: [PATCH 53/84] Fix cabal projects --- cabal.project.deps | 11 ++++ cabal.project.stage1-boot | 88 -------------------------------- cabal.project.stage1-rts | 15 ++++-- cabal.project.stage2 | 102 ++++++++++++++++++++++++++++++-------- 4 files changed, 101 insertions(+), 115 deletions(-) create mode 100644 cabal.project.deps delete mode 100644 cabal.project.stage1-boot diff --git a/cabal.project.deps b/cabal.project.deps new file mode 100644 index 000000000000..a36ad71747ff --- /dev/null +++ b/cabal.project.deps @@ -0,0 +1,11 @@ +allow-boot-library-installs: True + +benchmarks: False +tests: False + +packages: + libraries/Cabal/Cabal + libraries/Cabal/Cabal-syntax + +program-options + ghc-options: -fhide-source-paths -j \ No newline at end of file diff --git a/cabal.project.stage1-boot b/cabal.project.stage1-boot deleted file mode 100644 index 3188b7c89361..000000000000 --- a/cabal.project.stage1-boot +++ /dev/null @@ -1,88 +0,0 @@ -allow-boot-library-installs: True -active-repositories: :none - -benchmarks: False -tests: False - -packages: - ./compiler - ./ghc - ./libraries/array - ./libraries/base - ./libraries/binary - ./libraries/bytestring - ./libraries/Cabal/Cabal - ./libraries/Cabal/Cabal-syntax - ./libraries/containers/containers - ./libraries/deepseq - ./libraries/directory - ./libraries/exceptions - ./libraries/file-io - ./libraries/filepath - ./libraries/ghc-bignum - ./libraries/ghc-boot - ./libraries/ghc-boot-th - ./libraries/ghc-compact - ./libraries/ghc-experimental - ./libraries/ghc-heap - ./libraries/ghci - -- ./libraries/ghc-internal - _stage1-boot/src/ghc-internal - ./libraries/ghc-platform - ./libraries/ghc-prim - ./libraries/haskeline - ./libraries/hpc - ./libraries/integer-gmp - ./libraries/mtl - ./libraries/os-string - ./libraries/parsec - ./libraries/pretty - ./libraries/process - ./libraries/semaphore-compat - ./libraries/stm - ./libraries/system-cxx-std-lib - ./libraries/template-haskell - ./libraries/terminfo - ./libraries/text - ./libraries/time - ./libraries/transformers - ./libraries/unix - ./libraries/Win32 - ./libraries/xhtml - ./utils/deriveConstants - ./utils/genprimopcode - ./utils/ghc-pkg - ./utils/ghc-toolchain - ./utils/hsc2hs - ./utils/unlit - https://hackage.haskell.org/package/alex-3.5.2.0/alex-3.5.2.0.tar.gz - https://hackage.haskell.org/package/happy-2.1.5/happy-2.1.5.tar.gz - https://hackage.haskell.org/package/happy-lib-2.1.5/happy-lib-2.1.5.tar.gz - -- https://hackage.haskell.org/package/os-string-2.0.7/os-string-2.0.7.tar.gz - -- https://hackage.haskell.org/package/process-1.6.25.0/process-1.6.25.0.tar.gz - -- https://hackage.haskell.org/package/time-1.14/time-1.14.tar.gz - -- https://hackage.haskell.org/package/unix-2.8.6.0/unix-2.8.6.0.tar.gz - -package hsc2hs - flags: +in-ghc-tree - -package ghc - -- build-tool-depends: require genprimopcode, etc. used by Setup.hs - -- internal-interpreter: otherwise our compiler has the internal - -- interpreter but not the boot library we install - -- FIXME: we should really install the lib we used to build stage2 - flags: +build-tool-depends +internal-interpreter - -package ghci - flags: +internal-interpreter - -package ghc-internal - -- FIXME: make our life easier for now by using the native bignum backend - flags: +bignum-native - -package text - -- FIXME: avoid having to deal with system-cxx-std-lib fake package for now - flags: -simdutf - -program-options - ghc-options: -fhide-source-paths -j \ No newline at end of file diff --git a/cabal.project.stage1-rts b/cabal.project.stage1-rts index db4f2f7d6b72..df66ac61c38f 100644 --- a/cabal.project.stage1-rts +++ b/cabal.project.stage1-rts @@ -1,13 +1,18 @@ allow-boot-library-installs: True --- active-repositories: :none benchmarks: False tests: False packages: - rts - rts-fs - rts-headers + rts + rts-fs + rts-headers + +package rts + flags: +table-next-to-code +leading-underscore + ghc-options: -v program-options - ghc-options: -fhide-source-paths -j \ No newline at end of file + ghc-options: -fhide-source-paths -j + +-- constraints: any.base installed \ No newline at end of file diff --git a/cabal.project.stage2 b/cabal.project.stage2 index 87382021c69d..e4f48fec4b50 100644 --- a/cabal.project.stage2 +++ b/cabal.project.stage2 @@ -1,35 +1,93 @@ +allow-boot-library-installs: True +active-repositories: :none + +benchmarks: False +tests: False + packages: + ./compiler ./ghc - -- https://hackage.haskell.org/package/directory-1.3.9.0/directory-1.3.9.0.tar.gz - -- ./libraries/file-io - -- ./libraries/filepath - -- ./libraries/ghc-platform - -- ./libraries/ghc-boot - -- ./libraries/ghc-boot-th - -- ./libraries/ghc-heap - -- ./libraries/ghci + ./libraries/array + ./libraries/base + ./libraries/binary + ./libraries/bytestring + ./libraries/Cabal/Cabal + ./libraries/Cabal/Cabal-syntax + ./libraries/containers/containers + ./libraries/deepseq + ./libraries/directory + ./libraries/exceptions + ./libraries/file-io + ./libraries/filepath + ./libraries/ghc-bignum + ./libraries/ghc-boot + ./libraries/ghc-boot-th + ./libraries/ghc-compact + ./libraries/ghc-experimental + ./libraries/ghc-heap + ./libraries/ghci + -- ./libraries/ghc-internal + _stage1/src/ghc-internal + ./libraries/ghc-platform + ./libraries/ghc-prim + ./libraries/haskeline + ./libraries/hpc + ./libraries/integer-gmp + ./libraries/mtl + ./libraries/os-string + ./libraries/parsec + ./libraries/pretty + ./libraries/process + ./libraries/semaphore-compat + ./libraries/stm + ./libraries/system-cxx-std-lib + ./libraries/template-haskell + ./libraries/terminfo + ./libraries/text + ./libraries/time + ./libraries/transformers + ./libraries/unix + ./libraries/Win32 + ./libraries/xhtml + ./utils/deriveConstants + ./utils/genprimopcode + ./utils/ghc-pkg + ./utils/ghc-toolchain + ./utils/hsc2hs + ./utils/unlit + https://hackage.haskell.org/package/alex-3.5.2.0/alex-3.5.2.0.tar.gz + https://hackage.haskell.org/package/happy-2.1.5/happy-2.1.5.tar.gz + https://hackage.haskell.org/package/happy-lib-2.1.5/happy-lib-2.1.5.tar.gz -- https://hackage.haskell.org/package/os-string-2.0.7/os-string-2.0.7.tar.gz -- https://hackage.haskell.org/package/process-1.6.25.0/process-1.6.25.0.tar.gz - -- ./libraries/semaphore-compat -- https://hackage.haskell.org/package/time-1.14/time-1.14.tar.gz -- https://hackage.haskell.org/package/unix-2.8.6.0/unix-2.8.6.0.tar.gz - -- ./libraries/Win32 - ./utils/ghc-pkg - -- ./utils/hsc2hs - -- ./utils/unlit - -- ./utils/ghc-toolchain - -- ./utils/ghc-toolchain/exe -benchmarks: False -profiling: False -tests: False +package hsc2hs + flags: +in-ghc-tree + +package ghc + -- build-tool-depends: require genprimopcode, etc. used by Setup.hs + -- internal-interpreter: otherwise our compiler has the internal + -- interpreter but not the boot library we install + -- FIXME: we should really install the lib we used to build stage2 + flags: +build-tool-depends +internal-interpreter + ghc-options: -v3 + +package ghci + flags: +internal-interpreter + +package ghc-internal + -- FIXME: make our life easier for now by using the native bignum backend + flags: +bignum-native package ghc-bin - -- FIXME: we don't support the threaded rts way yet - flags: +internal-interpreter -threaded + -- FIXME: we don't have the threaded RTS yet. + flags: -threaded -package hsc2hs - flags: +in-ghc-tree +package text + -- FIXME: avoid having to deal with system-cxx-std-lib fake package for now + flags: -simdutf program-options ghc-options: -fhide-source-paths -j \ No newline at end of file From 3218299c4603c017dab8b55a4590ee06436aa611 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Fri, 21 Mar 2025 13:52:47 +0900 Subject: [PATCH 54/84] fixup! Move ghcversion into the rts, and pass the defines from GHC. --- rts/include/ghcversion.h | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 rts/include/ghcversion.h diff --git a/rts/include/ghcversion.h b/rts/include/ghcversion.h new file mode 100644 index 000000000000..6ac210f7e35a --- /dev/null +++ b/rts/include/ghcversion.h @@ -0,0 +1,9 @@ +#pragma once + +#define MIN_VERSION_GLASGOW_HASKELL(ma, mi, pl1, pl2) ( \ + ((ma)*100+(mi)) < __GLASGOW_HASKELL__ || \ + ((ma)*100+(mi)) == __GLASGOW_HASKELL__ \ + && (pl1) < __GLASGOW_HASKELL_PATCHLEVEL1__ || \ + ((ma)*100+(mi)) == __GLASGOW_HASKELL__ \ + && (pl1) == __GLASGOW_HASKELL_PATCHLEVEL1__ \ + && (pl2) <= __GLASGOW_HASKELL_PATCHLEVEL2__ ) \ No newline at end of file From 82ae45d29fee97dcc4ec74a15d4a409e1a18e337 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Fri, 21 Mar 2025 15:14:17 +0900 Subject: [PATCH 55/84] Add ghcversion.h to rts-headers --- rts-headers/include/ghcversion.h | 9 +++++++++ rts-headers/rts-headers.cabal | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 rts-headers/include/ghcversion.h diff --git a/rts-headers/include/ghcversion.h b/rts-headers/include/ghcversion.h new file mode 100644 index 000000000000..6ac210f7e35a --- /dev/null +++ b/rts-headers/include/ghcversion.h @@ -0,0 +1,9 @@ +#pragma once + +#define MIN_VERSION_GLASGOW_HASKELL(ma, mi, pl1, pl2) ( \ + ((ma)*100+(mi)) < __GLASGOW_HASKELL__ || \ + ((ma)*100+(mi)) == __GLASGOW_HASKELL__ \ + && (pl1) < __GLASGOW_HASKELL_PATCHLEVEL1__ || \ + ((ma)*100+(mi)) == __GLASGOW_HASKELL__ \ + && (pl1) == __GLASGOW_HASKELL_PATCHLEVEL1__ \ + && (pl2) <= __GLASGOW_HASKELL_PATCHLEVEL2__ ) \ No newline at end of file diff --git a/rts-headers/rts-headers.cabal b/rts-headers/rts-headers.cabal index 6d1b89a7ca33..4058c6ab4530 100644 --- a/rts-headers/rts-headers.cabal +++ b/rts-headers/rts-headers.cabal @@ -15,8 +15,9 @@ build-type: Simple library include-dirs: include - + install-includes: + ghcversion.h rts/Bytecodes.h rts/storage/ClosureTypes.h rts/storage/FunTypes.h From 96681583097f43cea9cc2e8abf03bfe126369da0 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Fri, 21 Mar 2025 15:15:38 +0900 Subject: [PATCH 56/84] Drop ghcversion from rts.cabal --- rts/include/ghcversion.h | 9 --------- rts/rts.cabal | 5 ++--- 2 files changed, 2 insertions(+), 12 deletions(-) delete mode 100644 rts/include/ghcversion.h diff --git a/rts/include/ghcversion.h b/rts/include/ghcversion.h deleted file mode 100644 index 6ac210f7e35a..000000000000 --- a/rts/include/ghcversion.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#define MIN_VERSION_GLASGOW_HASKELL(ma, mi, pl1, pl2) ( \ - ((ma)*100+(mi)) < __GLASGOW_HASKELL__ || \ - ((ma)*100+(mi)) == __GLASGOW_HASKELL__ \ - && (pl1) < __GLASGOW_HASKELL_PATCHLEVEL1__ || \ - ((ma)*100+(mi)) == __GLASGOW_HASKELL__ \ - && (pl1) == __GLASGOW_HASKELL_PATCHLEVEL1__ \ - && (pl2) <= __GLASGOW_HASKELL_PATCHLEVEL2__ ) \ No newline at end of file diff --git a/rts/rts.cabal b/rts/rts.cabal index d1c73bf768e8..625e3296d473 100644 --- a/rts/rts.cabal +++ b/rts/rts.cabal @@ -287,13 +287,13 @@ flag static-libzstd default: False manual: True flag leading-underscore - default: False + default: True manual: True flag unregisterised default: False manual: True flag tables-next-to-code - default: False + default: True manual: True flag smp default: True @@ -348,7 +348,6 @@ library install-includes: ghcautoconf.h ghcplatform.h - ghcversion.h DerivedConstants.h stg/MachRegsForHost.h From db3383d0a4cd1a32d30ce6e7851d8d07cb7f4c64 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Fri, 21 Mar 2025 15:15:58 +0900 Subject: [PATCH 57/84] `ghcversion.h`, not ``. --- compiler/GHC/SysTools/Cpp.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/GHC/SysTools/Cpp.hs b/compiler/GHC/SysTools/Cpp.hs index bde91f6d17be..ded8a4d8313f 100644 --- a/compiler/GHC/SysTools/Cpp.hs +++ b/compiler/GHC/SysTools/Cpp.hs @@ -272,7 +272,7 @@ getGhcVersionIncludeFlags dflags logger tmpfs = do throwGhcExceptionIO (InstallationError ("ghcversion.h missing; tried: " ++ path)) return ["-include", path] Nothing -> do - return $ ["-include", ""] + return $ ["-include", "ghcversion.h"] ++ map (\(k, v) -> "-D" ++ k ++ "=" ++ v) [ ("__GLASGOW_HASKELL__", cProjectVersionInt) , ("__GLASGOW_HASKELL_FULL_VERSION__", cProjectVersion) From 0fcd7be72438df28349c956aa74b9b2988260237 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Fri, 21 Mar 2025 15:16:19 +0900 Subject: [PATCH 58/84] Add `-no-ghcversion-header` flag to ghc. --- compiler/GHC/Driver/Flags.hs | 1 + compiler/GHC/Driver/Pipeline/Execute.hs | 4 +++- compiler/GHC/Driver/Session.hs | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/GHC/Driver/Flags.hs b/compiler/GHC/Driver/Flags.hs index 6a106b615601..37b17d7beee0 100644 --- a/compiler/GHC/Driver/Flags.hs +++ b/compiler/GHC/Driver/Flags.hs @@ -716,6 +716,7 @@ data GeneralFlag | Opt_EagerBlackHoling | Opt_OrigThunkInfo | Opt_NoHsMain + | Opt_NoGhcVersionH | Opt_SplitSections | Opt_StgStats | Opt_HideAllPackages diff --git a/compiler/GHC/Driver/Pipeline/Execute.hs b/compiler/GHC/Driver/Pipeline/Execute.hs index 798da42a5e63..cd92aa6e7180 100644 --- a/compiler/GHC/Driver/Pipeline/Execute.hs +++ b/compiler/GHC/Driver/Pipeline/Execute.hs @@ -523,7 +523,9 @@ runCcPhase cc_phase pipe_env hsc_env location input_fn = do else []) ++ verbFlags ++ cc_opt - ++ include_ghcVersionH + ++ (if gopt Opt_NoGhcVersionH dflags + then [] + else include_ghcVersionH) ++ framework_paths ++ include_paths ++ pkg_extra_cc_opts diff --git a/compiler/GHC/Driver/Session.hs b/compiler/GHC/Driver/Session.hs index 21f22d359120..c33419e4594f 100644 --- a/compiler/GHC/Driver/Session.hs +++ b/compiler/GHC/Driver/Session.hs @@ -1303,6 +1303,8 @@ dynamic_flags_deps = [ (NoArg (unSetGeneralFlag Opt_AutoLinkPackages)) , make_ord_flag defGhcFlag "no-hs-main" (NoArg (setGeneralFlag Opt_NoHsMain)) + , make_ord_flag defGhcFlag "no-ghcversion-header" + (NoArg (setGeneralFlag Opt_NoGhcVersionH)) , make_ord_flag defGhcFlag "fno-state-hack" (NoArg (setGeneralFlag Opt_G_NoStateHack)) , make_ord_flag defGhcFlag "fno-opt-coercion" From 2092f90594c1f9f47432d483ea57b06da58abac9 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Fri, 21 Mar 2025 15:37:02 +0900 Subject: [PATCH 59/84] fixup! Drop ghcversion from rts.cabal --- rts/rts.cabal | 1 - 1 file changed, 1 deletion(-) diff --git a/rts/rts.cabal b/rts/rts.cabal index 625e3296d473..a22ebc86901b 100644 --- a/rts/rts.cabal +++ b/rts/rts.cabal @@ -61,7 +61,6 @@ extra-source-files: include/ghcautoconf.h.in include/ghcplatform.h.in include/ghcconfig.h - include/ghcversion.h include/HsFFI.h include/MachDeps.h include/rts/Adjustor.h From 30877e40725ab7f142c82c6cfcd191c4c41584e5 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Fri, 21 Mar 2025 17:27:35 +0900 Subject: [PATCH 60/84] fixup! Move ghcversion into the rts, and pass the defines from GHC. --- compiler/GHC/SysTools/Cpp.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/GHC/SysTools/Cpp.hs b/compiler/GHC/SysTools/Cpp.hs index ded8a4d8313f..571f690380e8 100644 --- a/compiler/GHC/SysTools/Cpp.hs +++ b/compiler/GHC/SysTools/Cpp.hs @@ -275,7 +275,8 @@ getGhcVersionIncludeFlags dflags logger tmpfs = do return $ ["-include", "ghcversion.h"] ++ map (\(k, v) -> "-D" ++ k ++ "=" ++ v) [ ("__GLASGOW_HASKELL__", cProjectVersionInt) - , ("__GLASGOW_HASKELL_FULL_VERSION__", cProjectVersion) + -- The cProjectVersion needs to be quoted! + , ("__GLASGOW_HASKELL_FULL_VERSION__", "\"" ++ cProjectVersion ++ "\"") , ("__GLASGOW_HASKELL_PATCHLEVEL1__", cProjectPatchLevel1) , ("__GLASGOW_HASKELL_PATCHLEVEL2__", cProjectPatchLevel2) ] From 3dcc8ee35f3c17a3b774704006826474ba792d5a Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Fri, 21 Mar 2025 17:27:55 +0900 Subject: [PATCH 61/84] Don't pass `ghcversion.h` when building the rts. --- cabal.project.stage1-rts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cabal.project.stage1-rts b/cabal.project.stage1-rts index df66ac61c38f..571dd50fa449 100644 --- a/cabal.project.stage1-rts +++ b/cabal.project.stage1-rts @@ -13,6 +13,6 @@ package rts ghc-options: -v program-options - ghc-options: -fhide-source-paths -j + ghc-options: -fhide-source-paths -j -no-ghcversion-header -- constraints: any.base installed \ No newline at end of file From da47326a356d7069ca464d5d7d4ddb6f4f01beb4 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Fri, 21 Mar 2025 17:28:16 +0900 Subject: [PATCH 62/84] Add Cabal/Cabal-syntax to the boot lirbaries. We need them for the custom setups. --- cabal.project.stage1 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cabal.project.stage1 b/cabal.project.stage1 index e97e5e086545..a74f483c0f86 100644 --- a/cabal.project.stage1 +++ b/cabal.project.stage1 @@ -25,6 +25,10 @@ packages: ./utils/deriveConstants ./utils/ghc-toolchain ./utils/ghc-toolchain/exe + -- we need these here, as we'll need them for the setup.hs for the RTS, and + -- other packages. Once Cabal upstream is recent enough, we can drop them. + ./libraries/Cabal/Cabal + ./libraries/Cabal/Cabal-syntax benchmarks: False tests: False From d959bf4aa82e502df037a1041c92cd7d725867f9 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Fri, 21 Mar 2025 19:42:07 +0900 Subject: [PATCH 63/84] Update Makefile --- Makefile | 215 +++++++++++++++++++++++++++---------------------------- 1 file changed, 107 insertions(+), 108 deletions(-) diff --git a/Makefile b/Makefile index 2aaf3cf86d7f..55f57775ab3b 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,39 @@ +# The Makefile to build GHC with cabal +# +# Pre-requisites: +# There are a few tools we expect to exist prior to building this. These are +# documented here. If you end up creating more dependencies, be explicit about +# them here at the start. +# +# - make +# - ghc (a recent enough GHC to function at the boostrap compiler) +# - cabal (a recent enough cabal-install executable to build the cabal pkgs +# and the necessary changes for dual stage, ...) +# +# Build Plan: +# In general GHC is built in two stages to ensure the compiler is linked against +# libraries built by the same compiler. This allows the compiler to have the +# same abi as the code it produces. This does not work for cross compilers, as +# we can't build a compiler for the host platform using a host->target compiler. +# +# Stage 0 (boostrap stage) +# In this stage we build just enough of the compiler dependencies to build the +# Stage 1 compiler (ghc executable). We want to build the ghc executable, but +# may need to build extra libraries that are newer than the ones that come with +# the bootstrap compiler. This crucially also means, these libraries are stable +# (as long as their source doesn't change) to be cached. +# +# Stage 1 +# We now have the boostrap libraries and a compiler (ghc1) built with (ghc0) the +# ghc0-libraries + extra libraries built with ghc0. This includes the new run- +# time system (rts). Thus we have a ghc1 but no libraries yet. We now build all +# the libraries required to build the compiler (from ø) using ghc1. And then +# build ghc2 using ghc1 with the newly build libraries. +# +# Stage 2 +# This gives us our stage2 compiler (ghc2, all it's deps built with ghc1). This +# is the pair we package up. + SHELL := bash .ONESHELL: .SHELLFLAGS := -eu -o pipefail -c @@ -7,8 +43,7 @@ MAKEFLAGS += --no-builtin-rules all: stage1-boot -CABAL0 ?= cabal -CABAL ?= _stage0/bin/cabal +CABAL ?= cabal GHC0 ?= ghc define LIB = @@ -28,7 +63,7 @@ endef CABAL_FLAGS += --store-dir $(OUT)/store --logs-dir $(OUT)/logs CABAL_BUILD_FLAGS += --builddir $(OUT)/build -CABAL_BUILD_FLAGS += --with-compiler $(GHC) +CABAL_BUILD_FLAGS += --with-compiler $(GHC) --with-hc-pkg $(GHC)-pkg --with-build-compiler $(GHC0) --with-build-hc-pkg $(GHC0)-pkg CABAL_BUILD = $(CABAL) $(CABAL_FLAGS) build $(CABAL_BUILD_FLAGS) @@ -39,25 +74,12 @@ CABAL_INSTALL_FLAGS += --install-method=copy CABAL_INSTALL = $(CABAL) $(CABAL_FLAGS) install $(CABAL_BUILD_FLAGS) $(CABAL_INSTALL_FLAGS) -cabal: _stage0/bin/cabal - -CABAL_EXE = cabal cabal-main-simple cabal-main-configure -CABAL_BIN = $(addprefix _stage0/bin/,$(CABAL_EXE)) - -$(CABAL_BIN) &: OUT ?= $(abspath _stage0) -$(CABAL_BIN) &: override GHC=$(GHC0) -$(CABAL_BIN) &: CABAL=$(CABAL0) -$(CABAL_BIN) &: - @$(LIB) - log mkdir -p $(@D) - log $(CABAL_INSTALL) --project-dir libraries/Cabal --project-file cabal.release.project $(addprefix exe:,$(CABAL_EXE)) - -STAGE1_EXE = ghc ghc-pkg ghc-toolchain-bin deriveConstants genprimopcode genapply +STAGE1_EXE = ghc ghc-pkg ghc-toolchain-bin deriveConstants genprimopcode genapply unlit STAGE1_BIN = $(addprefix _stage1/bin/,$(STAGE1_EXE)) $(STAGE1_BIN) &: OUT ?= $(abspath _stage1) $(STAGE1_BIN) &: override GHC=$(GHC0) -$(STAGE1_BIN) &: $(CABAL) +$(STAGE1_BIN) &: @$(LIB) log mkdir -p $(@D) log export HADRIAN_SETTINGS="$$(cat ./HADRIAN_SETTINGS)" @@ -77,116 +99,93 @@ TARGET := $(shell cc -dumpmachine) _stage1/lib/settings: _stage1/bin/ghc-toolchain-bin @$(LIB) mkdir -p $(@D) - log _stage1/bin/ghc-toolchain-bin --cc=cc --cxx=c++ --output-settings -t $(TARGET) -o $@ - -stage1: _stage1/bin/ghc _stage1/lib/settings + log _stage1/bin/ghc-toolchain-bin --cc=cc --cxx=c++ --install-name-tool=install_name_tool --otool=otool --output-settings -t $(TARGET) -o $@ -_stage1-rts/lib/package.conf.d/rts-fs-1.0.0.0.conf: _stage0/bin/cabal-main-simple +_stage2/lib/settings: _stage1/bin/ghc-toolchain-bin @$(LIB) - mkdir -p "$(@D)/lib/package.conf.d" - - pushd rts-fs || exit - log ../_stage0/bin/cabal-main-simple configure --builddir "$(OUT)/dist/rts-fs" $(CABAL_CONFIG_FLAGS) --ipid=$(notdir $(@:%.conf=%)) - log ../_stage0/bin/cabal-main-simple build --builddir "$(OUT)/dist/rts-fs" - log ../_stage0/bin/cabal-main-simple install --builddir "$(OUT)/dist/rts-fs" - popd - -_stage1-rts/lib/package.conf.d/rts-headers-1.0.0.0.conf: _stage0/bin/cabal-main-simple - @$(LIB) - mkdir -p "$(@D)" + mkdir -p $(@D) + log _stage1/bin/ghc-toolchain-bin --cc=cc --cxx=c++ --install-name-tool=install_name_tool --otool=otool --output-settings -t $(TARGET) -o $@ - pushd rts-headers || exit - log ../_stage0/bin/cabal-main-simple configure --builddir "$(OUT)/dist/rts-headers" $(CABAL_CONFIG_FLAGS) --ipid=$(notdir $(@:%.conf=%)) - log ../_stage0/bin/cabal-main-simple build --builddir "$(OUT)/dist/rts-headers" - log ../_stage0/bin/cabal-main-simple install --builddir "$(OUT)/dist/rts-headers" - popd -# NOTE: The bootstrap is particularly annoying in this step. -# -# rts has a custom config so we need a Cabal to compile Setup.hs, but we cannot -# use the new compiler (not even stage1) for this because we do not have the rts -# yet (as we are just preparing to build it). -# -# We cut the know by using the version of Cabal we had built with the stage0 compiler. -# NOTE: the requirement _stage0/bin/cabal is representative of the fact that we had built the library -# +stage1: _stage1/bin/ghc _stage1/lib/settings -# _stage0/bin/cabal as evidence that we have build cabal -_stage1-rts/dist/rts/Setup: .EXTRA_PREREQS=_stage0/bin/cabal -_stage1-rts/dist/rts/Setup: rts/Setup.hs - @$(LIB) - # FIXME I am using the store as a package db, its path is not quite fixed as it - # relies on the bootstrap compiler id - mkdir -p $(@D) - log $(GHC0) -clear-package-db -global-package-db -package-db _stage0/store/*/package.db -o $@ $< -_stage1-rts/lib/package.conf.d/rts-1.0.0.0.conf: _stage1/lib/settings _stage1/bin/ghc rts/configure _stage1-rts/lib/package.conf.d/rts-fs-1.0.0.0.conf _stage1-rts/lib/package.conf.d/rts-headers-1.0.0.0.conf _stage1-rts/dist/rts/Setup _stage1/bin/deriveConstants _stage1/bin/genapply - @$(LIB) - mkdir -p "$(@D)/lib/package.conf.d" - - # for rts setup to find derivedConstants and genApply - export PATH=$(abspath _stage1/bin):$$PATH - - pushd rts || exit - log ../_stage1-rts/dist/rts/Setup configure --builddir "$(OUT)/dist/rts" $(CABAL_CONFIG_FLAGS) --ipid=$(notdir $(@:%.conf=%)) - log ../_stage1-rts/dist/rts/Setup build --builddir "$(OUT)/dist/rts" - log ../_stage1-rts/dist/rts/Setup install --builddir "$(OUT)/dist/rts" - popd - -stage1-rts: GHC = $(abspath _stage1/bin/ghc) -stage1-rts: CABAL_CONFIG_FLAGS += -v --with-compiler $(GHC) -stage1-rts: GHCPKG = $(abspath _stage1/bin/ghc-pkg) -stage1-rts: CABAL_CONFIG_FLAGS += --with-hc-pkg $(GHCPKG) -stage1-rts: CABAL_CONFIG_FLAGS += --prefix $(OUT) -stage1-rts: CABAL_CONFIG_FLAGS += --package-db $(OUT)/lib/package.conf.d -stage1-rts: OUT ?= $(abspath _stage1-rts) -stage1-rts: $(addprefix _stage1-rts/lib/package.conf.d/,rts-1.0.0.0.conf rts-fs-1.0.0.0.conf rts-headers-1.0.0.0.conf) - -_stage1-boot/src/compiler/GHC/Builtin/primops.txt: compiler/GHC/Builtin/primops.txt.pp +# this should be in the setup of compiler.cabal? +_stage1/src/compiler/GHC/Builtin/primops.txt: compiler/GHC/Builtin/primops.txt.pp @$(LIB) mkdir -p $(@D) log cc -E -undef -traditional -P -x c $< >$@ -_stage1-boot/src/ghc-internal/ghc-internal.cabal: +# This should be in the setup of ghc-internal.cabal? +_stage1/src/ghc-internal/ghc-internal.cabal: @$(LIB) rm -rf $(@D) mkdir -p $(@D) cp -r libraries/ghc-internal/* $(@D) -_stage1-boot/src/ghc-internal/src/GHC/Internal/Prim.hs: _stage1-boot/src/compiler/GHC/Builtin/primops.txt | _stage1-boot/src/ghc-internal/ghc-internal.cabal +_stage1/src/ghc-internal/src/GHC/Internal/Prim.hs: _stage1/src/compiler/GHC/Builtin/primops.txt | _stage1/src/ghc-internal/ghc-internal.cabal @$(LIB) mkdir -p $(@D) log _stage1/bin/genprimopcode --make-haskell-source < $< > $@ -_stage1-boot/src/ghc-internal/src/GHC/Internal/PrimopWrappers.hs: _stage1-boot/src/compiler/GHC/Builtin/primops.txt | _stage1-boot/src/ghc-internal/ghc-internal.cabal +_stage1/src/ghc-internal/src/GHC/Internal/PrimopWrappers.hs: _stage1/src/compiler/GHC/Builtin/primops.txt | _stage1/src/ghc-internal/ghc-internal.cabal @$(LIB) mkdir -p $(@D) log _stage1/bin/genprimopcode --make-haskell-wrappers < $< > $@ - -_stage1-boot/src/ghc-internal/.ready: _stage1-boot/src/ghc-internal/ghc-internal.cabal -_stage1-boot/src/ghc-internal/.ready: _stage1-boot/src/ghc-internal/src/GHC/Internal/Prim.hs -_stage1-boot/src/ghc-internal/.ready: _stage1-boot/src/ghc-internal/src/GHC/Internal/PrimopWrappers.hs -_stage1-boot/src/ghc-internal/.ready: _stage1-boot/src/ghc-internal/configure - -# targets -STAGE1_BOOT_TARGETS = ghc-internal ghc-experimental ghc-compact base stm system-cxx-std-lib -# shallow compat packages over ghc-internal -STAGE1_BOOT_TARGETS += ghc-prim ghc-bignum integer-gmp template-haskell -# target dependencies -STAGE1_BOOT_TARGETS += ghc-boot-th pretty -# other boot libraries used by tests -STAGE1_BOOT_TARGETS += array binary bytestring Cabal Cabal-syntax containers deepseq directory exceptions file-io filepath hpc mtl os-string parsec process semaphore-compat text time transformers -STAGE1_BOOT_TARGETS += unix -# FIXME: we'd have to install Win32 for Windows target. Maybe --libs could install dependencies too.. -# ghc related -STAGE1_BOOT_TARGETS += ghc-boot ghc-heap ghc-platform ghc-toolchain ghci ghc - -stage1-boot: CABAL = _stage0/bin/cabal -stage1-boot: GHC = $(abspath _stage1/bin/ghc) -stage1-boot: OUT ?= $(abspath _stage1-boot) -stage1-boot: _stage0/bin/cabal _stage1/bin/ghc _stage1-boot/src/ghc-internal/.ready stage1-rts + +_stage1/src/ghc-internal/.ready: _stage1/src/ghc-internal/ghc-internal.cabal +_stage1/src/ghc-internal/.ready: _stage1/src/ghc-internal/src/GHC/Internal/Prim.hs +_stage1/src/ghc-internal/.ready: _stage1/src/ghc-internal/src/GHC/Internal/PrimopWrappers.hs +_stage1/src/ghc-internal/.ready: _stage1/src/ghc-internal/configure + +# We need this folder to exist prior to running anything with _stage1/bin/ghc and cabal, +# because that will result in ghc-pkg being invoked. That one looking into the ../lib/settings file. +# Finding that package.conf.d is the global package db, and then falling over itself because that +# folder doesn't exist after building the ghc executable. So here we link the cabal _store_ package-db +# into the _stage1/lib/package.conf.d folder, thus the new ghc compiler will always have access to all +# the packages it built on the way to ghc stage2. +_stage1/lib/package.conf.d: + @$(LIB) + log _stage1/bin/ghc-pkg init $(PWD)/_stage2/store/$$(_stage1/bin/ghc --info | grep "Project Unit Id" | cut -d'"' -f4)/package.db + log ln -sf $(PWD)/_stage2/store/$$(_stage1/bin/ghc --info | grep "Project Unit Id" | cut -d'"' -f4)/package.db _stage1/lib/package.conf.d + log ln -sf $(PWD)/_stage2/store/$$(_stage1/bin/ghc --info | grep "Project Unit Id" | cut -d'"' -f4)/package.db _stage2/lib/package.conf.d + +# This is basically the glue piece. We have a compiler `ghc`, that just doesn't have an RTS yet, and thus can't really link any executable. +# Ideally we'd just ask cabal to start building, by providing the boostrap compiler as GHC0 and the stage1 compiler as GHC. However, cabal +# will fall over itself trying to solve the packages even for the build-compiler. E.g. it sees it needs Cabal/Cabal-syntax, which are listed +# as packages in the cabal.project file, then tries to figure out how to build base, ... which just can't work. Ideally the build compiler +# would make a cut wrt to which packages it considers to rebuild. A small closure maybe. Maybe we should re-use non-reinstallable packages +# for this? Although I'd argue, I really don't want those in cabal anymore at some point. Another option would be to have build-packages +# in the cabal-project file, or just outright deny the build-compiler to consider building any of those packages and requesting in that +# special case that people just install --lib the necessary packages as needed? The idea of extending `build-packages` to the cabal.project +# file is growing on me. E.g. consider these packages under `build-packages` eligable to build from source when using the build-compiler +# e.g. for setup, and build-depends. +_stage2/rts.ready : OUT ?= $(abspath _stage2) +_stage2/rts.ready : GHC = $(abspath _stage1/bin/ghc) +_stage2/rts.ready : GHC0 = $(shell which ghc) +_stage2/rts.ready : _stage1/bin/ghc _stage1/lib/settings rts/configure _stage1/lib/package.conf.d @$(LIB) - # for rts/configure - export DERIVE_CONSTANTS=$(abspath _stage1/bin/deriveConstants) - export GENAPPLY=$(abspath _stage1/bin/genapply) - log $(CABAL_INSTALL) --lib --package-db=$(abspath _stage1-rts/lib/package.conf.d) --package-env $(OUT) --project-file cabal.project.stage1-boot Cabal + log mkdir -p $(@D) + log export PATH="$(abspath _stage1/bin):$(PATH)" + log $(CABAL_INSTALL) --lib --build-package-db=$(abspath _stage1/store)/$$($(GHC0) --info | grep "Project Unit Id" | cut -d'"' -f4)/package.db --project-file cabal.project.stage1-rts all + log touch $@ + + +# Now that we've jammed the rts's into the stage1 compiler package.db, we can go on and just build the rest of the stage2 compiler. +# This will automatically also mean, we end up with the relevant packages to ship alognside the stage2 compiler in the _stage1/lib/package.conf.d. +STAGE2_EXE = ghc ghc-pkg +STAGE2_BIN = $(addprefix _stage2/bin/,$(STAGE2_EXE)) + +$(STAGE2_BIN) &: OUT ?= $(abspath _stage2) +$(STAGE2_BIN) &: GHC = $(abspath _stage1/bin/ghc) +$(STAGE2_BIN) &: GHC0 = $(abspath _stage1/bin/ghc) +$(STAGE2_BIN) &: _stage1/bin/ghc _stage1/src/ghc-internal/.ready _stage2/rts.ready + @$(LIB) + log mkdir -p $(@D) + log export HADRIAN_SETTINGS="$$(cat ./HADRIAN_SETTINGS)" + log $(CABAL_INSTALL) --package-db=$(abspath _stage1/lib/package.conf.d) --project-file cabal.project.stage2 $(addprefix exe:,$(STAGE2_EXE)) + +# 1. git clean -xfd +# 2. make _stage1/bin/ghc +# 3. make _stage2/bin/ghc +# 4. make _stage2/lib/settings \ No newline at end of file From 99bec78c2bb227feae416755b11b0f020b91944d Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Fri, 21 Mar 2025 19:48:57 +0900 Subject: [PATCH 64/84] Clarify rts. --- Makefile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 55f57775ab3b..d0c24821f657 100644 --- a/Makefile +++ b/Makefile @@ -25,10 +25,11 @@ # # Stage 1 # We now have the boostrap libraries and a compiler (ghc1) built with (ghc0) the -# ghc0-libraries + extra libraries built with ghc0. This includes the new run- -# time system (rts). Thus we have a ghc1 but no libraries yet. We now build all -# the libraries required to build the compiler (from ø) using ghc1. And then -# build ghc2 using ghc1 with the newly build libraries. +# ghc0-libraries + extra libraries built with ghc0. Thus we have a ghc1 but no +# libraries yet. We now build all the libraries required to build the compiler +# (from ø) using ghc1. First we need to build the rts with ghc1. Then build all +# the libraries necessary to build ghc2. And then build ghc2 using ghc1 with the +# newly build libraries. # # Stage 2 # This gives us our stage2 compiler (ghc2, all it's deps built with ghc1). This From 114c366c6e08d83e50d3125272fd7f7bd479d2a5 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Sat, 22 Mar 2025 10:47:12 +0900 Subject: [PATCH 65/84] Add `mermaid` to ghc-pkg --- utils/ghc-pkg/Main.hs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/utils/ghc-pkg/Main.hs b/utils/ghc-pkg/Main.hs index 14684dc96494..3b62bbd6c8fe 100644 --- a/utils/ghc-pkg/Main.hs +++ b/utils/ghc-pkg/Main.hs @@ -268,6 +268,10 @@ usageHeader prog = substProg prog $ " for input for the graphviz tools. For example, to generate a PDF\n" ++ " of the dependency graph: ghc-pkg dot | tred | dot -Tpdf >pkgs.pdf\n" ++ "\n" ++ + " $p mermaid\n" ++ + " Generate a graph of the package dependencies in Mermaid format\n" ++ + " suitable for embedding in Markdown files.\n" ++ + "\n" ++ " $p find-module {module}\n" ++ " List registered packages exposing module {module} in the global\n" ++ " database, and also the user database if --user is given.\n" ++ @@ -464,6 +468,8 @@ runit verbosity cli nonopts = do (Just (Substring pkgarg_str m)) Nothing ["dot"] -> do showPackageDot verbosity cli + ["mermaid"] -> do + showPackageMermaid verbosity cli ["find-module", mod_name] -> do let match = maybe (==mod_name) id (substringCheck mod_name) listPackages verbosity cli Nothing (Just match) @@ -1643,6 +1649,27 @@ showPackageDot verbosity myflags = do ] putStrLn "}" +showPackageMermaid :: Verbosity -> [Flag] -> IO () +showPackageMermaid verbosity myflags = do + (_, GhcPkg.DbOpenReadOnly, flag_db_stack) <- + getPkgDatabases verbosity GhcPkg.DbOpenReadOnly + False{-use user-} True{-use cache-} False{-expand vars-} myflags + + let all_pkgs = allPackagesInStack flag_db_stack + ipix = PackageIndex.fromList all_pkgs + + putStrLn "```mermaid" + putStrLn "graph TD" + mapM_ putStrLn [ " " ++ from ++ " --> " ++ to + | p <- all_pkgs, + let from = display (mungedId p), + key <- depends p, + Just dep <- [PackageIndex.lookupUnitId ipix key], + let to = display (mungedId dep) + ] + putStrLn "```" + + -- ----------------------------------------------------------------------------- -- Prints the highest (hidden or exposed) version of a package From 2d5fb8627d756b60e5b9475c94aa496a9e43d48c Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Sat, 22 Mar 2025 20:57:22 +0900 Subject: [PATCH 66/84] Fixup build --- Makefile | 5 ++++- cabal.project.stage1 | 1 + cabal.project.stage1-rts | 3 ++- cabal.project.stage2 | 2 +- rts/rts.cabal | 2 +- 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index d0c24821f657..b2c606b429b6 100644 --- a/Makefile +++ b/Makefile @@ -63,6 +63,7 @@ endef CABAL_FLAGS += --store-dir $(OUT)/store --logs-dir $(OUT)/logs + CABAL_BUILD_FLAGS += --builddir $(OUT)/build CABAL_BUILD_FLAGS += --with-compiler $(GHC) --with-hc-pkg $(GHC)-pkg --with-build-compiler $(GHC0) --with-build-hc-pkg $(GHC0)-pkg @@ -72,6 +73,8 @@ CABAL_INSTALL_FLAGS += --installdir $(OUT)/bin CABAL_INSTALL_FLAGS += --overwrite-policy=always # If we copy the executables then ghc will recognise _stage1 as topdir (rather than a path in the store) CABAL_INSTALL_FLAGS += --install-method=copy +# stop cabal from being a fucking turd. +CABAL_INSTALL_FLAGS += --write-ghc-environment-files=never CABAL_INSTALL = $(CABAL) $(CABAL_FLAGS) install $(CABAL_BUILD_FLAGS) $(CABAL_INSTALL_FLAGS) @@ -180,7 +183,7 @@ STAGE2_BIN = $(addprefix _stage2/bin/,$(STAGE2_EXE)) $(STAGE2_BIN) &: OUT ?= $(abspath _stage2) $(STAGE2_BIN) &: GHC = $(abspath _stage1/bin/ghc) $(STAGE2_BIN) &: GHC0 = $(abspath _stage1/bin/ghc) -$(STAGE2_BIN) &: _stage1/bin/ghc _stage1/src/ghc-internal/.ready _stage2/rts.ready +$(STAGE2_BIN) &: _stage1/bin/ghc _stage1/src/ghc-internal/.ready _stage2/rts.ready _stage2/lib/settings @$(LIB) log mkdir -p $(@D) log export HADRIAN_SETTINGS="$$(cat ./HADRIAN_SETTINGS)" diff --git a/cabal.project.stage1 b/cabal.project.stage1 index a74f483c0f86..7adca7d02c6f 100644 --- a/cabal.project.stage1 +++ b/cabal.project.stage1 @@ -29,6 +29,7 @@ packages: -- other packages. Once Cabal upstream is recent enough, we can drop them. ./libraries/Cabal/Cabal ./libraries/Cabal/Cabal-syntax + ./libraries/Cabal/Cabal-hooks benchmarks: False tests: False diff --git a/cabal.project.stage1-rts b/cabal.project.stage1-rts index 571dd50fa449..f232b1ebe1c9 100644 --- a/cabal.project.stage1-rts +++ b/cabal.project.stage1-rts @@ -15,4 +15,5 @@ package rts program-options ghc-options: -fhide-source-paths -j -no-ghcversion-header --- constraints: any.base installed \ No newline at end of file +-- constraints: any.base installed, any.ghc-internal installed +-- allow-newer: Cabal-hooks:Cabal-syntax, Cabal-hooks:Cabal \ No newline at end of file diff --git a/cabal.project.stage2 b/cabal.project.stage2 index e4f48fec4b50..619a701e8fbc 100644 --- a/cabal.project.stage2 +++ b/cabal.project.stage2 @@ -40,7 +40,7 @@ packages: ./libraries/process ./libraries/semaphore-compat ./libraries/stm - ./libraries/system-cxx-std-lib + -- ./libraries/system-cxx-std-lib ./libraries/template-haskell ./libraries/terminfo ./libraries/text diff --git a/rts/rts.cabal b/rts/rts.cabal index a22ebc86901b..ebb33774cf19 100644 --- a/rts/rts.cabal +++ b/rts/rts.cabal @@ -1,4 +1,4 @@ -cabal-version: 3.8 +cabal-version: 3.14 name: rts version: 1.0.3 synopsis: The GHC runtime system From 819d1638150a84c9b3762aaf33fe8ec9f594406e Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Thu, 27 Mar 2025 15:03:16 +0900 Subject: [PATCH 67/84] Cleanup --- Makefile | 26 +++----------------------- Makefile.orig | 30 ------------------------------ cabal.project.stage2 | 37 ++++++++++++++++++++++++++++++------- rts/rts.cabal | 2 ++ 4 files changed, 35 insertions(+), 60 deletions(-) delete mode 100644 Makefile.orig diff --git a/Makefile b/Makefile index b2c606b429b6..0755b44f31c2 100644 --- a/Makefile +++ b/Makefile @@ -150,31 +150,11 @@ _stage1/src/ghc-internal/.ready: _stage1/src/ghc-internal/configure # the packages it built on the way to ghc stage2. _stage1/lib/package.conf.d: @$(LIB) + mkdir -p _stage1/lib _stage2/lib log _stage1/bin/ghc-pkg init $(PWD)/_stage2/store/$$(_stage1/bin/ghc --info | grep "Project Unit Id" | cut -d'"' -f4)/package.db log ln -sf $(PWD)/_stage2/store/$$(_stage1/bin/ghc --info | grep "Project Unit Id" | cut -d'"' -f4)/package.db _stage1/lib/package.conf.d log ln -sf $(PWD)/_stage2/store/$$(_stage1/bin/ghc --info | grep "Project Unit Id" | cut -d'"' -f4)/package.db _stage2/lib/package.conf.d -# This is basically the glue piece. We have a compiler `ghc`, that just doesn't have an RTS yet, and thus can't really link any executable. -# Ideally we'd just ask cabal to start building, by providing the boostrap compiler as GHC0 and the stage1 compiler as GHC. However, cabal -# will fall over itself trying to solve the packages even for the build-compiler. E.g. it sees it needs Cabal/Cabal-syntax, which are listed -# as packages in the cabal.project file, then tries to figure out how to build base, ... which just can't work. Ideally the build compiler -# would make a cut wrt to which packages it considers to rebuild. A small closure maybe. Maybe we should re-use non-reinstallable packages -# for this? Although I'd argue, I really don't want those in cabal anymore at some point. Another option would be to have build-packages -# in the cabal-project file, or just outright deny the build-compiler to consider building any of those packages and requesting in that -# special case that people just install --lib the necessary packages as needed? The idea of extending `build-packages` to the cabal.project -# file is growing on me. E.g. consider these packages under `build-packages` eligable to build from source when using the build-compiler -# e.g. for setup, and build-depends. -_stage2/rts.ready : OUT ?= $(abspath _stage2) -_stage2/rts.ready : GHC = $(abspath _stage1/bin/ghc) -_stage2/rts.ready : GHC0 = $(shell which ghc) -_stage2/rts.ready : _stage1/bin/ghc _stage1/lib/settings rts/configure _stage1/lib/package.conf.d - @$(LIB) - log mkdir -p $(@D) - log export PATH="$(abspath _stage1/bin):$(PATH)" - log $(CABAL_INSTALL) --lib --build-package-db=$(abspath _stage1/store)/$$($(GHC0) --info | grep "Project Unit Id" | cut -d'"' -f4)/package.db --project-file cabal.project.stage1-rts all - log touch $@ - - # Now that we've jammed the rts's into the stage1 compiler package.db, we can go on and just build the rest of the stage2 compiler. # This will automatically also mean, we end up with the relevant packages to ship alognside the stage2 compiler in the _stage1/lib/package.conf.d. STAGE2_EXE = ghc ghc-pkg @@ -182,8 +162,8 @@ STAGE2_BIN = $(addprefix _stage2/bin/,$(STAGE2_EXE)) $(STAGE2_BIN) &: OUT ?= $(abspath _stage2) $(STAGE2_BIN) &: GHC = $(abspath _stage1/bin/ghc) -$(STAGE2_BIN) &: GHC0 = $(abspath _stage1/bin/ghc) -$(STAGE2_BIN) &: _stage1/bin/ghc _stage1/src/ghc-internal/.ready _stage2/rts.ready _stage2/lib/settings +$(STAGE2_BIN) &: GHC0 = $(shell which ghc) +$(STAGE2_BIN) &: _stage1/bin/ghc _stage1/lib/settings rts/configure _stage1/lib/package.conf.d _stage1/src/ghc-internal/.ready @$(LIB) log mkdir -p $(@D) log export HADRIAN_SETTINGS="$$(cat ./HADRIAN_SETTINGS)" diff --git a/Makefile.orig b/Makefile.orig deleted file mode 100644 index d07edfae6fe9..000000000000 --- a/Makefile.orig +++ /dev/null @@ -1,30 +0,0 @@ -export CABAL := $(shell cabal update 2>&1 >/dev/null && cabal list-bin -v0 --project-dir libraries/Cabal cabal-install:exe:cabal) - -CPUS=$(shell mk/detect-cpu-count.sh) - -# Use CPU cores + 1 if not already set -THREADS=${THREADS:-$((CPUS + 1))} - -all: $(CABAL) ./booted - GHC=ghc-9.8.4 ./Build.hs - -cabal: $(CABAL) - -$(CABAL): - cabal build --project-dir libraries/Cabal cabal-install:exe:cabal - -./booted: - ./boot - touch $@ - -clean: - rm -f ./booted - rm -rf _build - -test: all - echo "using THREADS=${THREADS}" >&2 - TEST_HC=`pwd`/_build/bindist/bin/ghc \ - METRICS_FILE=`pwd`/_build/test-perf.csv \ - SUMMARY_FILE=`pwd`/_build/test-summary.txt \ - JUNIT_FILE=`pwd`/_build/test-junit.xml \ - make -C testsuite/tests test THREADS=${THREADS} diff --git a/cabal.project.stage2 b/cabal.project.stage2 index 619a701e8fbc..e59052b2679a 100644 --- a/cabal.project.stage2 +++ b/cabal.project.stage2 @@ -4,6 +4,14 @@ active-repositories: :none benchmarks: False tests: False +build-packages: + https://hackage.haskell.org/package/alex-3.5.2.0/alex-3.5.2.0.tar.gz + https://hackage.haskell.org/package/happy-2.1.5/happy-2.1.5.tar.gz + https://hackage.haskell.org/package/happy-lib-2.1.5/happy-lib-2.1.5.tar.gz + ./utils/deriveConstants + ./utils/genprimopcode + ./utils/genapply + packages: ./compiler ./ghc @@ -49,29 +57,44 @@ packages: ./libraries/unix ./libraries/Win32 ./libraries/xhtml - ./utils/deriveConstants - ./utils/genprimopcode ./utils/ghc-pkg ./utils/ghc-toolchain ./utils/hsc2hs ./utils/unlit - https://hackage.haskell.org/package/alex-3.5.2.0/alex-3.5.2.0.tar.gz - https://hackage.haskell.org/package/happy-2.1.5/happy-2.1.5.tar.gz - https://hackage.haskell.org/package/happy-lib-2.1.5/happy-lib-2.1.5.tar.gz + -- https://hackage.haskell.org/package/alex-3.5.2.0/alex-3.5.2.0.tar.gz + -- https://hackage.haskell.org/package/happy-2.1.5/happy-2.1.5.tar.gz + -- https://hackage.haskell.org/package/happy-lib-2.1.5/happy-lib-2.1.5.tar.gz -- https://hackage.haskell.org/package/os-string-2.0.7/os-string-2.0.7.tar.gz -- https://hackage.haskell.org/package/process-1.6.25.0/process-1.6.25.0.tar.gz -- https://hackage.haskell.org/package/time-1.14/time-1.14.tar.gz -- https://hackage.haskell.org/package/unix-2.8.6.0/unix-2.8.6.0.tar.gz + rts + rts-fs + rts-headers + +-- When building the rts{-headers,-fs} we do not have the ghcversion.h yet. +-- We basically have a bare ghc with no packages yet. To avoid the forced +-- need of ghcversion.h, we pass -no-ghcversion-header to ghc, to prevent it +-- from trying to pass `-include ghcversion.h`. + +package rts-headers + ghc-options: -v -no-ghcversion-header + +package rts-fs + ghc-options: -v -no-ghcversion-header + +package rts + flags: +table-next-to-code +leading-underscore + ghc-options: -v -no-ghcversion-header package hsc2hs flags: +in-ghc-tree package ghc - -- build-tool-depends: require genprimopcode, etc. used by Setup.hs -- internal-interpreter: otherwise our compiler has the internal -- interpreter but not the boot library we install -- FIXME: we should really install the lib we used to build stage2 - flags: +build-tool-depends +internal-interpreter + flags: +internal-interpreter ghc-options: -v3 package ghci diff --git a/rts/rts.cabal b/rts/rts.cabal index ebb33774cf19..5981039678fb 100644 --- a/rts/rts.cabal +++ b/rts/rts.cabal @@ -336,6 +336,8 @@ library ghc-options: -this-unit-id rts cmm-options: -this-unit-id rts + build-tool-depends: genapply:genapply, deriveConstants:deriveConstants + exposed: True exposed-modules: From 4614a24a7f9dd03305b8aea429404ab30bb2ef98 Mon Sep 17 00:00:00 2001 From: Sylvain Henry Date: Thu, 27 Mar 2025 09:45:48 +0100 Subject: [PATCH 68/84] Allow GHC to dump primop modules This patch adds two commands to GHC: - --print-prim-module: prints the contents of GHC.Internal.Prim - --print-prim-wrappers-module: prints the contents of GHC.Internal.PrimopWrappers These two commands can be used in ghc-internal's Setup.hs to generate these modules. This ensures that ghc-internal's primop code is always in sync with the GHC that builds it. It also avoids having to share code (primops.txt.pp and friends) between ghc-internal and ghc. (cherry picked from commit 4186a409f5bf885a250330b02cc342b312fe98bf) --- compiler/GHC/Builtin/PrimOps.hs | 10 +++++++++- compiler/Setup.hs | 2 ++ ghc/Main.hs | 12 +++++++++++- hadrian/src/Rules/Generate.hs | 2 ++ hadrian/src/Settings/Builders/GenPrimopCode.hs | 2 ++ utils/genprimopcode/Main.hs | 16 +++++++++++++++- 6 files changed, 41 insertions(+), 3 deletions(-) diff --git a/compiler/GHC/Builtin/PrimOps.hs b/compiler/GHC/Builtin/PrimOps.hs index d4d982427597..2273d34f9c3d 100644 --- a/compiler/GHC/Builtin/PrimOps.hs +++ b/compiler/GHC/Builtin/PrimOps.hs @@ -25,7 +25,9 @@ module GHC.Builtin.PrimOps ( getPrimOpResultInfo, isComparisonPrimOp, PrimOpResultInfo(..), - PrimCall(..) + PrimCall(..), + + primOpPrimModule, primOpWrappersModule ) where import GHC.Prelude @@ -171,6 +173,12 @@ primOpDocs :: [(FastString, String)] primOpDeprecations :: [(OccName, FastString)] #include "primop-deprecations.hs-incl" +primOpPrimModule :: String +#include "primop-prim-module.hs-incl" + +primOpWrappersModule :: String +#include "primop-wrappers-module.hs-incl" + {- ************************************************************************ * * diff --git a/compiler/Setup.hs b/compiler/Setup.hs index 23d233877e88..1614cd0227f8 100644 --- a/compiler/Setup.hs +++ b/compiler/Setup.hs @@ -57,6 +57,8 @@ primopIncls = , ("primop-vector-tycons.hs-incl" , "--primop-vector-tycons") , ("primop-docs.hs-incl" , "--wired-in-docs") , ("primop-deprecations.hs-incl" , "--wired-in-deprecations") + , ("primop-prim-module.hs-incl" , "--prim-module") + , ("primop-wrappers-module.hs-incl" , "--wrappers-module") ] ghcAutogen :: Verbosity -> LocalBuildInfo -> IO () diff --git a/ghc/Main.hs b/ghc/Main.hs index 87dbef1d89ef..9cee8ca7490c 100644 --- a/ghc/Main.hs +++ b/ghc/Main.hs @@ -38,6 +38,8 @@ import GHC.Platform import GHC.Platform.Ways import GHC.Platform.Host +import GHC.Builtin.PrimOps (primOpPrimModule, primOpWrappersModule) + #if defined(HAVE_INTERNAL_INTERPRETER) import GHCi.UI ( interactiveUI, ghciWelcomeMsg, defaultGhciSettings ) #endif @@ -147,6 +149,8 @@ main = do ShowVersion -> showVersion ShowNumVersion -> putStrLn cProjectVersion ShowOptions isInteractive -> showOptions isInteractive + PrintPrimModule -> liftIO $ putStrLn primOpPrimModule + PrintPrimWrappersModule -> liftIO $ putStrLn primOpWrappersModule Right postStartupMode -> -- start our GHC session GHC.runGhc mbMinusB $ do @@ -451,12 +455,16 @@ data PreStartupMode | ShowNumVersion -- ghc --numeric-version | ShowSupportedExtensions -- ghc --supported-extensions | ShowOptions Bool {- isInteractive -} -- ghc --show-options + | PrintPrimModule -- ghc --print-prim-module + | PrintPrimWrappersModule -- ghc --print-prim-wrappers-module -showVersionMode, showNumVersionMode, showSupportedExtensionsMode, showOptionsMode :: Mode +showVersionMode, showNumVersionMode, showSupportedExtensionsMode, showOptionsMode, printPrimModule, printPrimWrappersModule :: Mode showVersionMode = mkPreStartupMode ShowVersion showNumVersionMode = mkPreStartupMode ShowNumVersion showSupportedExtensionsMode = mkPreStartupMode ShowSupportedExtensions showOptionsMode = mkPreStartupMode (ShowOptions False) +printPrimModule = mkPreStartupMode PrintPrimModule +printPrimWrappersModule = mkPreStartupMode PrintPrimWrappersModule mkPreStartupMode :: PreStartupMode -> Mode mkPreStartupMode = Left @@ -622,6 +630,8 @@ mode_flags = , defFlag "-numeric-version" (PassFlag (setMode showNumVersionMode)) , defFlag "-info" (PassFlag (setMode showInfoMode)) , defFlag "-show-options" (PassFlag (setMode showOptionsMode)) + , defFlag "-print-prim-module" (PassFlag (setMode printPrimModule)) + , defFlag "-print-prim-wrappers-module" (PassFlag (setMode printPrimWrappersModule)) , defFlag "-supported-languages" (PassFlag (setMode showSupportedExtensionsMode)) , defFlag "-supported-extensions" (PassFlag (setMode showSupportedExtensionsMode)) , defFlag "-show-packages" (PassFlag (setMode showUnitsMode)) diff --git a/hadrian/src/Rules/Generate.hs b/hadrian/src/Rules/Generate.hs index d7745256467d..f0469a81af47 100644 --- a/hadrian/src/Rules/Generate.hs +++ b/hadrian/src/Rules/Generate.hs @@ -98,6 +98,8 @@ compilerDependencies = do , "primop-vector-uniques.hs-incl" , "primop-docs.hs-incl" , "primop-deprecations.hs-incl" + , "primop-prim-module.hs-incl" + , "primop-wrappers-module.hs-incl" , "GHC/Platform/Constants.hs" , "GHC/Settings/Config.hs" ] diff --git a/hadrian/src/Settings/Builders/GenPrimopCode.hs b/hadrian/src/Settings/Builders/GenPrimopCode.hs index d38dcf303853..625fadeba5b6 100644 --- a/hadrian/src/Settings/Builders/GenPrimopCode.hs +++ b/hadrian/src/Settings/Builders/GenPrimopCode.hs @@ -24,4 +24,6 @@ genPrimopCodeBuilderArgs = builder GenPrimopCode ? mconcat , output "//primop-vector-tycons.hs-incl" ? arg "--primop-vector-tycons" , output "//primop-docs.hs-incl" ? arg "--wired-in-docs" , output "//primop-deprecations.hs-incl" ? arg "--wired-in-deprecations" + , output "//primop-prim-module.hs-incl" ? arg "--prim-module" + , output "//primop-wrappers-module.hs-incl" ? arg "--wrappers-module" , output "//primop-usage.hs-incl" ? arg "--usage" ] diff --git a/utils/genprimopcode/Main.hs b/utils/genprimopcode/Main.hs index 604f1c55c165..2a3245a1fcbe 100644 --- a/utils/genprimopcode/Main.hs +++ b/utils/genprimopcode/Main.hs @@ -198,6 +198,12 @@ main = getArgs >>= \args -> "--make-haskell-source" -> putStr (gen_hs_source p_o_specs) + "--wrappers-module" + -> putStr (gen_wrappers_module p_o_specs) + + "--prim-module" + -> putStr (gen_hs_source_module p_o_specs) + "--wired-in-docs" -> putStr (gen_wired_in_docs p_o_specs) @@ -229,13 +235,18 @@ known_args "--make-haskell-source", "--make-latex-doc", "--wired-in-docs", - "--wired-in-deprecations" + "--wired-in-deprecations", + "--wrappers-module", + "--prim-module" ] ------------------------------------------------------------------ -- Code generators ----------------------------------------------- ------------------------------------------------------------------ +gen_hs_source_module :: Info -> String +gen_hs_source_module info = "primOpPrimModule = " ++ show (gen_hs_source info) + gen_hs_source :: Info -> String gen_hs_source (Info defaults entries) = "{-\n" @@ -461,6 +472,9 @@ In PrimopWrappers we set some crucial GHC options a very simple module and there is no optimisation to be done -} +gen_wrappers_module :: Info -> String +gen_wrappers_module info = "primOpWrappersModule = " ++ show (gen_wrappers info) + gen_wrappers :: Info -> String gen_wrappers (Info _ entries) = "-- | Users should not import this module. It is GHC internal only.\n" From d4f778e5497eb2a08d6d381bd9326133e9a2d3b7 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Thu, 27 Mar 2025 20:27:14 +0900 Subject: [PATCH 69/84] ghc-internal, use GHC to dump GHC.Internal.Prim[opWrappers] --- libraries/ghc-internal/Setup.hs | 70 ++++++++++++++++++++++- libraries/ghc-internal/ghc-internal.cabal | 12 ++-- 2 files changed, 75 insertions(+), 7 deletions(-) diff --git a/libraries/ghc-internal/Setup.hs b/libraries/ghc-internal/Setup.hs index 54f57d6f118a..540558fa583b 100644 --- a/libraries/ghc-internal/Setup.hs +++ b/libraries/ghc-internal/Setup.hs @@ -1,6 +1,72 @@ -module Main (main) where +{-# LANGUAGE CPP #-} +module Main where import Distribution.Simple +import Distribution.Simple.BuildPaths +import Distribution.Types.ComponentLocalBuildInfo +import Distribution.Types.ComponentName (ComponentName(CLibName)) +import Distribution.Types.LocalBuildInfo +import Distribution.Types.LibraryName (LibraryName(LMainLibName)) +import Distribution.Verbosity +import Distribution.Simple.Program +import Distribution.Simple.Utils +import Distribution.Simple.Setup +#if MIN_VERSION_Cabal(3,14,0) +import Distribution.Simple.LocalBuildInfo (interpretSymbolicPathLBI) +#endif + +import System.IO +import System.Process +import System.Directory +import System.FilePath +import Control.Monad +import Data.Char +import qualified Data.Map as Map +import GHC.ResponseFile +import System.Environment main :: IO () -main = defaultMainWithHooks autoconfUserHooks +main = defaultMainWithHooks ghcHooks + where + ghcHooks = autoconfUserHooks + { postConf = \args cfg pd lbi -> do + let verbosity = fromFlagOrDefault minBound (configVerbosity cfg) + ghcAutogen verbosity lbi + postConf autoconfUserHooks args cfg pd lbi + } + +ghcAutogen :: Verbosity -> LocalBuildInfo -> IO () +ghcAutogen verbosity lbi = do + +#if MIN_VERSION_Cabal(3,14,0) + let fromSymPath = interpretSymbolicPathLBI lbi +#else + let fromSymPath = id +#endif + notice verbosity "Running ghc-internal pre-build hook: Generating Prim modules..." + + -- Get GHC path from LocalBuildInfo + let compilerInfo = compiler lbi + -- ghcPath <- case compilerFlavor compilerInfo of + -- GHC -> return $ compilerPath compilerInfo + -- _ -> fail "This setup script requires GHC." + + (ghc ,withPrograms) <- requireProgram normal ghcProgram (withPrograms lbi) + + -- Get autogen directory + let autogenDir = fromSymPath (autogenPackageModulesDir lbi) + let internalDir = autogenDir "GHC" "Internal" + + -- Ensure target directory exists + createDirectoryIfMissing True internalDir + + -- Define output file paths + let primHsPath = internalDir "Prim.hs" + let primWrappersHsPath = internalDir "PrimopWrappers.hs" + + -- Run GHC commands + notice verbosity $ "Generating " ++ primHsPath + getProgramOutput normal ghc ["--print-prim-module"] >>= rewriteFileEx verbosity primHsPath + + notice verbosity $ "Generating " ++ primWrappersHsPath + getProgramOutput normal ghc ["--print-prim-wrappers-module"] >>= rewriteFileEx verbosity primWrappersHsPath diff --git a/libraries/ghc-internal/ghc-internal.cabal b/libraries/ghc-internal/ghc-internal.cabal index a4c672cf3b4e..3ad2fc72cfc6 100644 --- a/libraries/ghc-internal/ghc-internal.cabal +++ b/libraries/ghc-internal/ghc-internal.cabal @@ -8,14 +8,13 @@ maintainer: The GHC Developers bug-reports: https://gitlab.haskell.org/ghc/ghc/-/issues/new synopsis: Basic libraries category: Prelude -build-type: Configure +build-type: Custom description: This package contains the implementation of GHC's standard libraries and is not intended for use by end-users. . Users should instead use either the @base@ or @ghc-experimental@ packages - extra-tmp-files: autom4te.cache ghc-internal.buildinfo @@ -41,6 +40,9 @@ extra-source-files: include/HsIntegerGmp.h.in install-sh +custom-setup + setup-depends: base >= 3 && < 5, Cabal >= 1.6 && <3.16, directory, process, filepath, containers + source-repository head type: git location: https://gitlab.haskell.org/ghc/ghc.git @@ -342,9 +344,9 @@ Library -- Cabal expects autogen modules to be some specific directories, not in the -- source dirs... - -- autogen-modules: - -- GHC.Internal.Prim - -- GHC.Internal.PrimopWrappers + autogen-modules: + GHC.Internal.Prim + GHC.Internal.PrimopWrappers other-modules: GHC.Internal.Data.Typeable.Internal From f41df9d310df569598851bc1479d8d29fd2d0133 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Thu, 27 Mar 2025 20:27:48 +0900 Subject: [PATCH 70/84] Drop nonsense. --- Makefile | 31 +------------------------------ cabal.project.stage2 | 3 +-- 2 files changed, 2 insertions(+), 32 deletions(-) diff --git a/Makefile b/Makefile index 0755b44f31c2..edb5ca0ab9da 100644 --- a/Makefile +++ b/Makefile @@ -113,35 +113,6 @@ _stage2/lib/settings: _stage1/bin/ghc-toolchain-bin stage1: _stage1/bin/ghc _stage1/lib/settings - -# this should be in the setup of compiler.cabal? -_stage1/src/compiler/GHC/Builtin/primops.txt: compiler/GHC/Builtin/primops.txt.pp - @$(LIB) - mkdir -p $(@D) - log cc -E -undef -traditional -P -x c $< >$@ - -# This should be in the setup of ghc-internal.cabal? -_stage1/src/ghc-internal/ghc-internal.cabal: - @$(LIB) - rm -rf $(@D) - mkdir -p $(@D) - cp -r libraries/ghc-internal/* $(@D) - -_stage1/src/ghc-internal/src/GHC/Internal/Prim.hs: _stage1/src/compiler/GHC/Builtin/primops.txt | _stage1/src/ghc-internal/ghc-internal.cabal - @$(LIB) - mkdir -p $(@D) - log _stage1/bin/genprimopcode --make-haskell-source < $< > $@ - -_stage1/src/ghc-internal/src/GHC/Internal/PrimopWrappers.hs: _stage1/src/compiler/GHC/Builtin/primops.txt | _stage1/src/ghc-internal/ghc-internal.cabal - @$(LIB) - mkdir -p $(@D) - log _stage1/bin/genprimopcode --make-haskell-wrappers < $< > $@ - -_stage1/src/ghc-internal/.ready: _stage1/src/ghc-internal/ghc-internal.cabal -_stage1/src/ghc-internal/.ready: _stage1/src/ghc-internal/src/GHC/Internal/Prim.hs -_stage1/src/ghc-internal/.ready: _stage1/src/ghc-internal/src/GHC/Internal/PrimopWrappers.hs -_stage1/src/ghc-internal/.ready: _stage1/src/ghc-internal/configure - # We need this folder to exist prior to running anything with _stage1/bin/ghc and cabal, # because that will result in ghc-pkg being invoked. That one looking into the ../lib/settings file. # Finding that package.conf.d is the global package db, and then falling over itself because that @@ -163,7 +134,7 @@ STAGE2_BIN = $(addprefix _stage2/bin/,$(STAGE2_EXE)) $(STAGE2_BIN) &: OUT ?= $(abspath _stage2) $(STAGE2_BIN) &: GHC = $(abspath _stage1/bin/ghc) $(STAGE2_BIN) &: GHC0 = $(shell which ghc) -$(STAGE2_BIN) &: _stage1/bin/ghc _stage1/lib/settings rts/configure _stage1/lib/package.conf.d _stage1/src/ghc-internal/.ready +$(STAGE2_BIN) &: _stage1/bin/ghc _stage1/lib/settings rts/configure libraries/ghc-internal/configure _stage1/lib/package.conf.d @$(LIB) log mkdir -p $(@D) log export HADRIAN_SETTINGS="$$(cat ./HADRIAN_SETTINGS)" diff --git a/cabal.project.stage2 b/cabal.project.stage2 index e59052b2679a..de552bca8d42 100644 --- a/cabal.project.stage2 +++ b/cabal.project.stage2 @@ -34,8 +34,7 @@ packages: ./libraries/ghc-experimental ./libraries/ghc-heap ./libraries/ghci - -- ./libraries/ghc-internal - _stage1/src/ghc-internal + ./libraries/ghc-internal ./libraries/ghc-platform ./libraries/ghc-prim ./libraries/haskeline From 752123204c1304c3f3c223b9276bac24682132f0 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Fri, 28 Mar 2025 09:42:06 +0900 Subject: [PATCH 71/84] Further cleanup --- Makefile | 112 +++++++++------------------------------ cabal.project.deps | 11 ---- cabal.project.stage1-rts | 19 ------- cabal.project.stage2 | 7 ++- 4 files changed, 28 insertions(+), 121 deletions(-) delete mode 100644 cabal.project.deps delete mode 100644 cabal.project.stage1-rts diff --git a/Makefile b/Makefile index edb5ca0ab9da..b1c1528145bd 100644 --- a/Makefile +++ b/Makefile @@ -1,48 +1,11 @@ -# The Makefile to build GHC with cabal -# -# Pre-requisites: -# There are a few tools we expect to exist prior to building this. These are -# documented here. If you end up creating more dependencies, be explicit about -# them here at the start. -# -# - make -# - ghc (a recent enough GHC to function at the boostrap compiler) -# - cabal (a recent enough cabal-install executable to build the cabal pkgs -# and the necessary changes for dual stage, ...) -# -# Build Plan: -# In general GHC is built in two stages to ensure the compiler is linked against -# libraries built by the same compiler. This allows the compiler to have the -# same abi as the code it produces. This does not work for cross compilers, as -# we can't build a compiler for the host platform using a host->target compiler. -# -# Stage 0 (boostrap stage) -# In this stage we build just enough of the compiler dependencies to build the -# Stage 1 compiler (ghc executable). We want to build the ghc executable, but -# may need to build extra libraries that are newer than the ones that come with -# the bootstrap compiler. This crucially also means, these libraries are stable -# (as long as their source doesn't change) to be cached. -# -# Stage 1 -# We now have the boostrap libraries and a compiler (ghc1) built with (ghc0) the -# ghc0-libraries + extra libraries built with ghc0. Thus we have a ghc1 but no -# libraries yet. We now build all the libraries required to build the compiler -# (from ø) using ghc1. First we need to build the rts with ghc1. Then build all -# the libraries necessary to build ghc2. And then build ghc2 using ghc1 with the -# newly build libraries. -# -# Stage 2 -# This gives us our stage2 compiler (ghc2, all it's deps built with ghc1). This -# is the pair we package up. - SHELL := bash .ONESHELL: .SHELLFLAGS := -eu -o pipefail -c .DELETE_ON_ERROR: -MAKEFLAGS += --warn-undefined-variables -MAKEFLAGS += --no-builtin-rules +MAKEFLAGS += --warn-undefined-variables --no-builtin-rules -all: stage1-boot +# Default target +all: stage2 CABAL ?= cabal GHC0 ?= ghc @@ -62,25 +25,21 @@ endef log autoreconf $(@D) CABAL_FLAGS += --store-dir $(OUT)/store --logs-dir $(OUT)/logs - - -CABAL_BUILD_FLAGS += --builddir $(OUT)/build -CABAL_BUILD_FLAGS += --with-compiler $(GHC) --with-hc-pkg $(GHC)-pkg --with-build-compiler $(GHC0) --with-build-hc-pkg $(GHC0)-pkg +CABAL_BUILD_FLAGS += --builddir $(OUT)/build --with-compiler $(GHC) --with-hc-pkg $(GHC)-pkg --with-build-compiler $(GHC0) --with-build-hc-pkg $(GHC0)-pkg +CABAL_INSTALL_FLAGS += --installdir $(OUT)/bin --overwrite-policy=always --install-method=copy --write-ghc-environment-files=never CABAL_BUILD = $(CABAL) $(CABAL_FLAGS) build $(CABAL_BUILD_FLAGS) - -CABAL_INSTALL_FLAGS += --installdir $(OUT)/bin -CABAL_INSTALL_FLAGS += --overwrite-policy=always -# If we copy the executables then ghc will recognise _stage1 as topdir (rather than a path in the store) -CABAL_INSTALL_FLAGS += --install-method=copy -# stop cabal from being a fucking turd. -CABAL_INSTALL_FLAGS += --write-ghc-environment-files=never - CABAL_INSTALL = $(CABAL) $(CABAL_FLAGS) install $(CABAL_BUILD_FLAGS) $(CABAL_INSTALL_FLAGS) -STAGE1_EXE = ghc ghc-pkg ghc-toolchain-bin deriveConstants genprimopcode genapply unlit +STAGE1_EXE = ghc ghc-pkg ghc-toolchain-bin STAGE1_BIN = $(addprefix _stage1/bin/,$(STAGE1_EXE)) +STAGE2_EXE = ghc ghc-pkg +STAGE2_BIN = $(addprefix _stage2/bin/,$(STAGE2_EXE)) + +TARGET := $(shell cc -dumpmachine) + +# Stage 1 $(STAGE1_BIN) &: OUT ?= $(abspath _stage1) $(STAGE1_BIN) &: override GHC=$(GHC0) $(STAGE1_BIN) &: @@ -89,36 +48,11 @@ $(STAGE1_BIN) &: log export HADRIAN_SETTINGS="$$(cat ./HADRIAN_SETTINGS)" log $(CABAL_INSTALL) --project-file cabal.project.stage1 $(addprefix exe:,$(STAGE1_EXE)) -TARGET := $(shell cc -dumpmachine) - -# FIXME: why do they all claim ("target has subsections via symbols","NO") for -# macOS? 9.8 seems to claim this as well. This seems wrong and will severely -# impact dead-stripability if ghc does not emit subsection via symbols. wtf. -# I remain that `ghc-toolchain` is a bad tool and should just be a configure -# script for ghc-bin producing a `settings` file according to a passed -# `--target`. I also think most of the settins file values should have sensible -# defaults: install_name_tool = install_name_tool, ... that do not need to be -# explicitly listed in the settings file unless you want to override them. - -_stage1/lib/settings: _stage1/bin/ghc-toolchain-bin +%/settings: _stage1/bin/ghc-toolchain-bin @$(LIB) mkdir -p $(@D) log _stage1/bin/ghc-toolchain-bin --cc=cc --cxx=c++ --install-name-tool=install_name_tool --otool=otool --output-settings -t $(TARGET) -o $@ -_stage2/lib/settings: _stage1/bin/ghc-toolchain-bin - @$(LIB) - mkdir -p $(@D) - log _stage1/bin/ghc-toolchain-bin --cc=cc --cxx=c++ --install-name-tool=install_name_tool --otool=otool --output-settings -t $(TARGET) -o $@ - - -stage1: _stage1/bin/ghc _stage1/lib/settings - -# We need this folder to exist prior to running anything with _stage1/bin/ghc and cabal, -# because that will result in ghc-pkg being invoked. That one looking into the ../lib/settings file. -# Finding that package.conf.d is the global package db, and then falling over itself because that -# folder doesn't exist after building the ghc executable. So here we link the cabal _store_ package-db -# into the _stage1/lib/package.conf.d folder, thus the new ghc compiler will always have access to all -# the packages it built on the way to ghc stage2. _stage1/lib/package.conf.d: @$(LIB) mkdir -p _stage1/lib _stage2/lib @@ -126,11 +60,9 @@ _stage1/lib/package.conf.d: log ln -sf $(PWD)/_stage2/store/$$(_stage1/bin/ghc --info | grep "Project Unit Id" | cut -d'"' -f4)/package.db _stage1/lib/package.conf.d log ln -sf $(PWD)/_stage2/store/$$(_stage1/bin/ghc --info | grep "Project Unit Id" | cut -d'"' -f4)/package.db _stage2/lib/package.conf.d -# Now that we've jammed the rts's into the stage1 compiler package.db, we can go on and just build the rest of the stage2 compiler. -# This will automatically also mean, we end up with the relevant packages to ship alognside the stage2 compiler in the _stage1/lib/package.conf.d. -STAGE2_EXE = ghc ghc-pkg -STAGE2_BIN = $(addprefix _stage2/bin/,$(STAGE2_EXE)) +stage1: $(STAGE1_BIN) _stage1/lib/settings _stage1/lib/package.conf.d +# Stage 2 $(STAGE2_BIN) &: OUT ?= $(abspath _stage2) $(STAGE2_BIN) &: GHC = $(abspath _stage1/bin/ghc) $(STAGE2_BIN) &: GHC0 = $(shell which ghc) @@ -140,7 +72,13 @@ $(STAGE2_BIN) &: _stage1/bin/ghc _stage1/lib/settings rts/configure libraries/gh log export HADRIAN_SETTINGS="$$(cat ./HADRIAN_SETTINGS)" log $(CABAL_INSTALL) --package-db=$(abspath _stage1/lib/package.conf.d) --project-file cabal.project.stage2 $(addprefix exe:,$(STAGE2_EXE)) -# 1. git clean -xfd -# 2. make _stage1/bin/ghc -# 3. make _stage2/bin/ghc -# 4. make _stage2/lib/settings \ No newline at end of file +stage2: stage1 _stage2/lib/settings $(STAGE2_BIN) + +# Clean up +clean: + rm -rf _stage1 _stage2 + +# Usage instructions +# 1. make clean +# 2. make stage1 +# 3. make stage2 \ No newline at end of file diff --git a/cabal.project.deps b/cabal.project.deps deleted file mode 100644 index a36ad71747ff..000000000000 --- a/cabal.project.deps +++ /dev/null @@ -1,11 +0,0 @@ -allow-boot-library-installs: True - -benchmarks: False -tests: False - -packages: - libraries/Cabal/Cabal - libraries/Cabal/Cabal-syntax - -program-options - ghc-options: -fhide-source-paths -j \ No newline at end of file diff --git a/cabal.project.stage1-rts b/cabal.project.stage1-rts deleted file mode 100644 index f232b1ebe1c9..000000000000 --- a/cabal.project.stage1-rts +++ /dev/null @@ -1,19 +0,0 @@ -allow-boot-library-installs: True - -benchmarks: False -tests: False - -packages: - rts - rts-fs - rts-headers - -package rts - flags: +table-next-to-code +leading-underscore - ghc-options: -v - -program-options - ghc-options: -fhide-source-paths -j -no-ghcversion-header - --- constraints: any.base installed, any.ghc-internal installed --- allow-newer: Cabal-hooks:Cabal-syntax, Cabal-hooks:Cabal \ No newline at end of file diff --git a/cabal.project.stage2 b/cabal.project.stage2 index de552bca8d42..2028e3c665f2 100644 --- a/cabal.project.stage2 +++ b/cabal.project.stage2 @@ -77,14 +77,14 @@ packages: -- from trying to pass `-include ghcversion.h`. package rts-headers - ghc-options: -v -no-ghcversion-header + ghc-options: -no-ghcversion-header package rts-fs - ghc-options: -v -no-ghcversion-header + ghc-options: -no-ghcversion-header package rts flags: +table-next-to-code +leading-underscore - ghc-options: -v -no-ghcversion-header + ghc-options: -no-ghcversion-header package hsc2hs flags: +in-ghc-tree @@ -94,7 +94,6 @@ package ghc -- interpreter but not the boot library we install -- FIXME: we should really install the lib we used to build stage2 flags: +internal-interpreter - ghc-options: -v3 package ghci flags: +internal-interpreter From 1d3ed082571294d7167e14999eb62bdd2cee1971 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Fri, 28 Mar 2025 13:15:10 +0900 Subject: [PATCH 72/84] program-options doesn't appear to work. --- cabal.project.stage1 | 5 +++-- cabal.project.stage2 | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cabal.project.stage1 b/cabal.project.stage1 index 7adca7d02c6f..20a3691723d8 100644 --- a/cabal.project.stage1 +++ b/cabal.project.stage1 @@ -48,6 +48,7 @@ package ghc-boot-th flags: +bootstrap package hsc2hs + -- FIXME: What's this for? flags: +in-ghc-tree -- allow template-haskell with newer ghc-boot-th @@ -57,5 +58,5 @@ constraints: -- FIXME: template-haskell 2.23 is too recent when booting with 9.8.4 template-haskell <= 2.22 -program-options - ghc-options: -fhide-source-paths -j \ No newline at end of file +package * + ghc-options: -fhide-source-paths -j diff --git a/cabal.project.stage2 b/cabal.project.stage2 index 2028e3c665f2..8f0489628342 100644 --- a/cabal.project.stage2 +++ b/cabal.project.stage2 @@ -104,11 +104,11 @@ package ghc-internal package ghc-bin -- FIXME: we don't have the threaded RTS yet. - flags: -threaded + flags: -threaded +internal-interpreter package text -- FIXME: avoid having to deal with system-cxx-std-lib fake package for now flags: -simdutf -program-options - ghc-options: -fhide-source-paths -j \ No newline at end of file +package * + ghc-options: -fhide-source-paths -j From a1e5d65ed6044347cadcc448ae67fa639097b4cf Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Fri, 28 Mar 2025 13:15:20 +0900 Subject: [PATCH 73/84] Cleanup: Try to use the same stores --- Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index b1c1528145bd..5560f1fc8695 100644 --- a/Makefile +++ b/Makefile @@ -24,8 +24,8 @@ endef @$(LIB) log autoreconf $(@D) -CABAL_FLAGS += --store-dir $(OUT)/store --logs-dir $(OUT)/logs -CABAL_BUILD_FLAGS += --builddir $(OUT)/build --with-compiler $(GHC) --with-hc-pkg $(GHC)-pkg --with-build-compiler $(GHC0) --with-build-hc-pkg $(GHC0)-pkg +CABAL_FLAGS += --store-dir $(abspath _build/store) --logs-dir $(abspath _build/logs) -j --ghc-option=-fhide-source-paths --ghc-option=-j +CABAL_BUILD_FLAGS += --builddir $(abspath _build/build) --with-compiler $(GHC) --with-hc-pkg $(GHC)-pkg --with-build-compiler $(GHC0) --with-build-hc-pkg $(GHC0)-pkg CABAL_INSTALL_FLAGS += --installdir $(OUT)/bin --overwrite-policy=always --install-method=copy --write-ghc-environment-files=never CABAL_BUILD = $(CABAL) $(CABAL_FLAGS) build $(CABAL_BUILD_FLAGS) @@ -56,9 +56,9 @@ $(STAGE1_BIN) &: _stage1/lib/package.conf.d: @$(LIB) mkdir -p _stage1/lib _stage2/lib - log _stage1/bin/ghc-pkg init $(PWD)/_stage2/store/$$(_stage1/bin/ghc --info | grep "Project Unit Id" | cut -d'"' -f4)/package.db - log ln -sf $(PWD)/_stage2/store/$$(_stage1/bin/ghc --info | grep "Project Unit Id" | cut -d'"' -f4)/package.db _stage1/lib/package.conf.d - log ln -sf $(PWD)/_stage2/store/$$(_stage1/bin/ghc --info | grep "Project Unit Id" | cut -d'"' -f4)/package.db _stage2/lib/package.conf.d + log _stage1/bin/ghc-pkg init $(abspath _build/store)/$$(_stage1/bin/ghc --info | grep "Project Unit Id" | cut -d'"' -f4)/package.db + log ln -sf $(abspath _build/store)/$$(_stage1/bin/ghc --info | grep "Project Unit Id" | cut -d'"' -f4)/package.db _stage1/lib/package.conf.d + log ln -sf $(abspath _build/store)/$$(_stage1/bin/ghc --info | grep "Project Unit Id" | cut -d'"' -f4)/package.db _stage2/lib/package.conf.d stage1: $(STAGE1_BIN) _stage1/lib/settings _stage1/lib/package.conf.d From 2bc593b565b6a22c79ca4da3728f6bdbde9833e8 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Sat, 5 Apr 2025 17:03:26 +0900 Subject: [PATCH 74/84] More cleanup --- Makefile | 20 +++++++++++++------- cabal.project.stage2 | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 5560f1fc8695..66b8ca680931 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,7 @@ STAGE2_BIN = $(addprefix _stage2/bin/,$(STAGE2_EXE)) TARGET := $(shell cc -dumpmachine) -# Stage 1 +# Stage 1 -- should we pass prefix=stage1- here? And get stage1-ghc, stage1-ghc-pkg, ...? $(STAGE1_BIN) &: OUT ?= $(abspath _stage1) $(STAGE1_BIN) &: override GHC=$(GHC0) $(STAGE1_BIN) &: @@ -56,9 +56,15 @@ $(STAGE1_BIN) &: _stage1/lib/package.conf.d: @$(LIB) mkdir -p _stage1/lib _stage2/lib - log _stage1/bin/ghc-pkg init $(abspath _build/store)/$$(_stage1/bin/ghc --info | grep "Project Unit Id" | cut -d'"' -f4)/package.db - log ln -sf $(abspath _build/store)/$$(_stage1/bin/ghc --info | grep "Project Unit Id" | cut -d'"' -f4)/package.db _stage1/lib/package.conf.d - log ln -sf $(abspath _build/store)/$$(_stage1/bin/ghc --info | grep "Project Unit Id" | cut -d'"' -f4)/package.db _stage2/lib/package.conf.d + log _stage1/bin/ghc-pkg init $(abspath _build/store)/$$(_stage1/bin/ghc --info | grep "Project Unit Id" | sed -E 's/.*_(ghc-[0-9.]+-[0-9a-z]+).*/\1/')/package.db + log ln -sf $(abspath _build/store)/$$(_stage1/bin/ghc --info | grep "Project Unit Id" | sed -E 's/.*_(ghc-[0-9.]+-[0-9a-z]+).*/\1/')/package.db _stage1/lib/package.conf.d + log ln -sf $(abspath _build/store)/$$(_stage1/bin/ghc --info | grep "Project Unit Id" | sed -E 's/.*_(ghc-[0-9.]+-[0-9a-z]+).*/\1/')/package.db _stage2/lib/package.conf.d + +# stage0 is boot +_stage0/lib/package.conf.d: + @$(LIB) + mkdir -p _stage0/lib + log ln -sf $(abspath _build/store)/$$(ghc --info | grep "Project Unit Id" | sed -E 's/.*[_]*(ghc-[0-9.]+-[0-9a-z]+).*/\1/')/package.db _stage0/lib/package.conf.d stage1: $(STAGE1_BIN) _stage1/lib/settings _stage1/lib/package.conf.d @@ -66,17 +72,17 @@ stage1: $(STAGE1_BIN) _stage1/lib/settings _stage1/lib/package.conf.d $(STAGE2_BIN) &: OUT ?= $(abspath _stage2) $(STAGE2_BIN) &: GHC = $(abspath _stage1/bin/ghc) $(STAGE2_BIN) &: GHC0 = $(shell which ghc) -$(STAGE2_BIN) &: _stage1/bin/ghc _stage1/lib/settings rts/configure libraries/ghc-internal/configure _stage1/lib/package.conf.d +$(STAGE2_BIN) &: _stage1/bin/ghc _stage1/lib/settings rts/configure libraries/ghc-internal/configure _stage0/lib/package.conf.d _stage1/lib/package.conf.d @$(LIB) log mkdir -p $(@D) log export HADRIAN_SETTINGS="$$(cat ./HADRIAN_SETTINGS)" - log $(CABAL_INSTALL) --package-db=$(abspath _stage1/lib/package.conf.d) --project-file cabal.project.stage2 $(addprefix exe:,$(STAGE2_EXE)) + log $(CABAL_INSTALL) --package-db=$(abspath _stage1/lib/package.conf.d) --build-package-db=$(abspath _stage0/lib/package.conf.d) --project-file cabal.project.stage2 $(addprefix exe:,$(STAGE2_EXE)) stage2: stage1 _stage2/lib/settings $(STAGE2_BIN) # Clean up clean: - rm -rf _stage1 _stage2 + rm -rf _stage0 _stage1 _stage2 _build # Usage instructions # 1. make clean diff --git a/cabal.project.stage2 b/cabal.project.stage2 index 8f0489628342..c83a79a5a17e 100644 --- a/cabal.project.stage2 +++ b/cabal.project.stage2 @@ -82,10 +82,14 @@ package rts-headers package rts-fs ghc-options: -no-ghcversion-header +-- FIXME: TNTC should be configurable. +-- FIXME: leading-underscore is platform dependent (only mach-o!) package rts flags: +table-next-to-code +leading-underscore ghc-options: -no-ghcversion-header +-- FIXME: Still not sure what in-ghc-tree is. Maybe we should specify/explain +-- this HERE! package hsc2hs flags: +in-ghc-tree @@ -111,4 +115,33 @@ package text flags: -simdutf package * + -- try to make everything build faster 😓 ghc-options: -fhide-source-paths -j + +constraints: + -- these build.* constraints will ensure that we do not rebuild any library + -- during stage2 that we had built during stage1 anyway. build.* constraints + -- only apply to Setup.hs / build-tool dependencies, and are built with our + -- bootstrap compiler anyway. + -- + -- Stage1: GHC0=GHC1=bootstrap-ghc + -- .-<--' + -- Stage2: GHC0=bootstrap-ghc, GHC1=stage1-ghc + -- .---------<---------' + -- Stage3: GHC0=stage1-ghc, GHC1=stage2-ghc + -- + build.rts installed, + build.template-haskell installed, + build.process installed, + build.file-io installed, + build.containers installed, + build.directory installed, + build.Cabal-syntax installed, + build.Cabal installed + + -- FIXME: we don't seem to be able to request build-tools to be "installed". + -- build.genprimopcode installed, + -- build.genapply installed, + -- build.deriveConstants installed, + -- build.alex installed, + -- build.happy installed \ No newline at end of file From da72419670c45e8610d783f1e6000efbc0b6e0e0 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Mon, 7 Apr 2025 19:58:38 +0900 Subject: [PATCH 75/84] bump cabal --- libraries/Cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/Cabal b/libraries/Cabal index 367c5c61c361..7e50837ade18 160000 --- a/libraries/Cabal +++ b/libraries/Cabal @@ -1 +1 @@ -Subproject commit 367c5c61c361bf4b4d814eeff494d322840e64cb +Subproject commit 7e50837ade188504d1401bad932a5b8b3769661e From 38452d944a3c3b70a5b9d4e302ab081187785580 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Thu, 10 Apr 2025 08:34:29 +0900 Subject: [PATCH 76/84] Add support for UnitFlags (This requires a recent enough Cabal!) --- libraries/ghc-boot/GHC/Unit/Database.hs | 13 ++++++++++++- utils/ghc-pkg/Main.hs | 6 ++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/libraries/ghc-boot/GHC/Unit/Database.hs b/libraries/ghc-boot/GHC/Unit/Database.hs index ac6847615604..86dfba36b814 100644 --- a/libraries/ghc-boot/GHC/Unit/Database.hs +++ b/libraries/ghc-boot/GHC/Unit/Database.hs @@ -150,6 +150,14 @@ data GenericUnitInfo srcpkgid srcpkgname uid modulename mod = GenericUnitInfo -- components that can be registered in a database and used by other -- modules. + , unitFlags :: [ST.ShortText] + -- ^ Flags used to build this unit. These are the flags that were + -- specified/or automatically elected when cabal built this unit. + -- + -- This is a list of strings, each string is a flag name. The order of + -- the flags is not important. They are prefixed with + or - to indicate + -- whether the flag was enabled or disabled. + , unitAbiHash :: ST.ShortText -- ^ ABI hash used to avoid mixing up units compiled with different -- dependencies, compiler, options, etc. @@ -536,7 +544,7 @@ instance Binary DbUnitInfo where unitId unitInstanceOf unitInstantiations unitPackageId unitPackageName unitPackageVersion - unitComponentName + unitComponentName unitFlags unitAbiHash unitDepends unitAbiDepends unitImportDirs unitLibraries unitExtDepLibsSys unitExtDepLibsGhc unitLibraryDirs unitLibraryDynDirs @@ -550,6 +558,7 @@ instance Binary DbUnitInfo where put unitPackageName put unitPackageVersion put unitComponentName + put unitFlags put unitId put unitInstanceOf put unitInstantiations @@ -581,6 +590,7 @@ instance Binary DbUnitInfo where unitPackageName <- get unitPackageVersion <- get unitComponentName <- get + unitFlags <- get unitId <- get unitInstanceOf <- get unitInstantiations <- get @@ -614,6 +624,7 @@ instance Binary DbUnitInfo where unitPackageName unitPackageVersion unitComponentName + unitFlags unitAbiHash unitDepends unitAbiDepends diff --git a/utils/ghc-pkg/Main.hs b/utils/ghc-pkg/Main.hs index 3b62bbd6c8fe..3e110a5548e2 100644 --- a/utils/ghc-pkg/Main.hs +++ b/utils/ghc-pkg/Main.hs @@ -44,6 +44,7 @@ import Distribution.Text import Distribution.Version import Distribution.Backpack import Distribution.Pretty (Pretty (..)) +import Distribution.Types.Flag (showFlagValue, unFlagAssignment) import Distribution.Types.UnqualComponentName import Distribution.Types.LibraryName import Distribution.Types.MungedPackageName @@ -1434,6 +1435,7 @@ convertPackageInfoToCacheFormat pkg = GhcPkg.unitDepends = depends pkg, GhcPkg.unitAbiDepends = map (\(AbiDependency k v) -> (k,ST.pack $ unAbiHash v)) (abiDepends pkg), GhcPkg.unitAbiHash = ST.pack $ unAbiHash (abiHash pkg), + GhcPkg.unitFlags = map (ST.pack . showFlagValue) . unFlagAssignment $ Cabal.unitFlags pkg, GhcPkg.unitImportDirs = map ST.pack $ importDirs pkg, GhcPkg.unitLibraries = map ST.pack $ hsLibraries pkg, GhcPkg.unitExtDepLibsSys = map ST.pack $ extraLibraries pkg, @@ -1581,7 +1583,7 @@ listPackages verbosity my_flags mPackageName mModuleName = do | installedUnitId p `elem` broken = printf "{%s}" doc | exposed p = doc | otherwise = printf "(%s)" doc - where doc | verbosity >= Verbose = printf "%s (%s)" pkg (display (installedUnitId p)) + where doc | verbosity >= Verbose = printf "%s (%s) [%s]" pkg (display (installedUnitId p)) (display (Cabal.unitFlags p)) | otherwise = pkg where pkg = display (mungedId p) @@ -1608,7 +1610,7 @@ listPackages verbosity my_flags mPackageName mModuleName = do | installedUnitId p `elem` broken = printf "\ESC[31m%s\ESC[0m" doc -- red color | exposed p = doc | otherwise = printf "\ESC[34m%s\ESC[0m" doc -- blue color - where doc | verbosity >= Verbose = printf "%s (%s)" pkg (display (installedUnitId p)) + where doc | verbosity >= Verbose = printf "%s (%s) [%s]" pkg (display (installedUnitId p)) (display (Cabal.unitFlags p)) | otherwise = pkg where pkg = display (mungedId p) From 99f7910b1f16ffff91ead73d32fa1488558c0ef2 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Thu, 10 Apr 2025 11:24:14 +0900 Subject: [PATCH 77/84] Lookup wired-in RTS based on flags. Instead of the _thr _debug, ... suffix logic, we now use the flags as recorded by cabal to pick the appropriate RTS. --- Makefile | 28 ++++++++++++++++++- compiler/GHC/Unit/State.hs | 37 +++++++++++++++++++++---- rts/rts.cabal | 55 +++++++++++++++++--------------------- 3 files changed, 84 insertions(+), 36 deletions(-) diff --git a/Makefile b/Makefile index 66b8ca680931..2045b2e7367b 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ SHELL := bash MAKEFLAGS += --warn-undefined-variables --no-builtin-rules # Default target -all: stage2 +all: stage2 rts-debug rts-threaded rts-debug-threaded CABAL ?= cabal GHC0 ?= ghc @@ -78,6 +78,32 @@ $(STAGE2_BIN) &: _stage1/bin/ghc _stage1/lib/settings rts/configure libraries/gh log export HADRIAN_SETTINGS="$$(cat ./HADRIAN_SETTINGS)" log $(CABAL_INSTALL) --package-db=$(abspath _stage1/lib/package.conf.d) --build-package-db=$(abspath _stage0/lib/package.conf.d) --project-file cabal.project.stage2 $(addprefix exe:,$(STAGE2_EXE)) +# Build a few extra RTS variants (debug, threaded, debug-threaded) +rts-debug: OUT = $(abspath _stage2) +rts-debug: GHC = $(abspath _stage2/bin/ghc) +rts-debug: _stage2/bin/ghc + @$(LIB) + log $(CABAL_INSTALL) --write-ghc-environment-files=never --package-db=$(abspath _stage1/lib/package.conf.d) --build-package-db=$(abspath _stage0/lib/package.conf.d) --project-file cabal.project.stage2 --lib rts:rts --constraint="rts+debug" + # cabal still writes the environment files even if we pass --write-ghc-environment-files=never + log rm ~/.ghc/*/*/default + +rts-threaded: OUT = $(abspath _stage2) +rts-threaded: GHC = $(abspath _stage2/bin/ghc) +rts-threaded: _stage2/bin/ghc + @$(LIB) + log $(CABAL_INSTALL) --write-ghc-environment-files=never --package-db=$(abspath _stage1/lib/package.conf.d) --build-package-db=$(abspath _stage0/lib/package.conf.d) --project-file cabal.project.stage2 --lib rts:rts --constraint="rts+threaded" + # cabal still writes the environment files even if we pass --write-ghc-environment-files=never + log rm ~/.ghc/*/*/default + + +rts-debug-threaded: OUT = $(abspath _stage2) +rts-debug-threaded: GHC = $(abspath _stage2/bin/ghc) +rts-debug-threaded: _stage2/bin/ghc + @$(LIB) + log $(CABAL_INSTALL) --write-ghc-environment-files=never --package-db=$(abspath _stage1/lib/package.conf.d) --build-package-db=$(abspath _stage0/lib/package.conf.d) --project-file cabal.project.stage2 --lib rts:rts --constraint="rts+debug" --constraint="rts+threaded" + # cabal still writes the environment files even if we pass --write-ghc-environment-files=never + log rm ~/.ghc/*/*/default + stage2: stage1 _stage2/lib/settings $(STAGE2_BIN) # Clean up diff --git a/compiler/GHC/Unit/State.hs b/compiler/GHC/Unit/State.hs index 6f3678b10eca..2ceda9bc70a9 100644 --- a/compiler/GHC/Unit/State.hs +++ b/compiler/GHC/Unit/State.hs @@ -644,7 +644,7 @@ initUnits logger dflags cached_dbs home_units = do (unit_state,dbs) <- withTiming logger (text "initializing unit database") forceUnitInfoMap - $ mkUnitState logger (initUnitConfig dflags cached_dbs home_units) + $ mkUnitState logger dflags (initUnitConfig dflags cached_dbs home_units) putDumpFileMaybe logger Opt_D_dump_mod_map "Module Map" FormatText (updSDocContext (\ctx -> ctx {sdocLineLength = 200}) @@ -1093,6 +1093,7 @@ type WiringMap = UniqMap UnitId UnitId findWiredInUnits :: Logger + -> DynFlags -> UnitPrecedenceMap -> [UnitInfo] -- database -> VisibilityMap -- info on what units are visible @@ -1100,7 +1101,7 @@ findWiredInUnits -> IO ([UnitInfo], -- unit database updated for wired in WiringMap) -- map from unit id to wired identity -findWiredInUnits logger prec_map pkgs vis_map = do +findWiredInUnits logger dflags prec_map pkgs vis_map = do -- Now we must find our wired-in units, and rename them to -- their canonical names (eg. base-1.0 ==> base), as described -- in Note [Wired-in units] in GHC.Unit.Types @@ -1126,11 +1127,36 @@ findWiredInUnits logger prec_map pkgs vis_map = do -- available. -- findWiredInUnit :: [UnitInfo] -> UnitId -> IO (Maybe (UnitId, UnitInfo)) - findWiredInUnit pkgs wired_pkg = firstJustsM [try all_exposed_ps, try all_ps, notfound] + findWiredInUnit pkgs wired_pkg + | wired_pkg == rtsUnitId = firstJustsM [try all_exposed_rts_ps, try all_rts_ps, notfound] + | otherwise = firstJustsM [try all_exposed_ps, try all_ps, notfound] where all_ps = [ p | p <- pkgs, p `matches` wired_pkg ] all_exposed_ps = [ p | p <- all_ps, (mkUnit p) `elemUniqMap` vis_map ] + -- this technically permits to have multiple rts's that match the required ways. + all_rts_ps = [ p | p <- pkgs, p `matches` wired_pkg + -- this is a bit stupid, we need to get + -- -threaded and -debug or + -- +threaded and -debug or + -- +threaded and +debug or + -- -threaded and +debug. + -- And then check if we have an rts instance + -- that matches these flags exactly. + , and [(wayToFlag way) `elem` (map ST.unpack (unitFlags p)) | way <- [WayThreaded, WayDebug]]] + all_exposed_rts_ps = [ p | p <- all_rts_ps, (mkUnit p) `elemUniqMap` vis_map ] + + prefixWay :: Way -> Char + prefixWay way = if (ways dflags) `hasWay` way then '+' else '-' + + wayToFlag :: Way -> String + wayToFlag way = prefixWay way:case way of + WayThreaded -> "threaded" + WayDebug -> "debug" + -- this can't really happen, as we only call this function + -- with Threaded and Debug + _ -> error "findWiredInUnits: unexpected way" + try ps = case sortByPreference prec_map ps of p:_ -> Just <$> pick p _ -> pure Nothing @@ -1464,9 +1490,10 @@ validateDatabase cfg pkg_map1 = mkUnitState :: Logger + -> DynFlags -> UnitConfig -> IO (UnitState,[UnitDatabase UnitId]) -mkUnitState logger cfg = do +mkUnitState logger dflags cfg = do {- Plan. @@ -1621,7 +1648,7 @@ mkUnitState logger cfg = do -- it modifies the unit ids of wired in packages, but when we process -- package arguments we need to key against the old versions. -- - (pkgs2, wired_map) <- findWiredInUnits logger prec_map pkgs1 vis_map2 + (pkgs2, wired_map) <- findWiredInUnits logger dflags prec_map pkgs1 vis_map2 let pkg_db = mkUnitInfoMap pkgs2 -- Update the visibility map, so we treat wired packages as visible. diff --git a/rts/rts.cabal b/rts/rts.cabal index 5981039678fb..a053e8766472 100644 --- a/rts/rts.cabal +++ b/rts/rts.cabal @@ -390,39 +390,34 @@ library stg/Types.h else - -- Here we declare several flavours to be available when passing the - -- suitable (combination of) flag(s) when configuring the RTS from hadrian, - -- using Cabal. - if flag(threaded) - extra-library-flavours: _thr - if flag(dynamic) - extra-dynamic-library-flavours: _thr + cc-options: -DFS_NAMESPACE=rts -DCOMPILING_RTS + cc-options: -Wall -Wextra -Wstrict-prototypes -Wmissing-prototypes + cc-options: -Wmissing-declarations -Winline -Wpointer-arith + cc-options: -Wmissing-noreturn -Wnested-externs -Wredundant-decls + cc-options: -Wundef -fno-strict-aliasing + + -- RTS *must* be compiled with optimisations. The INLINE_HEADER macro + -- requires that functions are inlined to work as expected. Inlining + -- only happens for optimised builds. Otherwise we can assume that + -- there is a non-inlined variant to use instead. But RTS does not + -- provide non-inlined alternatives and hence needs the function to + -- be inlined. See https://github.com/snowleopard/hadrian/issues/90. + if flag(debug) + cc-options: -DDEBUG -fno-omit-frame-pointer -g3 -O0 + if !flag(threaded) + -- TICKY_TICKY is only supported in non-threaded rts + ghc-options: -DTICKY_TICKY -optc-DTICKY_TICKY + else + cc-options: -O2 -fomit-frame-pointer + -- FIXME: PROFILING should is a different ABI, a PROFILING GHC should + -- emit -DPROFILING. if flag(profiling) - extra-library-flavours: _p - if flag(threaded) - extra-library-flavours: _thr_p - if flag(debug) - extra-library-flavours: _debug_p - if flag(threaded) - extra-library-flavours: _thr_debug_p - if flag(dynamic) - extra-dynamic-library-flavours: _p - if flag(threaded) - extra-dynamic-library-flavours: _thr_p - if flag(debug) - extra-dynamic-library-flavours: _debug_p - if flag(threaded) - extra-dynamic-library-flavours: _thr_debug_p + ghc-options: -DPROFILING - if flag(debug) - extra-library-flavours: _debug - if flag(dynamic) - extra-dynamic-library-flavours: _debug - if flag(threaded) - extra-library-flavours: _thr_debug - if flag(dynamic) - extra-dynamic-library-flavours: _thr_debug + if flag(threaded) + cc-options: -DTHREADED_RTS + cpp-options: -DTHREADED_RTS if flag(thread-sanitizer) cc-options: -fsanitize=thread From caacf9a60fa9df5d83cf7ed147b87e44d8678dae Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Thu, 10 Apr 2025 12:04:18 +0900 Subject: [PATCH 78/84] Fix auto-selection of leading_underscore --- cabal.project.stage2 | 3 +-- rts/rts.cabal | 6 +++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cabal.project.stage2 b/cabal.project.stage2 index c83a79a5a17e..d478ac0822ad 100644 --- a/cabal.project.stage2 +++ b/cabal.project.stage2 @@ -83,9 +83,8 @@ package rts-fs ghc-options: -no-ghcversion-header -- FIXME: TNTC should be configurable. --- FIXME: leading-underscore is platform dependent (only mach-o!) package rts - flags: +table-next-to-code +leading-underscore + flags: +table-next-to-code ghc-options: -no-ghcversion-header -- FIXME: Still not sure what in-ghc-tree is. Maybe we should specify/explain diff --git a/rts/rts.cabal b/rts/rts.cabal index a053e8766472..c111d1dbbdef 100644 --- a/rts/rts.cabal +++ b/rts/rts.cabal @@ -287,7 +287,7 @@ flag static-libzstd manual: True flag leading-underscore default: True - manual: True + manual: False flag unregisterised default: False manual: True @@ -352,6 +352,10 @@ library DerivedConstants.h stg/MachRegsForHost.h + if flag(leading-underscore) + if arch(darwin) + buildable: False + if arch(javascript) include-dirs: include From 0f6db64bb64a0f57e35779d0d0ddbd0d7899ad33 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Thu, 10 Apr 2025 12:34:32 +0900 Subject: [PATCH 79/84] Drop suffix logic --- compiler/GHC/Unit/Info.hs | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/compiler/GHC/Unit/Info.hs b/compiler/GHC/Unit/Info.hs index ba653c2b0a50..b224704a5d5d 100644 --- a/compiler/GHC/Unit/Info.hs +++ b/compiler/GHC/Unit/Info.hs @@ -205,14 +205,13 @@ libraryDirsForWay ws | otherwise = map ST.unpack . unitLibraryDirs unitHsLibs :: GhcNameVersion -> Ways -> UnitInfo -> [String] -unitHsLibs namever ways0 p = map (mkDynName . addSuffix . ST.unpack) (unitLibraries p) +unitHsLibs namever ways0 p = map (mkDynName . ST.unpack) (unitLibraries p) where ways1 = removeWay WayDyn ways0 -- the name of a shared library is libHSfoo-ghc.so -- we leave out the _dyn, because it is superfluous tag = waysTag (fullWays ways1) - rts_tag = waysTag ways1 mkDynName x | not (ways0 `hasWay` WayDyn) = x @@ -225,22 +224,3 @@ unitHsLibs namever ways0 p = map (mkDynName . addSuffix . ST.unpack) (unitLibrar | otherwise = panic ("Don't understand library name " ++ x) - -- Add _thr and other rts suffixes to packages named - -- `rts` or `rts-1.0`. Why both? Traditionally the rts - -- package is called `rts` only. However the tooling - -- usually expects a package name to have a version. - -- As such we will gradually move towards the `rts-1.0` - -- package name, at which point the `rts` package name - -- will eventually be unused. - -- - -- This change elevates the need to add custom hooks - -- and handling specifically for the `rts` package. - is_rts x = (x == "HSrts" || "HSrts-" `isPrefixOf` x) - -- ensure we don't consider packages with names like "rts-foo" - && unitPackageName p == PackageName (fsLit "rts") - addSuffix x - | is_rts x = x ++ (expandTag rts_tag) - | otherwise = x ++ (expandTag tag) - - expandTag t | null t = "" - | otherwise = '_':t From fd8fa1fe9e666e85a0fea4d879bbd79577ee032a Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Thu, 10 Apr 2025 12:34:44 +0900 Subject: [PATCH 80/84] threaded by default --- Makefile | 18 +++++++++--------- cabal.project.stage2 | 3 +-- compiler/GHC/Driver/DynFlags.hs | 3 ++- rts/rts.cabal | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 2045b2e7367b..4f3b84888cac 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ SHELL := bash MAKEFLAGS += --warn-undefined-variables --no-builtin-rules # Default target -all: stage2 rts-debug rts-threaded rts-debug-threaded +all: stage2 rts-debug rts-no-threaded rts-debug-no-threaded CABAL ?= cabal GHC0 ?= ghc @@ -87,20 +87,20 @@ rts-debug: _stage2/bin/ghc # cabal still writes the environment files even if we pass --write-ghc-environment-files=never log rm ~/.ghc/*/*/default -rts-threaded: OUT = $(abspath _stage2) -rts-threaded: GHC = $(abspath _stage2/bin/ghc) -rts-threaded: _stage2/bin/ghc +rts-no-threaded: OUT = $(abspath _stage2) +rts-no-threaded: GHC = $(abspath _stage2/bin/ghc) +rts-no-threaded: _stage2/bin/ghc @$(LIB) - log $(CABAL_INSTALL) --write-ghc-environment-files=never --package-db=$(abspath _stage1/lib/package.conf.d) --build-package-db=$(abspath _stage0/lib/package.conf.d) --project-file cabal.project.stage2 --lib rts:rts --constraint="rts+threaded" + log $(CABAL_INSTALL) --write-ghc-environment-files=never --package-db=$(abspath _stage1/lib/package.conf.d) --build-package-db=$(abspath _stage0/lib/package.conf.d) --project-file cabal.project.stage2 --lib rts:rts --constraint="rts-threaded" # cabal still writes the environment files even if we pass --write-ghc-environment-files=never log rm ~/.ghc/*/*/default -rts-debug-threaded: OUT = $(abspath _stage2) -rts-debug-threaded: GHC = $(abspath _stage2/bin/ghc) -rts-debug-threaded: _stage2/bin/ghc +rts-debug-no-threaded: OUT = $(abspath _stage2) +rts-debug-no-threaded: GHC = $(abspath _stage2/bin/ghc) +rts-debug-no-threaded: _stage2/bin/ghc @$(LIB) - log $(CABAL_INSTALL) --write-ghc-environment-files=never --package-db=$(abspath _stage1/lib/package.conf.d) --build-package-db=$(abspath _stage0/lib/package.conf.d) --project-file cabal.project.stage2 --lib rts:rts --constraint="rts+debug" --constraint="rts+threaded" + log $(CABAL_INSTALL) --write-ghc-environment-files=never --package-db=$(abspath _stage1/lib/package.conf.d) --build-package-db=$(abspath _stage0/lib/package.conf.d) --project-file cabal.project.stage2 --lib rts:rts --constraint="rts+debug" --constraint="rts-threaded" # cabal still writes the environment files even if we pass --write-ghc-environment-files=never log rm ~/.ghc/*/*/default diff --git a/cabal.project.stage2 b/cabal.project.stage2 index d478ac0822ad..80eaac852a6c 100644 --- a/cabal.project.stage2 +++ b/cabal.project.stage2 @@ -106,8 +106,7 @@ package ghc-internal flags: +bignum-native package ghc-bin - -- FIXME: we don't have the threaded RTS yet. - flags: -threaded +internal-interpreter + flags: +internal-interpreter package text -- FIXME: avoid having to deal with system-cxx-std-lib fake package for now diff --git a/compiler/GHC/Driver/DynFlags.hs b/compiler/GHC/Driver/DynFlags.hs index ee4ac23b7138..7280db2d8e29 100644 --- a/compiler/GHC/Driver/DynFlags.hs +++ b/compiler/GHC/Driver/DynFlags.hs @@ -636,7 +636,8 @@ defaultDynFlags mySettings = ignorePackageFlags = [], trustFlags = [], packageEnv = Nothing, - targetWays_ = Set.empty, + -- we default to threaded! + targetWays_ = Set.singleton WayThreaded, splitInfo = Nothing, ghcNameVersion = sGhcNameVersion mySettings, diff --git a/rts/rts.cabal b/rts/rts.cabal index c111d1dbbdef..ea4e6243859a 100644 --- a/rts/rts.cabal +++ b/rts/rts.cabal @@ -315,7 +315,7 @@ flag dynamic default: False manual: True flag threaded - default: False + default: True manual: True flag thread-sanitizer description: From 9b01ea11f49ce182cecbba27c02be50fceb2eecf Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Thu, 10 Apr 2025 17:19:40 +0900 Subject: [PATCH 81/84] Make it build --- Makefile | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 4f3b84888cac..e77bf11197b0 100644 --- a/Makefile +++ b/Makefile @@ -79,30 +79,34 @@ $(STAGE2_BIN) &: _stage1/bin/ghc _stage1/lib/settings rts/configure libraries/gh log $(CABAL_INSTALL) --package-db=$(abspath _stage1/lib/package.conf.d) --build-package-db=$(abspath _stage0/lib/package.conf.d) --project-file cabal.project.stage2 $(addprefix exe:,$(STAGE2_EXE)) # Build a few extra RTS variants (debug, threaded, debug-threaded) +# We build these with the stage1 compiler, as we build all other libraries rts-debug: OUT = $(abspath _stage2) -rts-debug: GHC = $(abspath _stage2/bin/ghc) +rts-debug: GHC = $(abspath _stage1/bin/ghc) rts-debug: _stage2/bin/ghc @$(LIB) + log rm -f ~/.ghc/*/*/default log $(CABAL_INSTALL) --write-ghc-environment-files=never --package-db=$(abspath _stage1/lib/package.conf.d) --build-package-db=$(abspath _stage0/lib/package.conf.d) --project-file cabal.project.stage2 --lib rts:rts --constraint="rts+debug" # cabal still writes the environment files even if we pass --write-ghc-environment-files=never - log rm ~/.ghc/*/*/default + log rm -f ~/.ghc/*/*/default rts-no-threaded: OUT = $(abspath _stage2) -rts-no-threaded: GHC = $(abspath _stage2/bin/ghc) +rts-no-threaded: GHC = $(abspath _stage1/bin/ghc) rts-no-threaded: _stage2/bin/ghc @$(LIB) - log $(CABAL_INSTALL) --write-ghc-environment-files=never --package-db=$(abspath _stage1/lib/package.conf.d) --build-package-db=$(abspath _stage0/lib/package.conf.d) --project-file cabal.project.stage2 --lib rts:rts --constraint="rts-threaded" + log rm -f ~/.ghc/*/*/default + log $(CABAL_INSTALL) --write-ghc-environment-files=never --package-db=$(abspath _stage1/lib/package.conf.d) --build-package-db=$(abspath _stage0/lib/package.conf.d) --project-file cabal.project.stage2 --lib rts:rts --constraint='rts -threaded' # cabal still writes the environment files even if we pass --write-ghc-environment-files=never - log rm ~/.ghc/*/*/default + log rm -f ~/.ghc/*/*/default rts-debug-no-threaded: OUT = $(abspath _stage2) -rts-debug-no-threaded: GHC = $(abspath _stage2/bin/ghc) +rts-debug-no-threaded: GHC = $(abspath _stage1/bin/ghc) rts-debug-no-threaded: _stage2/bin/ghc @$(LIB) - log $(CABAL_INSTALL) --write-ghc-environment-files=never --package-db=$(abspath _stage1/lib/package.conf.d) --build-package-db=$(abspath _stage0/lib/package.conf.d) --project-file cabal.project.stage2 --lib rts:rts --constraint="rts+debug" --constraint="rts-threaded" + log rm -f ~/.ghc/*/*/default + log $(CABAL_INSTALL) --write-ghc-environment-files=never --package-db=$(abspath _stage1/lib/package.conf.d) --build-package-db=$(abspath _stage0/lib/package.conf.d) --project-file cabal.project.stage2 --lib rts:rts --constraint='rts +debug -threaded' # cabal still writes the environment files even if we pass --write-ghc-environment-files=never - log rm ~/.ghc/*/*/default + log rm -f ~/.ghc/*/*/default stage2: stage1 _stage2/lib/settings $(STAGE2_BIN) From 3698f68639951afbdb5a931807e21ac817b03187 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Fri, 11 Apr 2025 04:21:24 +0000 Subject: [PATCH 82/84] fixup linux build --- rts-fs/rts-fs.cabal | 4 ++++ rts-headers/include/ghcversion.h | 3 ++- rts/rts.cabal | 8 +++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/rts-fs/rts-fs.cabal b/rts-fs/rts-fs.cabal index f2ebc8aab300..b3106df5ac0b 100644 --- a/rts-fs/rts-fs.cabal +++ b/rts-fs/rts-fs.cabal @@ -13,3 +13,7 @@ library include-dirs: . install-includes: fs.h default-language: Haskell2010 + cc-options: -DFS_NAMESPACE=rts -DCOMPILING_RTS + ghc-options: -DFS_NAMESPACE=rts -DCOMPILING_RTS + cpp-options: -DFS_NAMESPACE=rts -DCOMPILING_RTS + diff --git a/rts-headers/include/ghcversion.h b/rts-headers/include/ghcversion.h index 6ac210f7e35a..544cb219bfcc 100644 --- a/rts-headers/include/ghcversion.h +++ b/rts-headers/include/ghcversion.h @@ -6,4 +6,5 @@ && (pl1) < __GLASGOW_HASKELL_PATCHLEVEL1__ || \ ((ma)*100+(mi)) == __GLASGOW_HASKELL__ \ && (pl1) == __GLASGOW_HASKELL_PATCHLEVEL1__ \ - && (pl2) <= __GLASGOW_HASKELL_PATCHLEVEL2__ ) \ No newline at end of file + && (pl2) <= __GLASGOW_HASKELL_PATCHLEVEL2__ ) + diff --git a/rts/rts.cabal b/rts/rts.cabal index ea4e6243859a..4b82d3bcb3fa 100644 --- a/rts/rts.cabal +++ b/rts/rts.cabal @@ -286,7 +286,7 @@ flag static-libzstd default: False manual: True flag leading-underscore - default: True + default: False manual: False flag unregisterised default: False @@ -352,8 +352,8 @@ library DerivedConstants.h stg/MachRegsForHost.h - if flag(leading-underscore) - if arch(darwin) + if !flag(leading-underscore) + if os(darwin) buildable: False if arch(javascript) @@ -395,6 +395,8 @@ library else cc-options: -DFS_NAMESPACE=rts -DCOMPILING_RTS + ghc-options: -DFS_NAMESPACE=rts -DCOMPILING_RTS + cpp-options: -DFS_NAMESPACE=rts -DCOMPILING_RTS cc-options: -Wall -Wextra -Wstrict-prototypes -Wmissing-prototypes cc-options: -Wmissing-declarations -Winline -Wpointer-arith cc-options: -Wmissing-noreturn -Wnested-externs -Wredundant-decls From 94cb7fc8a6b3e37d698ab2b335bb84a67fc2eb6d Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Fri, 11 Apr 2025 13:22:48 +0900 Subject: [PATCH 83/84] Add configure depednencies --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index e77bf11197b0..36c7bcd5f4e8 100644 --- a/Makefile +++ b/Makefile @@ -42,7 +42,7 @@ TARGET := $(shell cc -dumpmachine) # Stage 1 -- should we pass prefix=stage1- here? And get stage1-ghc, stage1-ghc-pkg, ...? $(STAGE1_BIN) &: OUT ?= $(abspath _stage1) $(STAGE1_BIN) &: override GHC=$(GHC0) -$(STAGE1_BIN) &: +$(STAGE1_BIN) &: libraries/directory/configure libraries/unix/configure libraries/time/configure libraries/process/configure libraries/terminfo/configure @$(LIB) log mkdir -p $(@D) log export HADRIAN_SETTINGS="$$(cat ./HADRIAN_SETTINGS)" From e0642ad49f8f369e6a63a8da8448ae997c344fbc Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Fri, 11 Apr 2025 14:31:52 +0800 Subject: [PATCH 84/84] fixup! Adding HADRIAN_SETTINGS. --- Makefile | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 36c7bcd5f4e8..00b85e5a7b4c 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,32 @@ STAGE1_BIN = $(addprefix _stage1/bin/,$(STAGE1_EXE)) STAGE2_EXE = ghc ghc-pkg STAGE2_BIN = $(addprefix _stage2/bin/,$(STAGE2_EXE)) -TARGET := $(shell cc -dumpmachine) +define GHC_INFO +$(shell $(GHC0) --info | $(GHC0) -e 'getContents >>= foldMap putStrLn . lookup "$1" . read') +endef + +TARGET_PLATFORM := $(call GHC_INFO,target platform string) +TARGET_ARCH := $(call GHC_INFO,target arch) +TARGET_OS := $(call GHC_INFO,target os) +GIT_COMMIT_ID := $(shell git rev-parse HEAD) + +define HADRIAN_SETTINGS +[ ("hostPlatformArch", "$(TARGET_ARCH)") +, ("hostPlatformOS", "$(TARGET_OS)") +, ("cProjectGitCommitId", "$(GIT_COMMIT_ID)") +, ("cProjectVersion", "9.13") +, ("cProjectVersionInt", "913") +, ("cProjectPatchLevel", "0") +, ("cProjectPatchLevel1", "0") +, ("cProjectPatchLevel2", "0") +] +endef + +_stage1/cabal: + $(CABAL0) install --project-dir libraries/Cabal --project-file cabal.release.project --installdir _stage1 cabal-install:exe:cabal + +stage1: STAGE=stage1 +stage1: $(STAGE1_BIN) # Stage 1 -- should we pass prefix=stage1- here? And get stage1-ghc, stage1-ghc-pkg, ...? $(STAGE1_BIN) &: OUT ?= $(abspath _stage1) @@ -45,13 +70,13 @@ $(STAGE1_BIN) &: override GHC=$(GHC0) $(STAGE1_BIN) &: libraries/directory/configure libraries/unix/configure libraries/time/configure libraries/process/configure libraries/terminfo/configure @$(LIB) log mkdir -p $(@D) - log export HADRIAN_SETTINGS="$$(cat ./HADRIAN_SETTINGS)" + log export HADRIAN_SETTINGS='$(HADRIAN_SETTINGS)' log $(CABAL_INSTALL) --project-file cabal.project.stage1 $(addprefix exe:,$(STAGE1_EXE)) %/settings: _stage1/bin/ghc-toolchain-bin @$(LIB) mkdir -p $(@D) - log _stage1/bin/ghc-toolchain-bin --cc=cc --cxx=c++ --install-name-tool=install_name_tool --otool=otool --output-settings -t $(TARGET) -o $@ + log _stage1/bin/ghc-toolchain-bin --cc=cc --cxx=c++ --install-name-tool=install_name_tool --otool=otool --output-settings -t $(TARGET_PLATFORM) -o $@ _stage1/lib/package.conf.d: @$(LIB)