Skip to content

Commit 64db5c6

Browse files
committedFeb 28, 2025·
WIP
1 parent 1b12e5b commit 64db5c6

9 files changed

+91
-141
lines changed
 

‎.github/workflows/ci-cabal-install.yml

+4-7
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,13 @@ jobs:
7676
with:
7777
key: build-${{ matrix.os }}-${{ matrix.ghc }}-${{ github.run_id }}
7878
restore-keys: build-${{ matrix.os }}-${{ matrix.ghc }}-
79-
path: _build _stage0 _stage1
79+
path: _build _stage0 _stage1 _stage1-rts _stage1-boot
8080

8181
- name: Update Hackage index
8282
run: cabal update
8383

84-
- name: Build stage1
85-
run: make stage1
86-
87-
- name: Build stage1-rts
88-
run: make stage1-rts
84+
- name: Build
85+
run: make
8986

9087
- name: Upload artifacts
9188
uses: actions/upload-artifact@v4
@@ -98,7 +95,7 @@ jobs:
9895
if: always()
9996
with:
10097
key: build-${{ matrix.os }}-${{ matrix.ghc }}-${{ github.run_id }}
101-
path: _build _stage0 _stage1
98+
path: _build _stage0 _stage1 _stage1-rts _stage1-boot
10299

103100
- name: Save cabal store
104101
uses: actions/cache/save@v4

‎Makefile

+54-43
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ SHELL := bash
55
MAKEFLAGS += --warn-undefined-variables
66
MAKEFLAGS += --no-builtin-rules
77

8+
all: stage1-boot
9+
810
CABAL0 ?= cabal
911
CABAL ?= _stage0/bin/cabal
10-
GHC ?= ghc
12+
GHC0 ?= ghc
1113

1214
define LIB =
1315
BOLD_RED='\033[1;31m'
@@ -76,56 +78,65 @@ _stage1/lib/settings: _stage1/bin/ghc-toolchain-bin
7678

7779
stage1: _stage1/bin/ghc _stage1/lib/settings
7880

79-
#
80-
# TODO: We cannot build the rts with cabal-install because we are passing
81-
# to deriveConstants the headers in rts-headers via a relative path.
82-
# cabal-install's install command makes a source distribution before building
83-
# and this breaks the relative path. The solution is to move the call to
84-
# derivedConstants into Setup.hs where we have access to the installed
85-
# packagedb. I had a version of this then it looked too complex and I moved back
86-
# to configure.ac.
87-
#
88-
# stage1-rts: CABAL = _stage0/bin/cabal
89-
# stage1-rts: GHC = $(abspath _stage1/bin/ghc)
90-
# stage1-rts: OUT ?= $(abspath _stage1-rts)
91-
# stage1-rts: _stage0/bin/cabal _stage1/bin/ghc _stage1/bin/deriveConstants _stage1/bin/genapply rts/configure
92-
# @$(LIB)
93-
# # for rts/configure
94-
# export DERIVE_CONSTANTS=$(abspath _stage1/bin/deriveConstants)
95-
# export GENAPPLY=$(abspath _stage1/bin/genapply)
96-
# log $(CABAL_INSTALL) --lib --package-env $(OUT) --project-file cabal.project.stage1-rts all
97-
98-
stage1-rts: CABAL = _stage0/bin/cabal
99-
stage1-rts: CABAL_CONFIG_FLAGS += --with-compiler $(abspath _stage1/bin/ghc)
100-
stage1-rts: CABAL_CONFIG_FLAGS += --prefix $(OUT)
101-
stage1-rts: CABAL_CONFIG_FLAGS += --package-db $(OUT)/lib/package.conf.d
102-
stage1-rts: OUT ?= $(abspath _stage1-rts)
103-
stage1-rts: _stage0/bin/cabal-main-simple _stage0/bin/cabal-main-configure _stage1/bin/ghc _stage1/bin/deriveConstants _stage1/bin/genapply rts/configure
81+
_stage1-rts/lib/package.conf.d/rts-fs-1.0.0.0.conf: _stage0/bin/cabal-main-simple
10482
@$(LIB)
105-
mkdir -p $(OUT)/lib/package.conf.d
106-
107-
# for rts/configure
108-
export DERIVE_CONSTANTS=$(abspath _stage1/bin/deriveConstants)
109-
export GENAPPLY=$(abspath _stage1/bin/genapply)
83+
mkdir -p "$(@D)/lib/package.conf.d"
11084

