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