Always enable the external interpreter
[ghc.git] / hadrian / src / Settings / Packages.hs
1 module Settings.Packages (packageArgs) where
2
3 import Expression
4 import Flavour
5 import Oracles.Setting
6 import Oracles.Flag
7 import Packages
8 import Rules.Gmp
9 import Settings
10
11 -- | Package-specific command-line arguments.
12 packageArgs :: Args
13 packageArgs = do
14 stage <- getStage
15 rtsWays <- getRtsWays
16 path <- getBuildPath
17 intLib <- getIntegerPackage
18 compilerPath <- expr $ buildPath (vanillaContext stage compiler)
19 gmpBuildPath <- expr gmpBuildPath
20 let includeGmp = "-I" ++ gmpBuildPath -/- "include"
21 -- Do not bind the result to a Boolean: this forces the configure rule
22 -- immediately and may lead to cyclic dependencies.
23 -- See: https://gitlab.haskell.org/ghc/ghc/issues/16809.
24 cross = flag CrossCompiling
25
26 mconcat
27 --------------------------------- base ---------------------------------
28 [ package base ? mconcat
29 [ builder (Cabal Flags) ? notStage0 ? arg (pkgName intLib)
30
31 -- This fixes the 'unknown symbol stat' issue.
32 -- See: https://github.com/snowleopard/hadrian/issues/259.
33 , builder (Ghc CompileCWithGhc) ? arg "-optc-O2" ]
34
35 ------------------------------ bytestring ------------------------------
36 , package bytestring ?
37 builder (Cabal Flags) ? intLib == integerSimple ? arg "integer-simple"
38
39 --------------------------------- cabal --------------------------------
40 -- Cabal is a large library and slow to compile. Moreover, we build it
41 -- for Stage0 only so we can link ghc-pkg against it, so there is little
42 -- reason to spend the effort to optimise it.
43 , package cabal ?
44 stage0 ? builder Ghc ? arg "-O0"
45
46 ------------------------------- compiler -------------------------------
47 , package compiler ? mconcat
48 [ builder Alex ? arg "--latin1"
49
50 , builder (Ghc CompileHs) ? mconcat
51 [ inputs ["**/GHC.hs", "**/GhcMake.hs"] ? arg "-fprof-auto"
52 , input "**/Parser.hs" ?
53 pure ["-fno-ignore-interface-pragmas", "-fcmm-sink"]
54 -- These files take a very long time to compile with -O1,
55 -- so we use -O0 for them just in Stage0 to speed up the
56 -- build but not affect Stage1+ executables
57 , inputs ["**/HsInstances.hs", "**/DynFlags.hs"] ? stage0 ?
58 pure ["-O0"] ]
59
60 , builder (Cabal Setup) ? mconcat
61 [ arg $ "--ghc-option=-DSTAGE=" ++ show (fromEnum stage + 1)
62 , arg "--disable-library-for-ghci"
63 , anyTargetOs ["openbsd"] ? arg "--ld-options=-E"
64 , flag GhcUnregisterised ? arg "--ghc-option=-DNO_REGS"
65 , notM ghcWithSMP ? arg "--ghc-option=-DNOSMP"
66 , notM ghcWithSMP ? arg "--ghc-option=-optc-DNOSMP"
67 , (any (wayUnit Threaded) rtsWays) ?
68 notStage0 ? arg "--ghc-option=-optc-DTHREADED_RTS"
69 , ghcWithInterpreter ?
70 flag TablesNextToCode ?
71 notM (flag GhcUnregisterised) ?
72 notStage0 ? arg "--ghc-option=-DGHCI_TABLES_NEXT_TO_CODE"
73 , ghcWithInterpreter ?
74 ghciWithDebugger <$> flavour ?
75 notStage0 ? arg "--ghc-option=-DDEBUGGER"
76 , ghcProfiled <$> flavour ?
77 notStage0 ? arg "--ghc-pkg-option=--force" ]
78
79 , builder (Cabal Flags) ? mconcat
80 [ ghcWithNativeCodeGen ? arg "ncg"
81 , ghcWithInterpreter ? notStage0 ? arg "ghci"
82 , cross ? arg "-terminfo"
83 , notStage0 ? intLib == integerGmp ?
84 arg "integer-gmp"
85 , notStage0 ? intLib == integerSimple ?
86 arg "integer-simple" ]
87
88 , builder (Haddock BuildPackage) ? arg ("--optghc=-I" ++ path) ]
89
90 ---------------------------------- ghc ---------------------------------
91 , package ghc ? mconcat
92 [ builder Ghc ? arg ("-I" ++ compilerPath)
93
94 , builder (Cabal Flags) ? mconcat
95 [ ghcWithInterpreter ? notStage0 ? arg "ghci"
96 , cross ? arg "-terminfo"
97 -- the 'threaded' flag is True by default, but
98 -- let's record explicitly that we link all ghc
99 -- executables with the threaded runtime.
100 , arg "threaded" ] ]
101
102 -------------------------------- ghcPkg --------------------------------
103 , package ghcPkg ?
104 builder (Cabal Flags) ? cross ? arg "-terminfo"
105
106 -------------------------------- ghcPrim -------------------------------
107 , package ghcPrim ? mconcat
108 [ builder (Cabal Flags) ? arg "include-ghc-prim"
109
110 , builder (Cc CompileC) ? (not <$> flag GccIsClang) ?
111 input "**/cbits/atomic.c" ? arg "-Wno-sync-nand" ]
112
113 --------------------------------- ghci ---------------------------------
114 -- TODO: This should not be @not <$> flag CrossCompiling@. Instead we
115 -- should ensure that the bootstrap compiler has the same version as the
116 -- one we are building.
117
118 -- TODO: In that case we also do not need to build most of the Stage1
119 -- libraries, as we already know that the compiler comes with the most
120 -- recent versions.
121
122 -- TODO: The use case here is that we want to build @ghc-proxy@ for the
123 -- cross compiler. That one needs to be compiled by the bootstrap
124 -- compiler as it needs to run on the host. Hence @libiserv@ needs
125 -- @GHCi.TH@, @GHCi.Message@ and @GHCi.Run@ from @ghci@. And those are
126 -- behind the @-fghci@ flag.
127 , package ghci ? mconcat
128 [ notStage0 ? builder (Cabal Flags) ? arg "ghci"
129 , cross ? stage0 ? builder (Cabal Flags) ? arg "ghci" ]
130
131 -------------------------------- haddock -------------------------------
132 , package haddock ?
133 builder (Cabal Flags) ? arg "in-ghc-tree"
134
135 ------------------------------- haskeline ------------------------------
136 , package haskeline ?
137 builder (Cabal Flags) ? cross ? arg "-terminfo"
138
139 -------------------------------- hsc2hs --------------------------------
140 , package hsc2hs ?
141 builder (Cabal Flags) ? arg "in-ghc-tree"
142
143 ------------------------------ integerGmp ------------------------------
144 , package integerGmp ? mconcat
145 [ builder Cc ? arg includeGmp
146
147 , builder (Cabal Setup) ? mconcat
148 [ flag GmpInTree ? arg "--configure-option=--with-intree-gmp"
149 -- Windows is always built with inplace GMP until we have dynamic
150 -- linking working.
151 , windowsHost ? arg "--configure-option=--with-intree-gmp"
152 , flag GmpFrameworkPref ?
153 arg "--configure-option=--with-gmp-framework-preferred"
154 , arg ("--configure-option=CFLAGS=" ++ includeGmp)
155 , arg ("--gcc-options=" ++ includeGmp) ] ]
156
157 ---------------------------------- rts ---------------------------------
158 , package rts ? rtsPackageArgs -- RTS deserves a separate function
159
160 -------------------------------- runGhc --------------------------------
161 , package runGhc ?
162 builder Ghc ? input "**/Main.hs" ?
163 (\version -> ["-cpp", "-DVERSION=" ++ show version]) <$> getSetting ProjectVersion
164
165 --------------------------------- text ---------------------------------
166 -- The package @text@ is rather tricky. It's a boot library, and it
167 -- tries to determine on its own if it should link against @integer-gmp@
168 -- or @integer-simple@. For Stage0, we need to use the integer library
169 -- that the bootstrap compiler has (since @interger@ is not a boot
170 -- library) and therefore we copy it over into the Stage0 package-db.
171 -- Maybe we should stop doing this? And subsequently @text@ for Stage1
172 -- detects the same integer library again, even though we don't build it
173 -- in Stage1, and at that point the configuration is just wrong.
174 , package text ?
175 builder (Cabal Flags) ? notStage0 ? intLib == integerSimple ?
176 pure ["+integer-simple", "-bytestring-builder"] ]
177
178 -- | RTS-specific command line arguments.
179 rtsPackageArgs :: Args
180 rtsPackageArgs = package rts ? do
181 projectVersion <- getSetting ProjectVersion
182 hostPlatform <- getSetting HostPlatform
183 hostArch <- getSetting HostArch
184 hostOs <- getSetting HostOs
185 hostVendor <- getSetting HostVendor
186 buildPlatform <- getSetting BuildPlatform
187 buildArch <- getSetting BuildArch
188 buildOs <- getSetting BuildOs
189 buildVendor <- getSetting BuildVendor
190 targetPlatform <- getSetting TargetPlatform
191 targetArch <- getSetting TargetArch
192 targetOs <- getSetting TargetOs
193 targetVendor <- getSetting TargetVendor
194 ghcUnreg <- expr $ yesNo <$> flag GhcUnregisterised
195 ghcEnableTNC <- expr $ yesNo <$> flag TablesNextToCode
196 rtsWays <- getRtsWays
197 way <- getWay
198 path <- getBuildPath
199 top <- expr topDirectory
200 libffiName <- expr libffiLibraryName
201 ffiIncludeDir <- getSetting FfiIncludeDir
202 ffiLibraryDir <- getSetting FfiLibDir
203 let cArgs = mconcat
204 [ arg "-Irts"
205 , rtsWarnings
206 , arg $ "-I" ++ path
207 , flag UseSystemFfi ? arg ("-I" ++ ffiIncludeDir)
208 , arg $ "-DRtsWay=\"rts_" ++ show way ++ "\""
209 -- Set the namespace for the rts fs functions
210 , arg $ "-DFS_NAMESPACE=rts"
211 , arg $ "-DCOMPILING_RTS"
212 -- RTS *must* be compiled with optimisations. The INLINE_HEADER macro
213 -- requires that functions are inlined to work as expected. Inlining
214 -- only happens for optimised builds. Otherwise we can assume that
215 -- there is a non-inlined variant to use instead. But RTS does not
216 -- provide non-inlined alternatives and hence needs the function to
217 -- be inlined. See https://github.com/snowleopard/hadrian/issues/90.
218 , arg "-O2"
219 , arg "-fomit-frame-pointer"
220 , arg "-g"
221
222 , Debug `wayUnit` way ? pure [ "-DDEBUG"
223 , "-fno-omit-frame-pointer"
224 , "-g3"
225 , "-O0" ]
226 , way `elem` [debug, debugDynamic] ? arg "-DTICKY_TICKY"
227 , Profiling `wayUnit` way ? arg "-DPROFILING"
228 , Threaded `wayUnit` way ? arg "-DTHREADED_RTS"
229
230 , inputs ["**/RtsMessages.c", "**/Trace.c"] ?
231 arg ("-DProjectVersion=" ++ show projectVersion)
232
233 , input "**/RtsUtils.c" ? pure
234 [ "-DProjectVersion=" ++ show projectVersion
235 , "-DHostPlatform=" ++ show hostPlatform
236 , "-DHostArch=" ++ show hostArch
237 , "-DHostOS=" ++ show hostOs
238 , "-DHostVendor=" ++ show hostVendor
239 , "-DBuildPlatform=" ++ show buildPlatform
240 , "-DBuildArch=" ++ show buildArch
241 , "-DBuildOS=" ++ show buildOs
242 , "-DBuildVendor=" ++ show buildVendor
243 , "-DTargetPlatform=" ++ show targetPlatform
244 , "-DTargetArch=" ++ show targetArch
245 , "-DTargetOS=" ++ show targetOs
246 , "-DTargetVendor=" ++ show targetVendor
247 , "-DGhcUnregisterised=" ++ show ghcUnreg
248 , "-DTablesNextToCode=" ++ show ghcEnableTNC
249 ]
250
251 -- We're after pur performance here. So make sure fast math and
252 -- vectorization is enabled.
253 , input "**/xxhash.c" ? pure
254 [ "-O3"
255 , "-ffast-math"
256 , "-ftree-vectorize" ]
257
258 , inputs ["**/Evac.c", "**/Evac_thr.c"] ? arg "-funroll-loops"
259
260 , speedHack ?
261 inputs [ "**/Evac.c", "**/Evac_thr.c"
262 , "**/Scav.c", "**/Scav_thr.c"
263 , "**/Compact.c", "**/GC.c" ] ? arg "-fno-PIC"
264 -- @-static@ is necessary for these bits, as otherwise the NCG
265 -- generates dynamic references.
266 , speedHack ?
267 inputs [ "**/Updates.c", "**/StgMiscClosures.c"
268 , "**/PrimOps.c", "**/Apply.c"
269 , "**/AutoApply.c" ] ? pure ["-fno-PIC", "-static"]
270
271 -- inlining warnings happen in Compact
272 , inputs ["**/Compact.c"] ? arg "-Wno-inline"
273
274 -- emits warnings about call-clobbered registers on x86_64
275 , inputs [ "**/StgCRun.c"
276 , "**/win32/ConsoleHandler.c", "**/win32/ThrIOManager.c"] ? arg "-w"
277 -- The above warning suppression flags are a temporary kludge.
278 -- While working on this module you are encouraged to remove it and fix
279 -- any warnings in the module. See:
280 -- https://gitlab.haskell.org/ghc/ghc/wikis/working-conventions#Warnings
281
282 , (not <$> flag GccIsClang) ?
283 inputs ["**/Compact.c"] ? arg "-finline-limit=2500"
284
285 , input "**/RetainerProfile.c" ? flag GccIsClang ?
286 arg "-Wno-incompatible-pointer-types"
287 , windowsHost ? arg ("-DWINVER=" ++ windowsVersion)
288
289 -- libffi's ffi.h triggers various warnings
290 , inputs [ "**/Interpreter.c", "**/Storage.c", "**/Adjustor.c" ] ?
291 arg "-Wno-strict-prototypes"
292 , inputs ["**/Interpreter.c", "**/Adjustor.c", "**/sm/Storage.c"] ?
293 anyTargetArch ["powerpc"] ? arg "-Wno-undef" ]
294
295 mconcat
296 [ builder (Cabal Flags) ? mconcat
297 [ any (wayUnit Profiling) rtsWays ? arg "profiling"
298 , any (wayUnit Debug) rtsWays ? arg "debug"
299 , any (wayUnit Logging) rtsWays ? arg "logging"
300 , any (wayUnit Dynamic) rtsWays ? arg "dynamic"
301 , Debug `wayUnit` way ? arg "find-ptr"
302 ]
303 , builder (Cc FindCDependencies) ? cArgs
304 , builder (Ghc CompileCWithGhc) ? map ("-optc" ++) <$> cArgs
305 , builder Ghc ? arg "-Irts"
306
307 , builder HsCpp ? pure
308 [ "-DTOP=" ++ show top
309 , "-DFFI_INCLUDE_DIR=" ++ show ffiIncludeDir
310 , "-DFFI_LIB_DIR=" ++ show ffiLibraryDir
311 , "-DFFI_LIB=" ++ show libffiName ]
312
313 , builder HsCpp ? flag HaveLibMingwEx ? arg "-DHAVE_LIBMINGWEX" ]
314
315 -- Compile various performance-critical pieces *without* -fPIC -dynamic
316 -- even when building a shared library. If we don't do this, then the
317 -- GC runs about 50% slower on x86 due to the overheads of PIC. The
318 -- cost of doing this is a little runtime linking and less sharing, but
319 -- not much.
320 --
321 -- On x86_64 this doesn't work, because all objects in a shared library
322 -- must be compiled with -fPIC (since the 32-bit relocations generated
323 -- by the default small memory can't be resolved at runtime). So we
324 -- only do this on i386.
325 --
326 -- This apparently doesn't work on OS X (Darwin) nor on Solaris.
327 -- On Darwin we get errors of the form
328 --
329 -- ld: absolute addressing (perhaps -mdynamic-no-pic) used in _stg_ap_0_fast
330 -- from rts/dist/build/Apply.dyn_o not allowed in slidable image
331 --
332 -- and lots of these warnings:
333 --
334 -- ld: warning codegen in _stg_ap_pppv_fast (offset 0x0000005E) prevents image
335 -- from loading in dyld shared cache
336 --
337 -- On Solaris we get errors like:
338 --
339 -- Text relocation remains referenced
340 -- against symbol offset in file
341 -- .rodata (section) 0x11 rts/dist/build/Apply.dyn_o
342 -- ...
343 -- ld: fatal: relocations remain against allocatable but non-writable sections
344 -- collect2: ld returned 1 exit status
345 speedHack :: Action Bool
346 speedHack = do
347 i386 <- anyTargetArch ["i386"]
348 goodOS <- not <$> anyTargetOs ["darwin", "solaris2"]
349 return $ i386 && goodOS
350
351 -- See @rts/ghc.mk@.
352 rtsWarnings :: Args
353 rtsWarnings = mconcat
354 [ arg "-Wall"
355 , arg "-Wextra"
356 , arg "-Wstrict-prototypes"
357 , arg "-Wmissing-prototypes"
358 , arg "-Wmissing-declarations"
359 , arg "-Winline"
360 , arg "-Wpointer-arith"
361 , arg "-Wmissing-noreturn"
362 , arg "-Wnested-externs"
363 , arg "-Wredundant-decls"
364 , arg "-Wundef"
365 , arg "-fno-strict-aliasing" ]
366
367 -- These numbers can be found at:
368 -- https://msdn.microsoft.com/en-us/library/windows/desktop/aa383745(v=vs.85).aspx
369 -- If we're compiling on windows, enforce that we only support Vista SP1+
370 -- Adding this here means it doesn't have to be done in individual .c files
371 -- and also centralizes the versioning.
372 -- | Minimum supported Windows version.
373 windowsVersion :: String
374 windowsVersion = "0x06000100"