11185
pushd rts-fs || exit
112-
log ../_stage0/bin/cabal-main-simple configure --builddir "$(OUT)/dist/rts-fs" $(CABAL_CONFIG_FLAGS)
86+
log ../_stage0/bin/cabal-main-simple configure --builddir "$(OUT)/dist/rts-fs" $(CABAL_CONFIG_FLAGS) --ipid=$(notdir $(@:%.conf=%))
11387
log ../_stage0/bin/cabal-main-simple build --builddir "$(OUT)/dist/rts-fs"
11488
log ../_stage0/bin/cabal-main-simple install --builddir "$(OUT)/dist/rts-fs"
11589
popd
11690

91+
_stage1-rts/lib/package.conf.d/rts-headers-1.0.0.0.conf: _stage0/bin/cabal-main-simple
92+
@$(LIB)
93+
mkdir -p "$(@D)"
94+
11795
pushd rts-headers || exit
118-
log ../_stage0/bin/cabal-main-simple configure --builddir "$(OUT)/dist/rts-headers" $(CABAL_CONFIG_FLAGS)
96+
log ../_stage0/bin/cabal-main-simple configure --builddir "$(OUT)/dist/rts-headers" $(CABAL_CONFIG_FLAGS) --ipid=$(notdir $(@:%.conf=%))
11997
log ../_stage0/bin/cabal-main-simple build --builddir "$(OUT)/dist/rts-headers"
12098
log ../_stage0/bin/cabal-main-simple install --builddir "$(OUT)/dist/rts-headers"
12199
popd
122100

