Skip to content

Commit 2f3f6ff

Browse files
committed
WIP
1 parent 91b238e commit 2f3f6ff

5 files changed

+203
-20
lines changed

Makefile

+78-16
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,22 @@ endef
2525

2626
CABAL_FLAGS += --store-dir $(OUT)/store --logs-dir $(OUT)/logs
2727

28-
CABAL_INSTALL_FLAGS += --builddir $(OUT)/build
29-
CABAL_INSTALL_FLAGS += --with-compiler $(GHC)
28+
CABAL_BUILD_FLAGS += --builddir $(OUT)/build
29+
CABAL_BUILD_FLAGS += --with-compiler $(GHC)
30+
31+
CABAL_BUILD = $(CABAL) $(CABAL_FLAGS) build $(CABAL_BUILD_FLAGS)
32+
3033
CABAL_INSTALL_FLAGS += --installdir $(OUT)/bin
3134
CABAL_INSTALL_FLAGS += --overwrite-policy=always
3235
# If we copy the executables then ghc will recognise _stage1 as topdir (rather than a path in the store)
3336
CABAL_INSTALL_FLAGS += --install-method=copy
3437

35-
CABAL_INSTALL = $(CABAL) $(CABAL_FLAGS) install $(CABAL_INSTALL_FLAGS)
38+
CABAL_INSTALL = $(CABAL) $(CABAL_FLAGS) install $(CABAL_BUILD_FLAGS) $(CABAL_INSTALL_FLAGS)
3639

3740
cabal: _stage0/bin/cabal
3841

3942
CABAL_EXE = cabal cabal-main-simple cabal-main-configure
40-
CABAL_BIN := $(addprefix _stage0/bin/,$(CABAL_EXE))
43+
CABAL_BIN = $(addprefix _stage0/bin/,$(CABAL_EXE))
4144

4245
$(CABAL_BIN) &: OUT ?= $(abspath _stage0)
4346
$(CABAL_BIN) &: CABAL=$(CABAL0)
@@ -47,7 +50,7 @@ $(CABAL_BIN) &:
4750
log $(CABAL_INSTALL) --project-dir libraries/Cabal --project-file cabal.release.project $(addprefix exe:,$(CABAL_EXE))
4851

4952
STAGE1_EXE = ghc ghc-toolchain-bin deriveConstants genprimopcode genapply
50-
STAGE1_BIN := $(addprefix _stage1/bin/,$(STAGE1_EXE))
53+
STAGE1_BIN = $(addprefix _stage1/bin/,$(STAGE1_EXE))
5154

5255
$(STAGE1_BIN) &: OUT ?= $(abspath _stage1)
5356
$(STAGE1_BIN) &: $(CABAL)
@@ -73,35 +76,94 @@ _stage1/lib/settings: _stage1/bin/ghc-toolchain-bin
7376

7477
stage1: _stage1/bin/ghc _stage1/lib/settings
7578

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+
# export PATH=$(abspath _stage1/bin):$$PATH
94+
# log $(CABAL_INSTALL) --lib --package-env $(OUT) --project-file cabal.project.stage1-rts all
95+
7696
stage1-rts: CABAL = _stage0/bin/cabal
97+
stage1-rts: CABAL_CONFIG_FLAGS += --with-compiler $(abspath _stage1/bin/ghc)
98+
stage1-rts: CABAL_CONFIG_FLAGS += --prefix $(OUT)
99+
stage1-rts: CABAL_CONFIG_FLAGS += --package-db $(OUT)/lib/package.conf.d
77100
stage1-rts: OUT ?= $(abspath _stage1-rts)
78101
stage1-rts: _stage0/bin/cabal-main-simple _stage0/bin/cabal-main-configure _stage1/bin/ghc _stage1/bin/deriveConstants _stage1/bin/genapply rts/configure
79102
@$(LIB)
80-
81-
flags=( \
82-
--with-compiler $(abspath _stage1/bin/ghc) \
83-
--prefix "$(OUT)" \
84-
--package-db "$(OUT)/lib/package.conf.d" \
85-
)
86103
mkdir -p $(OUT)/lib/package.conf.d
87104

88105
pushd rts-fs || exit
89-
log ../_stage0/bin/cabal-main-simple configure --builddir "$(OUT)/dist/rts-fs" "$${flags[@]}"
106+
log ../_stage0/bin/cabal-main-simple configure --builddir "$(OUT)/dist/rts-fs" $(CABAL_CONFIG_FLAGS)
90107
log ../_stage0/bin/cabal-main-simple build --builddir "$(OUT)/dist/rts-fs"
91108
log ../_stage0/bin/cabal-main-simple install --builddir "$(OUT)/dist/rts-fs"
92109
popd
93110

