diff options
author | Andrey Mokhov <andrey.mokhov@gmail.com> | 2017-11-06 22:59:37 +0000 |
---|---|---|
committer | Andrey Mokhov <andrey.mokhov@gmail.com> | 2017-11-06 22:59:37 +0000 |
commit | 7b0b9f603bb1215e2b7af23c2404d637b95a4988 (patch) | |
tree | ca118c1b14bc4429e827e0caf925dbc3ab77d1cd /src/Settings/Packages | |
download | haskell-7b0b9f603bb1215e2b7af23c2404d637b95a4988.tar.gz |
Squashed 'hadrian/' content from commit 438dc57
git-subtree-dir: hadrian
git-subtree-split: 438dc576e7b84c473a09d1d7ec7798a30303bc4e
Diffstat (limited to 'src/Settings/Packages')
-rw-r--r-- | src/Settings/Packages/Base.hs | 12 | ||||
-rw-r--r-- | src/Settings/Packages/Cabal.hs | 10 | ||||
-rw-r--r-- | src/Settings/Packages/Compiler.hs | 45 | ||||
-rw-r--r-- | src/Settings/Packages/Ghc.hs | 13 | ||||
-rw-r--r-- | src/Settings/Packages/GhcCabal.hs | 24 | ||||
-rw-r--r-- | src/Settings/Packages/GhcPkg.hs | 7 | ||||
-rw-r--r-- | src/Settings/Packages/GhcPrim.hs | 13 | ||||
-rw-r--r-- | src/Settings/Packages/Ghci.hs | 6 | ||||
-rw-r--r-- | src/Settings/Packages/Haddock.hs | 7 | ||||
-rw-r--r-- | src/Settings/Packages/Haskeline.hs | 8 | ||||
-rw-r--r-- | src/Settings/Packages/IntegerGmp.hs | 24 | ||||
-rw-r--r-- | src/Settings/Packages/Rts.hs | 218 | ||||
-rw-r--r-- | src/Settings/Packages/RunGhc.hs | 9 |
13 files changed, 396 insertions, 0 deletions
diff --git a/src/Settings/Packages/Base.hs b/src/Settings/Packages/Base.hs new file mode 100644 index 0000000000..2e0ced4c26 --- /dev/null +++ b/src/Settings/Packages/Base.hs @@ -0,0 +1,12 @@ +module Settings.Packages.Base (basePackageArgs) where + +import Expression +import Settings + +basePackageArgs :: Args +basePackageArgs = package base ? do + integerLibraryName <- pkgName <$> getIntegerPackage + mconcat [ builder GhcCabal ? arg ("--flags=" ++ integerLibraryName) + -- This fixes the 'unknown symbol stat' issue. + -- See: https://github.com/snowleopard/hadrian/issues/259. + , builder (Ghc CompileCWithGhc) ? arg "-optc-O2" ] diff --git a/src/Settings/Packages/Cabal.hs b/src/Settings/Packages/Cabal.hs new file mode 100644 index 0000000000..c01be4b3ed --- /dev/null +++ b/src/Settings/Packages/Cabal.hs @@ -0,0 +1,10 @@ +module Settings.Packages.Cabal where + +import Expression + +cabalPackageArgs :: Args +cabalPackageArgs = package cabal ? + -- Cabal is a rather large library and quite slow to compile. Moreover, we + -- build it for stage0 only so we can link ghc-pkg against it, so there is + -- little reason to spend the effort to optimize it. + stage0 ? builder Ghc ? arg "-O0" diff --git a/src/Settings/Packages/Compiler.hs b/src/Settings/Packages/Compiler.hs new file mode 100644 index 0000000000..6b329d7b4f --- /dev/null +++ b/src/Settings/Packages/Compiler.hs @@ -0,0 +1,45 @@ +module Settings.Packages.Compiler (compilerPackageArgs) where + +import Base +import Expression +import Flavour +import Oracles.Flag +import Oracles.Setting +import Settings + +compilerPackageArgs :: Args +compilerPackageArgs = package compiler ? do + stage <- getStage + rtsWays <- getRtsWays + path <- getBuildPath + mconcat [ builder Alex ? arg "--latin1" + + , builder (Ghc CompileHs) ? mconcat + [ inputs ["//GHC.hs", "//GhcMake.hs"] ? arg "-fprof-auto" + , input "//Parser.hs" ? + pure ["-O0", "-fno-ignore-interface-pragmas", "-fcmm-sink" ] ] + + , builder GhcCabal ? mconcat + [ arg $ "--ghc-option=-DSTAGE=" ++ show (fromEnum stage + 1) + , arg "--disable-library-for-ghci" + , anyTargetOs ["openbsd"] ? arg "--ld-options=-E" + , flag GhcUnregisterised ? arg "--ghc-option=-DNO_REGS" + , notM ghcWithSMP ? arg "--ghc-option=-DNOSMP" + , notM ghcWithSMP ? arg "--ghc-option=-optc-DNOSMP" + , (threaded `elem` rtsWays) ? + notStage0 ? arg "--ghc-option=-optc-DTHREADED_RTS" + , ghcWithNativeCodeGen ? arg "--flags=ncg" + , ghcWithInterpreter ? + notStage0 ? arg "--flags=ghci" + , crossCompiling ? arg "-f-terminfo" + , ghcWithInterpreter ? + ghcEnableTablesNextToCode ? + notM (flag GhcUnregisterised) ? + notStage0 ? arg "--ghc-option=-DGHCI_TABLES_NEXT_TO_CODE" + , ghcWithInterpreter ? + ghciWithDebugger <$> flavour ? + notStage0 ? arg "--ghc-option=-DDEBUGGER" + , ghcProfiled <$> flavour ? + notStage0 ? arg "--ghc-pkg-option=--force" ] + + , builder (Haddock BuildPackage) ? arg ("--optghc=-I" ++ path) ] diff --git a/src/Settings/Packages/Ghc.hs b/src/Settings/Packages/Ghc.hs new file mode 100644 index 0000000000..d7b1d78ddd --- /dev/null +++ b/src/Settings/Packages/Ghc.hs @@ -0,0 +1,13 @@ +module Settings.Packages.Ghc (ghcPackageArgs) where + +import Expression +import Oracles.Setting +import Oracles.Flag (crossCompiling) + +ghcPackageArgs :: Args +ghcPackageArgs = package ghc ? do + stage <- getStage + path <- expr $ buildPath (vanillaContext stage compiler) + mconcat [ builder Ghc ? arg ("-I" ++ path) + , builder GhcCabal ? ghcWithInterpreter ? notStage0 ? arg "--flags=ghci" + , builder GhcCabal ? crossCompiling ? arg "-f-terminfo" ] diff --git a/src/Settings/Packages/GhcCabal.hs b/src/Settings/Packages/GhcCabal.hs new file mode 100644 index 0000000000..7d2e99e536 --- /dev/null +++ b/src/Settings/Packages/GhcCabal.hs @@ -0,0 +1,24 @@ +module Settings.Packages.GhcCabal (ghcCabalPackageArgs) where + +import Hadrian.Haskell.Cabal + +import Base +import Expression +import Utilities + +ghcCabalPackageArgs :: Args +ghcCabalPackageArgs = stage0 ? package ghcCabal ? builder Ghc ? do + cabalDeps <- expr $ stage1Dependencies cabal + cabalVersion <- expr $ pkgVersion (unsafePkgCabalFile cabal) -- TODO: improve + mconcat + [ pure [ "-package " ++ pkgName pkg | pkg <- cabalDeps, pkg /= parsec ] + , arg "--make" + , arg "-j" + , pure ["-Wall", "-fno-warn-unused-imports", "-fno-warn-warnings-deprecations"] + , arg ("-DCABAL_VERSION=" ++ replace "." "," cabalVersion) + , arg "-DBOOTSTRAPPING" + , arg "-DMIN_VERSION_binary_0_8_0" + , arg "-ilibraries/Cabal/Cabal" + , arg "-ilibraries/binary/src" + , arg "-ilibraries/filepath" + , arg "-ilibraries/hpc" ] diff --git a/src/Settings/Packages/GhcPkg.hs b/src/Settings/Packages/GhcPkg.hs new file mode 100644 index 0000000000..a13a9dab7e --- /dev/null +++ b/src/Settings/Packages/GhcPkg.hs @@ -0,0 +1,7 @@ +module Settings.Packages.GhcPkg (ghcPkgPackageArgs) where + +import Expression +import Oracles.Flag (crossCompiling) + +ghcPkgPackageArgs :: Args +ghcPkgPackageArgs = package ghcPkg ? builder GhcCabal ? crossCompiling ? arg "-f-terminfo" diff --git a/src/Settings/Packages/GhcPrim.hs b/src/Settings/Packages/GhcPrim.hs new file mode 100644 index 0000000000..df1c553d25 --- /dev/null +++ b/src/Settings/Packages/GhcPrim.hs @@ -0,0 +1,13 @@ +module Settings.Packages.GhcPrim (ghcPrimPackageArgs) where + +import Oracles.Flag +import Expression + +ghcPrimPackageArgs :: Args +ghcPrimPackageArgs = package ghcPrim ? mconcat + [ builder GhcCabal ? arg "--flag=include-ghc-prim" + + , builder (Cc CompileC) ? + (not <$> flag GccLt44) ? + (not <$> flag GccIsClang) ? + input "//cbits/atomic.c" ? arg "-Wno-sync-nand" ] diff --git a/src/Settings/Packages/Ghci.hs b/src/Settings/Packages/Ghci.hs new file mode 100644 index 0000000000..47e7d38deb --- /dev/null +++ b/src/Settings/Packages/Ghci.hs @@ -0,0 +1,6 @@ +module Settings.Packages.Ghci (ghciPackageArgs) where + +import Expression + +ghciPackageArgs :: Args +ghciPackageArgs = package ghci ? notStage0 ? builder GhcCabal ? arg "--flags=ghci" diff --git a/src/Settings/Packages/Haddock.hs b/src/Settings/Packages/Haddock.hs new file mode 100644 index 0000000000..c8d667ecb4 --- /dev/null +++ b/src/Settings/Packages/Haddock.hs @@ -0,0 +1,7 @@ +module Settings.Packages.Haddock (haddockPackageArgs) where + +import Expression + +haddockPackageArgs :: Args +haddockPackageArgs = package haddock ? + builder GhcCabal ? pure ["--flag", "in-ghc-tree"] diff --git a/src/Settings/Packages/Haskeline.hs b/src/Settings/Packages/Haskeline.hs new file mode 100644 index 0000000000..254c6b704c --- /dev/null +++ b/src/Settings/Packages/Haskeline.hs @@ -0,0 +1,8 @@ +module Settings.Packages.Haskeline (haskelinePackageArgs) where + +import Expression +import Oracles.Flag (crossCompiling) + +haskelinePackageArgs :: Args +haskelinePackageArgs = + package haskeline ? builder GhcCabal ? crossCompiling ? arg "-f-terminfo" diff --git a/src/Settings/Packages/IntegerGmp.hs b/src/Settings/Packages/IntegerGmp.hs new file mode 100644 index 0000000000..7c2b5f635b --- /dev/null +++ b/src/Settings/Packages/IntegerGmp.hs @@ -0,0 +1,24 @@ +module Settings.Packages.IntegerGmp (integerGmpPackageArgs) where + +import Base +import Expression +import Oracles.Setting +import Rules.Gmp + +-- TODO: Is this needed? +-- ifeq "$(GMP_PREFER_FRAMEWORK)" "YES" +-- libraries/integer-gmp_CONFIGURE_OPTS += --with-gmp-framework-preferred +-- endif +integerGmpPackageArgs :: Args +integerGmpPackageArgs = package integerGmp ? do + path <- expr gmpBuildPath + let includeGmp = "-I" ++ path -/- "include" + gmpIncludeDir <- getSetting GmpIncludeDir + gmpLibDir <- getSetting GmpLibDir + mconcat [ builder Cc ? arg includeGmp + + , builder GhcCabal ? mconcat + [ (null gmpIncludeDir && null gmpLibDir) ? + arg "--configure-option=--with-intree-gmp" + , arg ("--configure-option=CFLAGS=" ++ includeGmp) + , arg ("--gcc-options=" ++ includeGmp) ] ] diff --git a/src/Settings/Packages/Rts.hs b/src/Settings/Packages/Rts.hs new file mode 100644 index 0000000000..33169fe78b --- /dev/null +++ b/src/Settings/Packages/Rts.hs @@ -0,0 +1,218 @@ +module Settings.Packages.Rts ( + rtsContext, rtsBuildPath, rtsConfIn, rtsPackageArgs, rtsLibffiLibrary + ) where + +import Base +import Expression +import Oracles.Flag +import Oracles.Setting +import Settings + +-- | RTS is considered a Stage1 package. This determines RTS build directory. +rtsContext :: Context +rtsContext = vanillaContext Stage1 rts + +-- | Path to the RTS build directory. +rtsBuildPath :: Action FilePath +rtsBuildPath = buildPath rtsContext + +-- | Path to RTS package configuration file, to be processed by HsCpp. +rtsConfIn :: FilePath +rtsConfIn = pkgPath rts -/- "package.conf.in" + +-- These numbers can be found at: +-- https://msdn.microsoft.com/en-us/library/windows/desktop/aa383745(v=vs.85).aspx +-- If we're compiling on windows, enforce that we only support Vista SP1+ +-- Adding this here means it doesn't have to be done in individual .c files +-- and also centralizes the versioning. +-- | Minimum supported Windows version. +windowsVersion :: String +windowsVersion = "0x06000100" + +libffiLibraryName :: Action FilePath +libffiLibraryName = do + useSystemFfi <- flag UseSystemFfi + windows <- windowsHost + return $ case (useSystemFfi, windows) of + (True , False) -> "ffi" + (False, False) -> "Cffi" + (_ , True ) -> "Cffi-6" + +rtsLibffiLibrary :: Way -> Action FilePath +rtsLibffiLibrary way = do + name <- libffiLibraryName + suf <- libsuf way + rtsPath <- rtsBuildPath + return $ rtsPath -/- "lib" ++ name ++ suf + +-- Compile various performance-critical pieces *without* -fPIC -dynamic +-- even when building a shared library. If we don't do this, then the +-- GC runs about 50% slower on x86 due to the overheads of PIC. The +-- cost of doing this is a little runtime linking and less sharing, but +-- not much. +-- +-- On x86_64 this doesn't work, because all objects in a shared library +-- must be compiled with -fPIC (since the 32-bit relocations generated +-- by the default small memory can't be resolved at runtime). So we +-- only do this on i386. +-- +-- This apparently doesn't work on OS X (Darwin) nor on Solaris. +-- On Darwin we get errors of the form +-- +-- ld: absolute addressing (perhaps -mdynamic-no-pic) used in _stg_ap_0_fast from rts/dist/build/Apply.dyn_o not allowed in slidable image +-- +-- and lots of these warnings: +-- +-- ld: warning codegen in _stg_ap_pppv_fast (offset 0x0000005E) prevents image from loading in dyld shared cache +-- +-- On Solaris we get errors like: +-- +-- Text relocation remains referenced +-- against symbol offset in file +-- .rodata (section) 0x11 rts/dist/build/Apply.dyn_o +-- ... +-- ld: fatal: relocations remain against allocatable but non-writable sections +-- collect2: ld returned 1 exit status +speedHack :: Action Bool +speedHack = do + i386 <- anyTargetArch ["i386"] + goodOS <- not <$> anyTargetOs ["darwin", "solaris2"] + return $ i386 && goodOS + +rtsPackageArgs :: Args +rtsPackageArgs = package rts ? do + projectVersion <- getSetting ProjectVersion + hostPlatform <- getSetting HostPlatform + hostArch <- getSetting HostArch + hostOs <- getSetting HostOs + hostVendor <- getSetting HostVendor + buildPlatform <- getSetting BuildPlatform + buildArch <- getSetting BuildArch + buildOs <- getSetting BuildOs + buildVendor <- getSetting BuildVendor + targetPlatform <- getSetting TargetPlatform + targetArch <- getSetting TargetArch + targetOs <- getSetting TargetOs + targetVendor <- getSetting TargetVendor + ghcUnreg <- expr $ yesNo <$> flag GhcUnregisterised + ghcEnableTNC <- expr $ yesNo <$> ghcEnableTablesNextToCode + way <- getWay + path <- getBuildPath + top <- expr topDirectory + libffiName <- expr libffiLibraryName + ffiIncludeDir <- getSetting FfiIncludeDir + ffiLibraryDir <- getSetting FfiLibDir + ghclibDir <- expr installGhcLibDir + destDir <- expr getDestDir + let cArgs = mconcat + [ arg "-Irts" + , rtsWarnings + , arg $ "-I" ++ path + , flag UseSystemFfi ? arg ("-I" ++ ffiIncludeDir) + , arg $ "-DRtsWay=\"rts_" ++ show way ++ "\"" + -- RTS *must* be compiled with optimisations. The INLINE_HEADER macro + -- requires that functions are inlined to work as expected. Inlining + -- only happens for optimised builds. Otherwise we can assume that + -- there is a non-inlined variant to use instead. But RTS does not + -- provide non-inlined alternatives and hence needs the function to + -- be inlined. See https://github.com/snowleopard/hadrian/issues/90. + , arg "-O2" + + , Debug `wayUnit` way ? arg "-DDEBUG" + , way `elem` [debug, debugDynamic] ? arg "-DTICKY_TICKY" + , Profiling `wayUnit` way ? arg "-DPROFILING" + , Threaded `wayUnit` way ? arg "-DTHREADED_RTS" + + , inputs ["//RtsMessages.c", "//Trace.c"] ? + arg ("-DProjectVersion=" ++ show projectVersion) + + , input "//RtsUtils.c" ? pure + [ "-DProjectVersion=" ++ show projectVersion + , "-DHostPlatform=" ++ show hostPlatform + , "-DHostArch=" ++ show hostArch + , "-DHostOS=" ++ show hostOs + , "-DHostVendor=" ++ show hostVendor + , "-DBuildPlatform=" ++ show buildPlatform + , "-DBuildArch=" ++ show buildArch + , "-DBuildOS=" ++ show buildOs + , "-DBuildVendor=" ++ show buildVendor + , "-DTargetPlatform=" ++ show targetPlatform + , "-DTargetArch=" ++ show targetArch + , "-DTargetOS=" ++ show targetOs + , "-DTargetVendor=" ++ show targetVendor + , "-DGhcUnregisterised=" ++ show ghcUnreg + , "-DGhcEnableTablesNextToCode=" ++ show ghcEnableTNC ] + + , inputs ["//Evac.c", "//Evac_thr.c"] ? arg "-funroll-loops" + + , speedHack ? + inputs [ "//Evac.c", "//Evac_thr.c" + , "//Scav.c", "//Scav_thr.c" + , "//Compact.c", "//GC.c" ] ? arg "-fno-PIC" + -- -static is also necessary for these bits, otherwise the NCG + -- generates dynamic references: + , speedHack ? + inputs [ "//Updates.c", "//StgMiscClosures.c" + , "//PrimOps.c", "//Apply.c" + , "//AutoApply.c" ] ? pure ["-fno-PIC", "-static"] + + -- inlining warnings happen in Compact + , inputs ["//Compact.c"] ? arg "-Wno-inline" + + -- emits warnings about call-clobbered registers on x86_64 + , inputs [ "//RetainerProfile.c", "//StgCRun.c" + , "//win32/ConsoleHandler.c", "//win32/ThrIOManager.c"] ? arg "-w" + , inputs ["//RetainerSet.c"] ? arg "-Wno-format" + -- The above warning suppression flags are a temporary kludge. + -- While working on this module you are encouraged to remove it and fix + -- any warnings in the module. See: + -- http://ghc.haskell.org/trac/ghc/wiki/WorkingConventions#Warnings + + , (not <$> flag GccIsClang) ? + inputs ["//Compact.c"] ? arg "-finline-limit=2500" + + , inputs ["//Evac_thr.c", "//Scav_thr.c"] ? + pure ["-DPARALLEL_GC", "-Irts/sm"] + + , input "//StgCRun.c" ? windowsHost ? arg "-Wno-return-local-addr" + , input "//RetainerProfile.c" ? flag GccIsClang ? + arg "-Wno-incompatible-pointer-types" + , inputs [ "//Interpreter.c", "//Storage.c", "//Adjustor.c" ] ? + arg "-Wno-strict-prototypes" + , windowsHost ? arg ("-DWINVER=" ++ windowsVersion) ] + mconcat + [ builder (Cc FindCDependencies) ? cArgs + , builder (Ghc CompileCWithGhc) ? map ("-optc" ++) <$> cArgs + , builder Ghc ? arg "-Irts" + + , builder HsCpp ? pure + [ "-DTOP=" ++ show top + , "-DFFI_INCLUDE_DIR=" ++ show ffiIncludeDir + , "-DFFI_LIB_DIR=" ++ show ffiLibraryDir + , "-DFFI_LIB=" ++ show libffiName ] + + , builder HsCpp ? + input "//package.conf.in" ? + output "//package.conf.install.raw" ? + pure [ "-DINSTALLING" + , "-DLIB_DIR=\"" ++ destDir ++ ghclibDir ++ "\"" + , "-DINCLUDE_DIR=\"" ++ destDir ++ ghclibDir -/- "include\"" ] + + , builder HsCpp ? flag HaveLibMingwEx ? arg "-DHAVE_LIBMINGWEX" ] + +-- See @rts/ghc.mk@. +rtsWarnings :: Args +rtsWarnings = mconcat + [ pure ["-Wall", "-Werror"] + , flag GccLt34 ? arg "-W", not <$> flag GccLt34 ? arg "-Wextra" + , arg "-Wstrict-prototypes" + , arg "-Wmissing-prototypes" + , arg "-Wmissing-declarations" + , arg "-Winline" + , arg "-Waggregate-return" + , arg "-Wpointer-arith" + , arg "-Wmissing-noreturn" + , arg "-Wnested-externs" + , arg "-Wredundant-decls" + , not <$> flag GccLt46 ? arg "-Wundef" + , arg "-fno-strict-aliasing" ] diff --git a/src/Settings/Packages/RunGhc.hs b/src/Settings/Packages/RunGhc.hs new file mode 100644 index 0000000000..03a19c8373 --- /dev/null +++ b/src/Settings/Packages/RunGhc.hs @@ -0,0 +1,9 @@ +module Settings.Packages.RunGhc (runGhcPackageArgs) where + +import Oracles.Setting +import Expression + +runGhcPackageArgs :: Args +runGhcPackageArgs = package runGhc ? builder Ghc ? input "//Main.hs" ? do + version <- getSetting ProjectVersion + pure ["-cpp", "-DVERSION=" ++ show version] |