101+
# NOTE: The bootstrap is particularly annoying in this step.
102+
#
103+
# rts has a custom config so we need a Cabal to compile Setup.hs, but we cannot
104+
# use the new compiler (not even stage1) for this because we do not have the rts
105+
# yet (as we are just preparing to build it).
106+
#
107+
# We cut the know by using the version of Cabal we had built with the stage0 compiler.
108+
# NOTE: the requirement _stage0/bin/cabal is representative of the fact that we had built the library
109+
#
110+
111+
# _stage0/bin/cabal as evidence that we have build cabal
112+
_stage1-rts/dist/rts/Setup: .EXTRA_PREREQS=_stage0/bin/cabal
113+
_stage1-rts/dist/rts/Setup: rts/Setup.hs
114+
@$(LIB)
115+
# FIXME I am using the store as a package db, its path is not quite fixed as it
116+
# relies on the bootstrap compiler id
117+
mkdir -p $(@D)
118+
log $(GHC0) -clear-package-db -global-package-db -package-db _stage0/store/*/package.db -o $@ $<
119+
120+
_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
121+
@$(LIB)
122+
mkdir -p "$(@D)/lib/package.conf.d"
123+
124+
# for rts setup to find derivedConstants and genApply
125+
export PATH=$(abspath _stage1/bin):$$PATH
126+
123127
pushd rts || exit
124-
log ../_stage0/bin/cabal-main-configure configure --builddir "$(OUT)/dist/rts" $(CABAL_CONFIG_FLAGS)
125-
log ../_stage0/bin/cabal-main-configure build --builddir "$(OUT)/dist/rts"
126-
log ../_stage0/bin/cabal-main-configure install --builddir "$(OUT)/dist/rts"
128+
log ../_stage1-rts/dist/rts/Setup configure --builddir "$(OUT)/dist/rts" $(CABAL_CONFIG_FLAGS) --ipid=$(notdir $(@:%.conf=%))
129+
log ../_stage1-rts/dist/rts/Setup build --builddir "$(OUT)/dist/rts"
130+
log ../_stage1-rts/dist/rts/Setup install --builddir "$(OUT)/dist/rts"
127131
popd
128132

133+
stage1-rts: GHC = _stage1/bin/ghc
134+
stage1-rts: CABAL_CONFIG_FLAGS += -v --with-compiler $(abspath _stage1/bin/ghc)
135+
stage1-rts: CABAL_CONFIG_FLAGS += --prefix $(OUT)
136+
stage1-rts: CABAL_CONFIG_FLAGS += --package-db $(OUT)/lib/package.conf.d
137+
stage1-rts: OUT ?= $(abspath _stage1-rts)
138+
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)
139+
129140
_stage1-boot/src/compiler/GHC/Builtin/primops.txt: compiler/GHC/Builtin/primops.txt.pp
130141
@$(LIB)
131142
mkdir -p $(@D)
@@ -147,12 +158,13 @@ _stage1-boot/src/ghc-internal/src/GHC/Internal/PrimopWrappers.hs: _stage1-boot/s
147158
mkdir -p $(@D)
148159
log _stage1/bin/genprimopcode --make-haskell-wrappers < $< > $@
149160

150-
_stage1-boot/src/ghc-internal/.stamp: _stage1-boot/src/ghc-internal/ghc-internal.cabal
151-
_stage1-boot/src/ghc-internal/.stamp: _stage1-boot/src/ghc-internal/src/GHC/Internal/Prim.hs
152-
_stage1-boot/src/ghc-internal/.stamp: _stage1-boot/src/ghc-internal/src/GHC/Internal/PrimopWrappers.hs
161+
_stage1-boot/src/ghc-internal/.ready: _stage1-boot/src/ghc-internal/ghc-internal.cabal
162+
_stage1-boot/src/ghc-internal/.ready: _stage1-boot/src/ghc-internal/src/GHC/Internal/Prim.hs
163+
_stage1-boot/src/ghc-internal/.ready: _stage1-boot/src/ghc-internal/src/GHC/Internal/PrimopWrappers.hs
164+
_stage1-boot/src/ghc-internal/.ready: _stage1-boot/src/ghc-internal/configure
153165

154166
# targets
155-
STAGE1_BOOT_TARGETS = rts ghc-internal ghc-experimental ghc-compact base stm system-cxx-std-lib
167+
STAGE1_BOOT_TARGETS = ghc-internal ghc-experimental ghc-compact base stm system-cxx-std-lib
156168
# shallow compat packages over ghc-internal
157169
STAGE1_BOOT_TARGETS += ghc-prim ghc-bignum integer-gmp template-haskell
158170
# target dependencies
@@ -167,10 +179,9 @@ STAGE1_BOOT_TARGETS += ghc-boot ghc-heap ghc-platform ghc-toolchain ghci ghc
167179
stage1-boot: CABAL = _stage0/bin/cabal
168180
stage1-boot: GHC = $(abspath _stage1/bin/ghc)
169181
stage1-boot: OUT ?= $(abspath _stage1-boot)
170-
stage1-boot: _stage0/bin/cabal _stage1/bin/ghc _stage1-boot/src/ghc-internal/.stamp _stage1-boot/src/ghc-internal/configure
182+
stage1-boot: _stage0/bin/cabal _stage1/bin/ghc _stage1-boot/src/ghc-internal/.ready stage1-rts
171183
@$(LIB)
172184
# for rts/configure
173185
export DERIVE_CONSTANTS=$(abspath _stage1/bin/deriveConstants)
174186
export GENAPPLY=$(abspath _stage1/bin/genapply)
175-
log $(CABAL_INSTALL) --lib --package-env $(OUT) --project-file cabal.project.stage1-boot $(STAGE1_BOOT_TARGETS)
176-
187+
log $(CABAL_INSTALL) --lib --package-db=$(abspath _stage1-rts/lib/package.conf.d) --package-env $(OUT) --project-file cabal.project.stage1-boot Cabal

‎cabal.project.stage1-boot

-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ tests: False
77
packages:
88
./compiler
99
./ghc
10-
./rts
11-
./rts-headers
12-
./rts-fs
1310
./libraries/array
1411
./libraries/base
1512
./libraries/binary

‎cabal.project.stage1-rts

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
allow-boot-library-installs: True
2+
-- active-repositories: :none
3+
4+
benchmarks: False
5+
tests: False
6+
17
packages:
28
rts
39
rts-fs

‎hie.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ cradle:
1212
cradle:
1313
direct:
1414
arguments: []
15+
- path: ./rts/Setup.hs
16+
config:
17+
cradle:
18+
direct:
19+
arguments:
20+
- -clear-package-db
21+
- -global-package-db
22+
- -package-db _stage0/store/ghc-9.8.4-6626/package.db
23+
# - -package base
24+
# - -package Cabal
25+
# - -package Cabal-syntax
26+
# - -package mtl
27+
# - -package transformers
1528
- path: .
1629
config:
1730
cradle: {bios: {program: "./hadrian/hie-bios"}}

‎rts/Setup.hs

+13-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import Distribution.Types.BuildInfo as BI
1010
import Distribution.Types.InstalledPackageInfo as IPI
1111
import Distribution.Types.Library
1212
import Distribution.Types.PackageDescription
13+
import Distribution.Utils.Path (interpretSymbolicPathCWD, (</>), makeRelativePathEx)
1314
import Distribution.Verbosity (normal)
15+
import System.Directory (getCurrentDirectory)
16+
import System.Info (os)
1417

1518
nmProgram :: Program
1619
nmProgram = simpleProgram "nm"
@@ -27,9 +30,10 @@ main =
2730
autoconfUserHooks
2831
{ postConf = \args flags pd lbi -> do
2932
postConf autoconfUserHooks args flags pd lbi
30-
33+
3134
let verbosity = fromFlagOrDefault normal (configVerbosity flags)
32-
let progdb = withPrograms lbi
35+
progdb = withPrograms lbi
36+
3337
(nm, _progdb) <- requireProgram verbosity nmProgram progdb
3438
(objdump, _progdb) <- requireProgram verbosity objdumpProgram progdb
3539
(gcc, _progdb) <- requireProgram verbosity gccProgram progdb
@@ -48,22 +52,24 @@ main =
4852
, incdir <- IPI.includeDirs ipi
4953
]
5054

51-
55+
getCurrentDirectory >>= putStrLn
5256
runProgram verbosity deriveConstants $
5357
[ "--gen-header"
5458
, "-o"
55-
, "include/DerivedConstants.h"
59+
, interpretSymbolicPathCWD (buildDir lbi </> makeRelativePathEx "include/DerivedConstants.h")
5660
, "--target-os"
57-
, "linux"
61+
, os
5862
, "--gcc-program"
5963
, programPath gcc
6064
, "--nm-program"
6165
, programPath nm
6266
, "--objdump-program"
6367
, programPath objdump
6468
, "--tmpdir"
65-
, buildDir lbi
69+
, interpretSymbolicPathCWD (buildDir lbi)
70+
, "--gcc-flag"
71+
, "-I" ++ interpretSymbolicPathCWD (buildDir lbi </> makeRelativePathEx "include")
6672
]
67-
++ foldMap (\i -> ["--gcc-flag", "-I" ++ i]) thisIncDirs
73+
++ foldMap ((\i -> ["--gcc-flag", "-I" ++ i]) . interpretSymbolicPathCWD) thisIncDirs
6874
++ foldMap (\incdir -> ["--gcc-flag", "-I" ++ incdir]) depsIncDirs
6975
}

‎rts/configure.ac

-62
Original file line numberDiff line numberDiff line change
@@ -511,68 +511,6 @@ fi
511511

512512
rm -rf "$TEMP_FILE"
513513

514-
dnl --------------------------------------------------------------
515-
dnl Generate derived constants
516-
dnl --------------------------------------------------------------
517-
518-
AC_ARG_VAR([NM], [Path to the nm program])
519-
AC_PATH_PROG([NM], nm)
520-
if test -z "$NM"; then
521-
AC_MSG_ERROR([Cannot find nm])
522-
fi
523-
524-
AC_ARG_VAR([OBJDUMP], [Path to the objdump program])
525-
AC_PATH_PROG([OBJDUMP], objdump)
526-
if test -z "$OBJDUMP"; then
527-
AC_MSG_ERROR([Cannot find objdump])
528-
fi
529-
530-
AC_ARG_VAR([DERIVE_CONSTANTS], [Path to the deriveConstants program])
531-
AC_PATH_PROG([DERIVE_CONSTANTS], deriveConstants)
532-
if test -z "$DERIVE_CONSTANTS"; then
533-
AC_MSG_ERROR([Cannot find deriveConstants])
534-
fi
535-
536-
AC_CONFIG_COMMANDS([DerivedConstants.h],[
537-
dnl NOTE: dnl pass `-fcommon` to force symbols into the common section. If they end
538-
dnl up in the ro data section `nm` won't list their size, and thus derivedConstants
539-
dnl will fail. Recent clang (e.g. 16) will by default use `-fno-common`.
540-
dnl
541-
dnl FIXME: using a relative path here is TERRIBLE
542-
dnl
543-
$DERIVE_CONSTANTS \
544-
--gen-header \
545-
-o include/DerivedConstants.h \
546-
--target-os "$BuildOS_CPP" \
547-
--gcc-program "$CC" \
548-
--nm-program "$NM" \
549-
--objdump-program "$OBJDUMP" \
550-
--tmpdir "$PWD" \
551-
--gcc-flag "-Iinclude" \
552-
--gcc-flag "-I$srcdir" \
553-
--gcc-flag "-I$srcdir/include" \
554-
--gcc-flag "-I$srcdir/../rts-headers/include"
555-
],[
556-
BuildOS_CPP=$BuildOS_CPP
557-
CC=$CC
558-
DERIVE_CONSTANTS=$DERIVE_CONSTANTS
559-
NM=$NM
560-
OBJDUMP=$OBJDUMP
561-
])
562-
563-
AC_ARG_VAR([GENAPPLY], [Path to the genapply program])
564-
AC_PATH_PROG([GENAPPLY], genapply)
565-
if test -z "$GENAPPLY"; then
566-
AC_MSG_ERROR([Cannot find genapply])
567-
fi
568-
569-
AC_CONFIG_COMMANDS([AutoApply.h],[
570-
$GENAPPLY include/DerivedConstants.h > AutoApply.cmm
571-
$GENAPPLY include/DerivedConstants.h -V16 > AutoApply_V16.cmm
572-
$GENAPPLY include/DerivedConstants.h -V32 > AutoApply_V32.cmm
573-
$GENAPPLY include/DerivedConstants.h -V64 > AutoApply_V64.cmm
574-
],[GENAPPLY=$GENAPPLY])
575-
576514
dnl --------------------------------------------------------------
577515
dnl ** Write config files
578516
dnl --------------------------------------------------------------

‎rts/include/ghcautoconf.h.in

-18
Original file line numberDiff line numberDiff line change
@@ -444,24 +444,6 @@
444444
/* Define to 1 if we need -latomic for sub-word atomic operations. */
445445
#undef NEED_ATOMIC_LIB
446446

447-
/* Define to the address where bug reports for this package should be sent. */
448-
#undef PACKAGE_BUGREPORT
449-
450-
/* Define to the full name of this package. */
451-
#undef PACKAGE_NAME
452-
453-
/* Define to the full name and version of this package. */
454-
#undef PACKAGE_STRING
455-
456-
/* Define to the one symbol short name of this package. */
457-
#undef PACKAGE_TARNAME
458-
459-
/* Define to the home page for this package. */
460-
#undef PACKAGE_URL
461-
462-
/* Define to the version of this package. */
463-
#undef PACKAGE_VERSION
464-
465447
/* Version of GHC used to build this RTS */
466448
#undef ProjectVersion
467449

‎rts/rts.cabal

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ library
348348
ghcautoconf.h
349349
ghcplatform.h
350350
DerivedConstants.h
351+
stg/MachRegsForHost.h
351352

352353
if arch(javascript)
353354

@@ -384,7 +385,6 @@ library
384385

385386
install-includes: HsFFI.h MachDeps.h Rts.h RtsAPI.h Stg.h
386387
ghcconfig.h ghcplatform.h
387-
stg/MachRegsForHost.h
388388
stg/Types.h
389389

390390
else

0 commit comments

Comments
 (0)
Please sign in to comment.