94111
pushd rts-headers || exit
95-
log ../_stage0/bin/cabal-main-simple configure --builddir "$(OUT)/dist/rts-headers" "$${flags[@]}"
112+
log ../_stage0/bin/cabal-main-simple configure --builddir "$(OUT)/dist/rts-headers" $(CABAL_CONFIG_FLAGS)
96113
log ../_stage0/bin/cabal-main-simple build --builddir "$(OUT)/dist/rts-headers"
97114
log ../_stage0/bin/cabal-main-simple install --builddir "$(OUT)/dist/rts-headers"
98115
popd
99116

100117
export DERIVE_CONSTANTS=$(abspath _stage1/bin/deriveConstants)
101118
export GENAPPLY=$(abspath _stage1/bin/genapply)
102119
pushd rts || exit
103-
log ../_stage0/bin/cabal-main-configure configure --builddir "$(OUT)/dist/rts" -v "$${flags[@]}"
104-
log ../_stage0/bin/cabal-main-configure build --builddir "$(OUT)/dist/rts" -v
105-
log ../_stage0/bin/cabal-main-configure install --builddir "$(OUT)/dist/rts" -v
120+
log ../_stage0/bin/cabal-main-configure configure --builddir "$(OUT)/dist/rts" $(CABAL_CONFIG_FLAGS)
121+
log ../_stage0/bin/cabal-main-configure build --builddir "$(OUT)/dist/rts"
122+
log ../_stage0/bin/cabal-main-configure install --builddir "$(OUT)/dist/rts"
106123
popd
107124

125+
_stage1-boot/src/compiler/GHC/Builtin/primops.txt: compiler/GHC/Builtin/primops.txt.pp
126+
@$(LIB)
127+
mkdir -p $(@D)
128+
log cc -E -undef -traditional -P -x c $< >$@
129+
130+
_stage1-boot/src/ghc-internal/ghc-internal.cabal:
131+
@$(LIB)
132+
rm -rf $(@D)
133+
mkdir -p $(@D)
134+
cp -r libraries/ghc-internal/* $(@D)
135+
136+
_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
137+
@$(LIB)
138+
mkdir -p $(@D)
139+
log _stage1/bin/genprimopcode --make-haskell-source < $< > $@
140+
141+
_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
142+
@$(LIB)
143+
mkdir -p $(@D)
144+
log _stage1/bin/genprimopcode --make-haskell-wrappers < $< > $@
145+
146+
_stage1-boot/src/ghc-internal/.stamp: _stage1-boot/src/ghc-internal/ghc-internal.cabal
147+
_stage1-boot/src/ghc-internal/.stamp: _stage1-boot/src/ghc-internal/src/GHC/Internal/Prim.hs
148+
_stage1-boot/src/ghc-internal/.stamp: _stage1-boot/src/ghc-internal/src/GHC/Internal/PrimopWrappers.hs
149+
150+
# targets
151+
STAGE1_BOOT_TARGETS = rts ghc-internal ghc-experimental ghc-compact base stm system-cxx-std-lib
152+
# shallow compat packages over ghc-internal
153+
STAGE1_BOOT_TARGETS += ghc-prim ghc-bignum integer-gmp template-haskell
154+
# target dependencies
155+
STAGE1_BOOT_TARGETS += ghc-boot-th pretty
156+
# other boot libraries used by tests
157+
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
158+
STAGE1_BOOT_TARGETS += unix
159+
# FIXME: we'd have to install Win32 for Windows target. Maybe --libs could install dependencies too..
160+
# ghc related
161+
STAGE1_BOOT_TARGETS += ghc-boot ghc-heap ghc-platform ghc-toolchain ghci ghc
162+
163+
stage1-boot: CABAL = _stage0/bin/cabal
164+
stage1-boot: GHC = $(abspath _stage1/bin/ghc)
165+
stage1-boot: OUT ?= $(abspath _stage1-boot)
166+
stage1-boot: _stage0/bin/cabal _stage1/bin/ghc _stage1-boot/src/ghc-internal/.stamp _stage1-boot/src/ghc-internal/configure
167+
@$(LIB)
168+
log $(CABAL_INSTALL) --lib --package-env $(OUT) --project-file cabal.project.stage1-boot $(STAGE1_BOOT_TARGETS)
169+

cabal.project.stage1

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
-- aka cabal.project-ghc
2-
-- NOTE: this should be in sync with stage1_project in Build.hs until we merge them
3-
-- (except some packages paths)
4-
51
packages:
62
./compiler
73
./ghc

cabal.project.stage1-boot

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
allow-boot-library-installs: True
2+
active-repositories: :none
3+
4+
benchmarks: False
5+
tests: False
6+
7+
packages:
8+
./compiler
9+
./ghc
10+
./rts
11+
./rts-headers
12+
./rts-fs
13+
./libraries/array
14+
./libraries/base
15+
./libraries/binary
16+
./libraries/bytestring
17+
./libraries/Cabal/Cabal
18+
./libraries/Cabal/Cabal-syntax
19+
./libraries/containers/containers
20+
./libraries/deepseq
21+
./libraries/directory
22+
./libraries/exceptions
23+
./libraries/file-io
24+
./libraries/filepath
25+
./libraries/ghc-bignum
26+
./libraries/ghc-boot
27+
./libraries/ghc-boot-th
28+
./libraries/ghc-compact
29+
./libraries/ghc-experimental
30+
./libraries/ghc-heap
31+
./libraries/ghci
32+
-- ./libraries/ghc-internal
33+
_stage1-boot/src/ghc-internal
34+
./libraries/ghc-platform
35+
./libraries/ghc-prim
36+
./libraries/haskeline
37+
./libraries/hpc
38+
./libraries/integer-gmp
39+
./libraries/mtl
40+
./libraries/os-string
41+
./libraries/parsec
42+
./libraries/pretty
43+
./libraries/process
44+
./libraries/semaphore-compat
45+
./libraries/stm
46+
./libraries/system-cxx-std-lib
47+
./libraries/template-haskell
48+
./libraries/terminfo
49+
./libraries/text
50+
./libraries/time
51+
./libraries/transformers
52+
./libraries/unix
53+
./libraries/Win32
54+
./libraries/xhtml
55+
./utils/deriveConstants
56+
./utils/genprimopcode
57+
./utils/ghc-pkg
58+
./utils/ghc-toolchain
59+
./utils/hsc2hs
60+
./utils/unlit
61+
https://hackage.haskell.org/package/alex-3.5.2.0/alex-3.5.2.0.tar.gz
62+
https://hackage.haskell.org/package/happy-2.1.5/happy-2.1.5.tar.gz
63+
https://hackage.haskell.org/package/happy-lib-2.1.5/happy-lib-2.1.5.tar.gz
64+
-- https://hackage.haskell.org/package/os-string-2.0.7/os-string-2.0.7.tar.gz
65+
-- https://hackage.haskell.org/package/process-1.6.25.0/process-1.6.25.0.tar.gz
66+
-- https://hackage.haskell.org/package/time-1.14/time-1.14.tar.gz
67+
-- https://hackage.haskell.org/package/unix-2.8.6.0/unix-2.8.6.0.tar.gz
68+
69+
package hsc2hs
70+
flags: +in-ghc-tree
71+
72+
package ghc
73+
-- build-tool-depends: require genprimopcode, etc. used by Setup.hs
74+
-- internal-interpreter: otherwise our compiler has the internal
75+
-- interpreter but not the boot library we install
76+
-- FIXME: we should really install the lib we used to build stage2
77+
flags: +build-tool-depends +internal-interpreter
78+
79+
package ghci
80+
flags: +internal-interpreter
81+
82+
package ghc-internal
83+
-- FIXME: make our life easier for now by using the native bignum backend
84+
flags: +bignum-native
85+
86+
package text
87+
-- FIXME: avoid having to deal with system-cxx-std-lib fake package for now
88+
flags: -simdutf
89+

cabal.project.stage1-rts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
packages:
2+
rts
3+
rts-fs
4+
rts-headers

cabal.project.stage2

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
packages:
2+
./ghc
3+
-- https://hackage.haskell.org/package/directory-1.3.9.0/directory-1.3.9.0.tar.gz
4+
-- ./libraries/file-io
5+
-- ./libraries/filepath
6+
-- ./libraries/ghc-platform
7+
-- ./libraries/ghc-boot
8+
-- ./libraries/ghc-boot-th
9+
-- ./libraries/ghc-heap
10+
-- ./libraries/ghci
11+
-- https://hackage.haskell.org/package/os-string-2.0.7/os-string-2.0.7.tar.gz
12+
-- https://hackage.haskell.org/package/process-1.6.25.0/process-1.6.25.0.tar.gz
13+
-- ./libraries/semaphore-compat
14+
-- https://hackage.haskell.org/package/time-1.14/time-1.14.tar.gz
15+
-- https://hackage.haskell.org/package/unix-2.8.6.0/unix-2.8.6.0.tar.gz
16+
-- ./libraries/Win32
17+
./utils/ghc-pkg
18+
-- ./utils/hsc2hs
19+
-- ./utils/unlit
20+
-- ./utils/ghc-toolchain
21+
-- ./utils/ghc-toolchain/exe
22+
23+
benchmarks: False
24+
profiling: False
25+
tests: False
26+
27+
package ghc-bin
28+
-- FIXME: we don't support the threaded rts way yet
29+
flags: +internal-interpreter -threaded
30+
31+
package hsc2hs
32+
flags: +in-ghc-tree

0 commit comments

Comments
 (0)