Use Cabal directly in place of ghc-cabal + make build root configurable (#531)
[hadrian.git] / src / Settings / Packages / Rts.hs
1 module Settings.Packages.Rts (
2 rtsContext, rtsBuildPath, rtsConfIn, rtsPackageArgs, rtsLibffiLibrary
3 ) where
4
5 import Base
6 import Expression
7 import GHC.Packages
8 import Oracles.Flag
9 import Oracles.Setting
10 import Settings
11
12 -- | RTS is considered a Stage1 package. This determines RTS build directory.
13 rtsContext :: Context
14 rtsContext = vanillaContext Stage1 rts
15
16 -- | Path to the RTS build directory.
17 rtsBuildPath :: Action FilePath
18 rtsBuildPath = buildPath rtsContext
19
20 -- | Path to RTS package configuration file, to be processed by HsCpp.
21 rtsConfIn :: FilePath
22 rtsConfIn = pkgPath rts -/- "package.conf.in"
23
24 -- These numbers can be found at:
25 -- https://msdn.microsoft.com/en-us/library/windows/desktop/aa383745(v=vs.85).aspx
26 -- If we're compiling on windows, enforce that we only support Vista SP1+
27 -- Adding this here means it doesn't have to be done in individual .c files
28 -- and also centralizes the versioning.
29 -- | Minimum supported Windows version.
30 windowsVersion :: String
31 windowsVersion = "0x06000100"
32
33 libffiLibraryName :: Action FilePath
34 libffiLibraryName = do
35 useSystemFfi <- flag UseSystemFfi
36 windows <- windowsHost
37 return $ case (useSystemFfi, windows) of
38 (True , False) -> "ffi"
39 (False, False) -> "Cffi"
40 (_ , True ) -> "Cffi-6"
41
42 rtsLibffiLibrary :: Way -> Action FilePath
43 rtsLibffiLibrary way = do
44 name <- libffiLibraryName
45 suf <- libsuf way
46 rtsPath <- rtsBuildPath
47 return $ rtsPath -/- "lib" ++ name ++ suf
48
49 -- Compile various performance-critical pieces *without* -fPIC -dynamic
50 -- even when building a shared library. If we don't do this, then the
51 -- GC runs about 50% slower on x86 due to the overheads of PIC. The
52 -- cost of doing this is a little runtime linking and less sharing, but
53 -- not much.
54 --
55 -- On x86_64 this doesn't work, because all objects in a shared library
56 -- must be compiled with -fPIC (since the 32-bit relocations generated
57 -- by the default small memory can't be resolved at runtime). So we
58 -- only do this on i386.
59 --
60 -- This apparently doesn't work on OS X (Darwin) nor on Solaris.
61 -- On Darwin we get errors of the form
62 --
63 -- ld: absolute addressing (perhaps -mdynamic-no-pic) used in _stg_ap_0_fast
64 -- from rts/dist/build/Apply.dyn_o not allowed in slidable image
65 --
66 -- and lots of these warnings:
67 --
68 -- ld: warning codegen in _stg_ap_pppv_fast (offset 0x0000005E) prevents image
69 -- from loading in dyld shared cache
70 --
71 -- On Solaris we get errors like:
72 --
73 -- Text relocation remains referenced
74 -- against symbol offset in file
75 -- .rodata (section) 0x11 rts/dist/build/Apply.dyn_o
76 -- ...
77 -- ld: fatal: relocations remain against allocatable but non-writable sections
78 -- collect2: ld returned 1 exit status
79 speedHack :: Action Bool
80 speedHack = do
81 i386 <- anyTargetArch ["i386"]
82 goodOS <- not <$> anyTargetOs ["darwin", "solaris2"]
83 return $ i386 && goodOS
84
85 rtsPackageArgs :: Args
86 rtsPackageArgs = package rts ? do
87 projectVersion <- getSetting ProjectVersion
88 hostPlatform <- getSetting HostPlatform
89 hostArch <- getSetting HostArch
90 hostOs <- getSetting HostOs
91 hostVendor <- getSetting HostVendor
92 buildPlatform <- getSetting BuildPlatform
93 buildArch <- getSetting BuildArch
94 buildOs <- getSetting BuildOs
95 buildVendor <- getSetting BuildVendor
96 targetPlatform <- getSetting TargetPlatform
97 targetArch <- getSetting TargetArch
98 targetOs <- getSetting TargetOs
99 targetVendor <- getSetting TargetVendor
100 ghcUnreg <- expr $ yesNo <$> flag GhcUnregisterised
101 ghcEnableTNC <- expr $ yesNo <$> ghcEnableTablesNextToCode
102 way <- getWay
103 path <- getBuildPath
104 top <- expr topDirectory
105 libffiName <- expr libffiLibraryName
106 ffiIncludeDir <- getSetting FfiIncludeDir
107 ffiLibraryDir <- getSetting FfiLibDir
108 ghclibDir <- expr installGhcLibDir
109 destDir <- expr getDestDir
110 let cArgs = mconcat
111 [ arg "-Irts"
112 , rtsWarnings
113 , arg $ "-I" ++ path
114 , flag UseSystemFfi ? arg ("-I" ++ ffiIncludeDir)
115 , arg $ "-DRtsWay=\"rts_" ++ show way ++ "\""
116 -- RTS *must* be compiled with optimisations. The INLINE_HEADER macro
117 -- requires that functions are inlined to work as expected. Inlining
118 -- only happens for optimised builds. Otherwise we can assume that
119 -- there is a non-inlined variant to use instead. But RTS does not
120 -- provide non-inlined alternatives and hence needs the function to
121 -- be inlined. See https://github.com/snowleopard/hadrian/issues/90.
122 , arg "-O2"
123
124 , Debug `wayUnit` way ? arg "-DDEBUG"
125 , way `elem` [debug, debugDynamic] ? arg "-DTICKY_TICKY"
126 , Profiling `wayUnit` way ? arg "-DPROFILING"
127 , Threaded `wayUnit` way ? arg "-DTHREADED_RTS"
128
129 , inputs ["//RtsMessages.c", "//Trace.c"] ?
130 arg ("-DProjectVersion=" ++ show projectVersion)
131
132 , input "//RtsUtils.c" ? pure
133 [ "-DProjectVersion=" ++ show projectVersion
134 , "-DHostPlatform=" ++ show hostPlatform
135 , "-DHostArch=" ++ show hostArch
136 , "-DHostOS=" ++ show hostOs
137 , "-DHostVendor=" ++ show hostVendor
138 , "-DBuildPlatform=" ++ show buildPlatform
139 , "-DBuildArch=" ++ show buildArch
140 , "-DBuildOS=" ++ show buildOs
141 , "-DBuildVendor=" ++ show buildVendor
142 , "-DTargetPlatform=" ++ show targetPlatform
143 , "-DTargetArch=" ++ show targetArch
144 , "-DTargetOS=" ++ show targetOs
145 , "-DTargetVendor=" ++ show targetVendor
146 , "-DGhcUnregisterised=" ++ show ghcUnreg
147 , "-DGhcEnableTablesNextToCode=" ++ show ghcEnableTNC ]
148
149 , inputs ["//Evac.c", "//Evac_thr.c"] ? arg "-funroll-loops"
150
151 , speedHack ?
152 inputs [ "//Evac.c", "//Evac_thr.c"
153 , "//Scav.c", "//Scav_thr.c"
154 , "//Compact.c", "//GC.c" ] ? arg "-fno-PIC"
155 -- -static is also necessary for these bits, otherwise the NCG
156 -- generates dynamic references:
157 , speedHack ?
158 inputs [ "//Updates.c", "//StgMiscClosures.c"
159 , "//PrimOps.c", "//Apply.c"
160 , "//AutoApply.c" ] ? pure ["-fno-PIC", "-static"]
161
162 -- inlining warnings happen in Compact
163 , inputs ["//Compact.c"] ? arg "-Wno-inline"
164
165 -- emits warnings about call-clobbered registers on x86_64
166 , inputs [ "//RetainerProfile.c", "//StgCRun.c"
167 , "//win32/ConsoleHandler.c", "//win32/ThrIOManager.c"] ? arg "-w"
168 , inputs ["//RetainerSet.c"] ? arg "-Wno-format"
169 -- The above warning suppression flags are a temporary kludge.
170 -- While working on this module you are encouraged to remove it and fix
171 -- any warnings in the module. See:
172 -- http://ghc.haskell.org/trac/ghc/wiki/WorkingConventions#Warnings
173
174 , (not <$> flag GccIsClang) ?
175 inputs ["//Compact.c"] ? arg "-finline-limit=2500"
176
177 , input "//StgCRun.c" ? windowsHost ? arg "-Wno-return-local-addr"
178 , input "//RetainerProfile.c" ? flag GccIsClang ?
179 arg "-Wno-incompatible-pointer-types"
180 , windowsHost ? arg ("-DWINVER=" ++ windowsVersion)
181
182 -- libffi's ffi.h triggers various warnings
183 , inputs [ "//Interpreter.c", "//Storage.c", "//Adjustor.c" ] ?
184 arg "-Wno-strict-prototypes"
185 , inputs ["//Interpreter.c", "//Adjustor.c", "//sm/Storage.c"] ?
186 anyTargetArch ["powerpc"] ? arg "-Wno-undef" ]
187
188 mconcat
189 [ builder (Cc FindCDependencies) ? cArgs
190 , builder (Ghc CompileCWithGhc) ? map ("-optc" ++) <$> cArgs
191 , builder Ghc ? arg "-Irts"
192
193 , builder HsCpp ? pure
194 [ "-DTOP=" ++ show top
195 , "-DFFI_INCLUDE_DIR=" ++ show ffiIncludeDir
196 , "-DFFI_LIB_DIR=" ++ show ffiLibraryDir
197 , "-DFFI_LIB=" ++ show libffiName ]
198
199 , builder HsCpp ?
200 input "//package.conf.in" ?
201 output "//package.conf.install.raw" ?
202 pure [ "-DINSTALLING"
203 , "-DLIB_DIR=\"" ++ destDir ++ ghclibDir ++ "\""
204 , "-DINCLUDE_DIR=\"" ++ destDir ++ ghclibDir -/- "include\"" ]
205
206 , builder HsCpp ? flag HaveLibMingwEx ? arg "-DHAVE_LIBMINGWEX" ]
207
208 -- See @rts/ghc.mk@.
209 rtsWarnings :: Args
210 rtsWarnings = mconcat
211 [ arg "-Wall"
212 , arg "-Wextra"
213 , arg "-Wstrict-prototypes"
214 , arg "-Wmissing-prototypes"
215 , arg "-Wmissing-declarations"
216 , arg "-Winline"
217 , arg "-Waggregate-return"
218 , arg "-Wpointer-arith"
219 , arg "-Wmissing-noreturn"
220 , arg "-Wnested-externs"
221 , arg "-Wredundant-decls"
222 , arg "-Wundef"
223 , arg "-fno-strict-aliasing" ]