b221031100eb0487b9c71ce43012d2821ead72aa
[hadrian.git] / src / Settings / Packages.hs
1 module Settings.Packages (packageArgs) where
2
3 import Expression
4 import Flavour
5 import GHC.Packages
6 import Oracles.Setting
7 import Oracles.Flag
8 import Rules.Gmp
9 import Settings
10
11 -- TODO: Finish migration of package-specific settings into a single file.
12 packageArgs :: Args
13 packageArgs = do
14 intLib <- getIntegerPackage
15 stage <- getStage
16 rtsWays <- getRtsWays
17 path <- getBuildPath
18 compilerBuildPath <- expr $ buildPath (vanillaContext stage compiler)
19 gmpBuildPath <- expr gmpBuildPath
20
21 let includeGmp = "-I" ++ gmpBuildPath -/- "include"
22
23 mconcat
24 --------------------------------- base ---------------------------------
25 [ package base ? mconcat
26 [ builder CabalFlags ? arg ('+' : pkgName intLib)
27
28 -- This fixes the 'unknown symbol stat' issue.
29 -- See: https://github.com/snowleopard/hadrian/issues/259.
30 , builder (Ghc CompileCWithGhc) ? arg "-optc-O2" ]
31
32 ------------------------------ bytestring ------------------------------
33 , package bytestring ?
34 builder CabalFlags ? intLib == integerSimple ? arg "integer-simple"
35
36 --------------------------------- cabal --------------------------------
37 -- Cabal is a large library and slow to compile. Moreover, we build it
38 -- for Stage0 only so we can link ghc-pkg against it, so there is little
39 -- reason to spend the effort to optimise it.
40 , package cabal ?
41 stage0 ? builder Ghc ? arg "-O0"
42
43 ------------------------------- compiler -------------------------------
44 , package compiler ? mconcat
45 [ builder Alex ? arg "--latin1"
46
47 , builder (Ghc CompileHs) ? mconcat
48 [ inputs ["//GHC.hs", "//GhcMake.hs"] ? arg "-fprof-auto"
49 , input "//Parser.hs" ?
50 pure ["-O0", "-fno-ignore-interface-pragmas", "-fcmm-sink" ] ]
51
52 , builder (GhcCabal Conf) ? mconcat
53 [ arg $ "--ghc-option=-DSTAGE=" ++ show (fromEnum stage + 1)
54 , arg "--disable-library-for-ghci"
55 , anyTargetOs ["openbsd"] ? arg "--ld-options=-E"
56 , flag GhcUnregisterised ? arg "--ghc-option=-DNO_REGS"
57 , notM ghcWithSMP ? arg "--ghc-option=-DNOSMP"
58 , notM ghcWithSMP ? arg "--ghc-option=-optc-DNOSMP"
59 , (any (wayUnit Threaded) rtsWays) ?
60 notStage0 ? arg "--ghc-option=-optc-DTHREADED_RTS"
61 , ghcWithInterpreter ?
62 ghcEnableTablesNextToCode ?
63 notM (flag GhcUnregisterised) ?
64 notStage0 ? arg "--ghc-option=-DGHCI_TABLES_NEXT_TO_CODE"
65 , ghcWithInterpreter ?
66 ghciWithDebugger <$> flavour ?
67 notStage0 ? arg "--ghc-option=-DDEBUGGER"
68 , ghcProfiled <$> flavour ?
69 notStage0 ? arg "--ghc-pkg-option=--force" ]
70
71 , builder CabalFlags ? mconcat
72 [ ghcWithNativeCodeGen ? arg "ncg"
73 , ghcWithInterpreter ? notStage0 ? arg "ghci"
74 , flag CrossCompiling ? arg "-terminfo" ]
75
76 , builder (Haddock BuildPackage) ? arg ("--optghc=-I" ++ path) ]
77
78 ---------------------------------- ghc ---------------------------------
79 , package ghc ? mconcat
80 [ builder Ghc ? arg ("-I" ++ compilerBuildPath)
81
82 , builder CabalFlags ? mconcat
83 [ ghcWithInterpreter ? notStage0 ? arg "ghci"
84 , flag CrossCompiling ? arg "-terminfo" ] ]
85
86 -------------------------------- ghcPkg --------------------------------
87 , package ghcPkg ?
88 builder CabalFlags ? flag CrossCompiling ? arg "-terminfo"
89
90 -------------------------------- ghcPrim -------------------------------
91 , package ghcPrim ? mconcat
92 [ builder CabalFlags ? arg "include-ghc-prim"
93
94 , builder (Cc CompileC) ? (not <$> flag GccIsClang) ?
95 input "//cbits/atomic.c" ? arg "-Wno-sync-nand" ]
96
97 --------------------------------- ghci ---------------------------------
98 -- TODO: This should not be @not <$> flag CrossCompiling@. Instead we
99 -- should ensure that the bootstrap compiler has the same version as the
100 -- one we are building.
101
102 -- TODO: In that case we also do not need to build most of the Stage1
103 -- libraries, as we already know that the compiler comes with the most
104 -- recent versions.
105
106 -- TODO: The use case here is that we want to build @ghc-proxy@ for the
107 -- cross compiler. That one needs to be compiled by the bootstrap
108 -- compiler as it needs to run on the host. Hence @libiserv@ needs
109 -- @GHCi.TH@, @GHCi.Message@ and @GHCi.Run@ from @ghci@. And those are
110 -- behind the @-fghci@ flag.
111 , package ghci ? mconcat
112 [ notStage0 ? builder CabalFlags ? arg "ghci"
113 , flag CrossCompiling ? stage0 ? builder CabalFlags ? arg "ghci" ]
114
115 -------------------------------- haddock -------------------------------
116 , package haddock ?
117 builder CabalFlags ? arg "in-ghc-tree"
118
119 ------------------------------- haskeline ------------------------------
120 , package haskeline ?
121 builder CabalFlags ? flag CrossCompiling ? arg "-terminfo"
122
123 -------------------------------- hsc2hs --------------------------------
124 , package hsc2hs ?
125 builder CabalFlags ? arg "in-ghc-tree"
126
127 ------------------------------ integerGmp ------------------------------
128 , package integerGmp ? mconcat
129 [ builder Cc ? arg includeGmp
130
131 , builder (GhcCabal Conf) ? mconcat
132 [ -- TODO: This should respect some settings flag "InTreeGmp".
133 -- Depending on @IncludeDir@ and @LibDir@ is bound to fail, since
134 -- these are only set if the configure script was explicilty
135 -- called with GMP include and lib dirs. Their absense as such
136 -- does not imply @in-tree-gmp@.
137 -- (null gmpIncludeDir && null gmpLibDir) ?
138 -- arg "--configure-option=--with-intree-gmp"
139 arg ("--configure-option=CFLAGS=" ++ includeGmp)
140 , arg ("--gcc-options=" ++ includeGmp) ] ]
141
142 --------------------------------- text ---------------------------------
143 -- The package @text@ is rather tricky. It's a boot library, and it
144 -- tries to determine on its own if it should link against @integer-gmp@
145 -- or @integer-simple@. For Stage0, we need to use the integer library
146 -- that the bootstrap compiler has (since @interger@ is not a boot
147 -- library) and therefore we copy it over into the Stage0 package-db.
148 -- Maybe we should stop doing this? And subsequently @text@ for Stage1
149 -- detects the same integer library again, even though we don't build it
150 -- in Stage1, and at that point the configuration is just wrong.
151 , package text ?
152 builder CabalFlags ? notStage0 ? intLib == integerSimple ?
153 pure [ "+integer-simple", "-bytestring-builder"]
154
155 -------------------------------- runGhc --------------------------------
156 , package runGhc ?
157 builder Ghc ? input "//Main.hs" ?
158 (\version -> ["-cpp", "-DVERSION=" ++ show version]) <$> getSetting ProjectVersion
159
160 ---------------------------------- rts ---------------------------------
161 , package rts ?
162 builder CabalFlags ? (any (wayUnit Profiling) rtsWays) ? arg "profiling" ]