Commit 36fe21aa authored by Herbert Valerio Riedel's avatar Herbert Valerio Riedel 🕺 Committed by Ben Gamari

Enable building Cabal with parsec

Cabal's parser has been rewritten in terms of Parsec (which is not
enabled yet in Cabal-2.0 by default, but can be enabled by a cabal
flag). The plan for Cabal is to drop support for the non-parsec parser,
so we need to prepare GHC to cope with new situation.

However, this means that lib:Cabal requires three new library
dependency submodules,

 - parsec
 - text
 - mtl

What complicates matters is that we need to build `ghc-cabal` early on
during the bootstrap phase which currently needs to invoke `ghc --make`
directly. So these additional dependencies need to be integrated into
the monolithic `ghc --make` invocation which produces the `ghc-cabal`
executable.

Test Plan: `./validate --fast` passed

Reviewers: austin, bgamari

Subscribers: erikd, phadej, rwbarton, thomie

Differential Revision: https://phabricator.haskell.org/D3757
parent c13720c8
......@@ -158,8 +158,8 @@ if test "$WithGhc" = ""
then
AC_MSG_ERROR([GHC is required.])
fi
FP_COMPARE_VERSIONS([$GhcVersion],[-lt],[7.10],
[AC_MSG_ERROR([GHC version 7.10 or later is required to compile GHC.])])
FP_COMPARE_VERSIONS([$GhcVersion],[-lt],[8.0],
[AC_MSG_ERROR([GHC version 8.0 or later is required to compile GHC.])])
if test `expr $GhcMinVersion % 2` = "1"
then
......
......@@ -430,7 +430,7 @@ else # CLEANING
# programs such as GHC and ghc-pkg, that we do not assume the stage0
# compiler already has installed (or up-to-date enough).
PACKAGES_STAGE0 = binary Cabal/Cabal hpc ghc-boot-th ghc-boot transformers template-haskell ghci
PACKAGES_STAGE0 = binary text transformers mtl parsec Cabal/Cabal hpc ghc-boot-th ghc-boot template-haskell ghci
ifeq "$(Windows_Host)" "NO"
PACKAGES_STAGE0 += terminfo
endif
......@@ -457,11 +457,17 @@ PACKAGES_STAGE1 += process
PACKAGES_STAGE1 += hpc
PACKAGES_STAGE1 += pretty
PACKAGES_STAGE1 += binary
PACKAGES_STAGE1 += text
PACKAGES_STAGE1 += transformers
PACKAGES_STAGE1 += mtl
PACKAGES_STAGE1 += parsec
# temporary until Cabal switches to parsec mode by default
libraries/Cabal/Cabal_dist-boot_CONFIGURE_OPTS += --flag parsec
libraries/Cabal/Cabal_dist-install_CONFIGURE_OPTS += --flag parsec
PACKAGES_STAGE1 += Cabal/Cabal
PACKAGES_STAGE1 += ghc-boot-th
PACKAGES_STAGE1 += ghc-boot
PACKAGES_STAGE1 += template-haskell
PACKAGES_STAGE1 += transformers
PACKAGES_STAGE1 += ghc-compact
ifeq "$(HADDOCK_DOCS)" "YES"
......@@ -1264,6 +1270,7 @@ $(eval $(call sdist-ghc-file,compiler,stage2,parser,Parser,y))
$(eval $(call sdist-ghc-file,utils/hpc,dist-install,,HpcParser,y))
$(eval $(call sdist-ghc-file,utils/genprimopcode,dist,,Lexer,x))
$(eval $(call sdist-ghc-file,utils/genprimopcode,dist,,Parser,y))
$(eval $(call sdist-ghc-file2,libraries/Cabal/Cabal,dist-install,Distribution/Parsec,Lexer,x))
.PHONY: sdist-ghc-prep
sdist-ghc-prep : sdist-ghc-prep-tree
......
mtl @ b4725fe2
Subproject commit b4725fe28cba8a535e969e0ddbce3d5e05146ccd
parsec @ d21d8638
Subproject commit d21d86387998614de31697a26fd8fec15d40e62b
text @ 81f9de11
Subproject commit 81f9de11424b79e075d0d22cee23ce9ad90b506b
......@@ -114,6 +114,11 @@ libraries/transformers_dist-install_EXTRA_HC_OPTS += -Wno-unused-matches -Wno-un
libraries/transformers_dist-install_EXTRA_HC_OPTS += -Wno-redundant-constraints
libraries/transformers_dist-install_EXTRA_HC_OPTS += -Wno-orphans
# parsec has various warnings
libraries/parsec_dist-install_EXTRA_HC_OPTS += -Wno-name-shadowing -Wno-unused-matches
libraries/parsec_dist-install_EXTRA_HC_OPTS += -Wno-unused-do-bind -Wno-missing-signatures
libraries/parsec_dist-install_EXTRA_HC_OPTS += -Wno-unused-imports -Wno-type-defaults
# Turn of trustworthy-safe warning
libraries/base_dist-install_EXTRA_HC_OPTS += -Wno-trustworthy-safe
libraries/ghc-prim_dist-install_EXTRA_HC_OPTS += -Wno-trustworthy-safe
......
......@@ -52,9 +52,12 @@ libraries/directory - - ssh://g
libraries/filepath - - ssh://git@github.com/haskell/filepath.git
libraries/haskeline - - https://github.com/judah/haskeline.git
libraries/hpc - - -
libraries/mtl - - https://github.com/ekmett/mtl.git
libraries/parsec - - https://github.com/haskell/parsec.git
libraries/pretty - - https://github.com/haskell/pretty.git
libraries/process - - ssh://git@github.com/haskell/process.git
libraries/terminfo - - https://github.com/judah/terminfo.git
libraries/text - - https://github.com/bos/text.git
libraries/time - - https://github.com/haskell/time.git
libraries/transformers - - https://git.haskell.org/darcs-mirrors/transformers.git
libraries/unix - - ssh://git@github.com/haskell/unix.git
......
......@@ -44,3 +44,34 @@ sdist_$1_$2_$4 : $1/$2/build/$4.hs
# didn't generate all package-data.mk files.
$$(eval $$(call hs-suffix-rules-srcdir,$1,$2,$3))
endef
# -----------------------------------------------------------------------------
# Variant of sdist-ghc-file whose `$3`-argument is interpreted
# differently in a more appropriate way for cabal-packages
define sdist-ghc-file2
# $1 = dir
# $2 = distdir
# $3 = moduledir
# $4 = filename
# $5 = extension
.PHONY: sdist_$1_$2_$4
# We should do this before creating the `sdist-ghc` tarball, or when just
# running `make sdist-ghc-prep`.
sdist-ghc-prep : sdist_$1_$2_$4
# But first create SRC_DIST_GHC_DIR.
sdist_$1_$2_$4 : sdist-ghc-prep-tree
# Generate the .hs files if they don't exist yet, then do actual copying and
# moving.
sdist_$1_$2_$4 : $1/$2/build/$3/$4.hs
"$(CP)" $1/$2/build/$3/$4.hs $(SRC_DIST_GHC_DIR)/$1/$3
mv $(SRC_DIST_GHC_DIR)/$1/$3/$4.$5 $(SRC_DIST_GHC_DIR)/$1/$3/$4.$5.source
# And make sure the rules for generating the .hs files exist, even when we
# didn't generate all package-data.mk files.
$$(eval $$(call hs-suffix-rules-srcdir,$1,$2,$3))
endef
......@@ -27,9 +27,9 @@ CABAL_CONSTRAINT := --constraint="Cabal == $(CABAL_DOTTED_VERSION)"
# `cabal_macros_boot.h` also for GHC >= 8 (in which case it becomes a
# dummy include that doesn't contribute any macro definitions).
ifeq "$(Windows_Host)" "YES"
CABAL_BUILD_DEPS := base array time containers bytestring deepseq process pretty directory Win32
CABAL_BUILD_DEPS := ghc-prim base array transformers time containers bytestring deepseq process pretty directory Win32
else
CABAL_BUILD_DEPS := base array time containers bytestring deepseq process pretty directory unix
CABAL_BUILD_DEPS := ghc-prim base array transformers time containers bytestring deepseq process pretty directory unix
endif
ghc-cabal_DIST_BINARY_NAME = ghc-cabal$(exeext0)
......@@ -40,11 +40,23 @@ ifneq "$(BINDIST)" "YES"
$(ghc-cabal_INPLACE) : $(ghc-cabal_DIST_BINARY) | $$(dir $$@)/.
"$(CP)" $< $@
# Minor hack, since we can't reuse the `hs-suffix-rules-srcdir` macro
ifneq ($(wildcard libraries/Cabal/Cabal/Distribution/Parsec/Lexer.x),)
# Lexer.x exists so we have to call Alex ourselves
CABAL_LEXER_DEP := bootstrapping/Cabal/Distribution/Parsec/Lexer.hs
bootstrapping/Cabal/Distribution/Parsec/Lexer.hs: libraries/Cabal/Cabal/Distribution/Parsec/Lexer.x
mkdir -p bootstrapping/Cabal/Distribution/Parsec
$(call cmd,ALEX) $< -o $@
else
CABAL_LEXER_DEP := libraries/Cabal/Cabal/Distribution/Parsec/Lexer.hs
endif
$(ghc-cabal_DIST_BINARY): $(wildcard libraries/Cabal/Cabal/Distribution/*/*/*.hs)
$(ghc-cabal_DIST_BINARY): $(wildcard libraries/Cabal/Cabal/Distribution/*/*.hs)
$(ghc-cabal_DIST_BINARY): $(wildcard libraries/Cabal/Cabal/Distribution/*.hs)
$(ghc-cabal_DIST_BINARY): utils/ghc-cabal/Main.hs $(TOUCH_DEP) | $$(dir $$@)/. bootstrapping/.
$(ghc-cabal_DIST_BINARY): $(CABAL_LEXER_DEP) utils/ghc-cabal/Main.hs $(TOUCH_DEP) | $$(dir $$@)/. bootstrapping/.
"$(GHC)" $(SRC_HC_OPTS) \
$(addprefix -optc, $(SRC_CC_OPTS) $(CONF_CC_OPTS_STAGE0)) \
$(addprefix -optl, $(SRC_LD_OPTS) $(CONF_GCC_LINKER_OPTS_STAGE0)) \
......@@ -54,14 +66,21 @@ $(ghc-cabal_DIST_BINARY): utils/ghc-cabal/Main.hs $(TOUCH_DEP) | $$(dir $$@)/. b
-no-user-$(GHC_PACKAGE_DB_FLAG) \
-Wall -fno-warn-unused-imports -fno-warn-warnings-deprecations \
-DCABAL_VERSION=$(CABAL_VERSION) \
-DCABAL_PARSEC \
-DBOOTSTRAPPING \
-optP-include -optPutils/ghc-cabal/cabal_macros_boot.h \
-odir bootstrapping \
-hidir bootstrapping \
$(CABAL_LEXER_DEP) \
-ilibraries/Cabal/Cabal \
-ilibraries/binary/src \
-ilibraries/filepath \
-ilibraries/hpc \
-ilibraries/mtl \
-ilibraries/text \
libraries/text/cbits/cbits.c \
-Ilibraries/text/include \
-ilibraries/parsec \
$(utils/ghc-cabal_dist_EXTRA_HC_OPTS) \
$(EXTRA_HC_OPTS)
"$(TOUCH_CMD)" $@
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment