Generic library rules (#571)
[ghc.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 packageArgs :: Args
12 packageArgs = do
13 intLibPkg <- getIntegerPackage
14 integerLibraryName <- pkgName <$> getIntegerPackage
15
16 stage <- getStage
17 rtsWays <- getRtsWays
18 path <- getBuildPath
19
20 compilerBuildPath <- expr $ buildPath (vanillaContext stage compiler)
21
22 gmpBuildPath <- expr gmpBuildPath
23 let includeGmp = "-I" ++ gmpBuildPath -/- "include"
24
25 mconcat
26 [ package base
27 ? mconcat [ builder CabalFlags ? arg ('+':integerLibraryName)
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 , package bytestring
32 ? builder CabalFlags ? intLibPkg == integerSimple ? arg "integer-simple"
33 , package text
34 -- text is rather tricky. It's a boot lib, and it tries to determine on
35 -- it's own if it should link against integer-gmp or integer-simple.
36 -- For stage0, we need to use the integer library that the bootstrap
37 -- compiler has. (the interger-lib is not a boot lib) but as such, we'll
38 -- copy it over into the stage0 package-db (maybe we should stop doing this?)
39 -- And subsequently text for stage1 will detect the same integer lib again,
40 -- even though we don't build it in stage1, and at that point the
41 -- configuration is just wrong.
42 ? builder CabalFlags ? notStage0 ? intLibPkg == integerSimple ? pure [ "+integer-simple"
43 , "-bytestring-builder"]
44 , package cabal
45 -- Cabal is a rather large library and quite slow to compile. Moreover, we
46 -- build it for stage0 only so we can link ghc-pkg against it, so there is
47 -- little reason to spend the effort to optimize it.
48 ? stage0 ? builder Ghc ? arg "-O0"
49 , package compiler
50 ? mconcat [ builder Alex ? arg "--latin1"
51 , builder (Ghc CompileHs) ? mconcat
52 [ inputs ["//GHC.hs", "//GhcMake.hs"] ? arg "-fprof-auto"
53 , input "//Parser.hs" ?
54 pure ["-O0", "-fno-ignore-interface-pragmas", "-fcmm-sink" ] ]
55 , builder (GhcCabal Conf) ? mconcat
56 [ arg $ "--ghc-option=-DSTAGE=" ++ show (fromEnum stage + 1)
57 , arg "--disable-library-for-ghci"
58 , anyTargetOs ["openbsd"] ? arg "--ld-options=-E"
59 , flag GhcUnregisterised ? arg "--ghc-option=-DNO_REGS"
60 , notM ghcWithSMP ? arg "--ghc-option=-DNOSMP"
61 , notM ghcWithSMP ? arg "--ghc-option=-optc-DNOSMP"
62 , (any (wayUnit Threaded) rtsWays) ?
63 notStage0 ? arg "--ghc-option=-optc-DTHREADED_RTS"
64 , ghcWithInterpreter ?
65 ghcEnableTablesNextToCode ?
66 notM (flag GhcUnregisterised) ?
67 notStage0 ? arg "--ghc-option=-DGHCI_TABLES_NEXT_TO_CODE"
68 , ghcWithInterpreter ?
69 ghciWithDebugger <$> flavour ?
70 notStage0 ? arg "--ghc-option=-DDEBUGGER"
71 , ghcProfiled <$> flavour ?
72 notStage0 ? arg "--ghc-pkg-option=--force" ]
73 , builder CabalFlags ? mconcat
74 [ ghcWithNativeCodeGen ? arg "ncg"
75 , ghcWithInterpreter ?
76 notStage0 ? arg "ghci"
77 , crossCompiling ? arg "-terminfo"
78 ]
79 , builder (Haddock BuildPackage) ? arg ("--optghc=-I" ++ path) ]
80 , package ghc
81 ? mconcat [ builder Ghc ? arg ("-I" ++ compilerBuildPath)
82 , builder CabalFlags ? ghcWithInterpreter ? notStage0 ? arg "ghci"
83 , builder CabalFlags ? crossCompiling ? arg "-terminfo" ]
84 , package ghcPkg
85 ? builder CabalFlags ? crossCompiling ? arg "-terminfo"
86 , package ghcPrim
87 ? mconcat [ builder CabalFlags ? arg "include-ghc-prim"
88 , builder (Cc CompileC) ?
89 (not <$> flag GccIsClang) ?
90 input "//cbits/atomic.c" ? arg "-Wno-sync-nand" ]
91 -- XXX: This should not be *not <$> crossCompiling*, but ensure
92 -- that the bootstrap compiler has the same version as the
93 -- one we are building.
94 -- XXX: In that case we also do not need to build most of the
95 -- stage1 libraries, as we already know that the compiler
96 -- comes with the most recent versions.
97 -- XXX: The use case here is that we want to build ghc-proxy for
98 -- the cross compiler. That one needs to be compiled by the
99 -- bootstrap compiler as it needs to run on the host. and as
100 -- such libiserv needs GHCi.TH, GHCi.Message and GHCi.Run from
101 -- ghci. And those are beind the -fghci flag.
102 , package ghci ? notStage0 ? builder CabalFlags ? arg "ghci"
103 , package ghci ? crossCompiling ? stage0 ? builder CabalFlags ? arg "ghci"
104 , package haddock ? builder CabalFlags ? arg "in-ghc-tree"
105 , package haskeline ? builder CabalFlags ? crossCompiling ? arg "-terminfo"
106 , package hsc2hs ? builder CabalFlags ? arg "in-ghc-tree"
107 , package integerGmp
108 ? mconcat [ builder Cc ? arg includeGmp
109 , builder (GhcCabal Conf) ? mconcat
110 [ -- (null gmpIncludeDir && null gmpLibDir) ?
111 -- XXX: this should respect some settings flag "InTreeGmp".
112 -- depending on include and lib dir, is bound to fail
113 -- these are only set if ./configure was explicilty
114 -- called with gmp include and lib dirs. Their absense
115 -- as such does not imply in-tree-gmp
116 -- arg "--configure-option=--with-intree-gmp"
117 arg ("--configure-option=CFLAGS=" ++ includeGmp)
118 , arg ("--gcc-options=" ++ includeGmp) ] ]
119 , package runGhc
120 ? builder Ghc
121 ? input "//Main.hs"
122 ? (\version -> ["-cpp", "-DVERSION=" ++ show version]) <$> getSetting ProjectVersion
123 , package rts
124 ? builder CabalFlags ? (any (wayUnit Profiling) rtsWays) ? arg "profiling"
125 ]