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