diff options
author | Zubin Duggal <zubin.duggal@gmail.com> | 2021-06-13 16:02:06 +0530 |
---|---|---|
committer | Zubin Duggal <zubin.duggal@gmail.com> | 2021-08-14 02:39:18 +0530 |
commit | 48858f83140767fc3b512f14243354320939ef92 (patch) | |
tree | fae64524a43e5e3bac4ece24fa2d86e09e08a80b | |
parent | 100ffe75f509a73f1b26e768237888646f522b6c (diff) | |
download | haskell-wip/reinstallable.tar.gz |
reinstallable Setup.hswip/reinstallable
fix cabal file
fix cabal file
Move CodeGen.Platform.hs to compiler/
make cabal sdist work
Remove unnecessary GHC_STAGE guards
Remove unnecessary rts dependency
-rw-r--r-- | compiler/Setup.hs | 129 | ||||
-rw-r--r-- | compiler/cabal.project | 1 | ||||
-rw-r--r-- | compiler/ghc.cabal.in | 16 |
3 files changed, 143 insertions, 3 deletions
diff --git a/compiler/Setup.hs b/compiler/Setup.hs new file mode 100644 index 0000000000..d7c5ed2b04 --- /dev/null +++ b/compiler/Setup.hs @@ -0,0 +1,129 @@ +{-# LANGUAGE RecordWildCards #-} +module Main where + +import Distribution.Simple +import Distribution.Simple.BuildPaths +import Distribution.Types.LocalBuildInfo +import Distribution.Verbosity +import Distribution.Simple.Program + +import System.IO +import System.Process +import System.Directory +import System.FilePath +import Control.Monad +import Data.Char +import GHC.ResponseFile + +main :: IO () +main = defaultMainWithHooks ghcHooks + where + ghcHooks = simpleUserHooks + { buildHook = \pd lbi uh bf -> do + ghcAutogen lbi + buildHook simpleUserHooks pd lbi uh bf + } + +-- Mapping from primop-*.hs-incl file to command +primopIncls :: [(String,String)] +primopIncls = + [ ("primop-data-decl.hs-incl" , "--data-decl") + , ("primop-tag.hs-incl" , "--primop-tag") + , ("primop-list.hs-incl" , "--primop-list") + , ("primop-has-side-effects.hs-incl" , "--has-side-effects") + , ("primop-out-of-line.hs-incl" , "--out-of-line") + , ("primop-commutable.hs-incl" , "--commutable") + , ("primop-code-size.hs-incl" , "--code-size") + , ("primop-can-fail.hs-incl" , "--can-fail") + , ("primop-strictness.hs-incl" , "--strictness") + , ("primop-fixity.hs-incl" , "--fixity") + , ("primop-primop-info.hs-incl" , "--primop-primop-info") + , ("primop-vector-uniques.hs-incl" , "--primop-vector-uniques") + , ("primop-vector-tys.hs-incl" , "--primop-vector-tys") + , ("primop-vector-tys-exports.hs-incl", "--primop-vector-tys-exports") + , ("primop-vector-tycons.hs-incl" , "--primop-vector-tycons") + , ("primop-docs.hs-incl" , "--wired-in-docs") + ] + +ghcAutogen :: LocalBuildInfo -> IO () +ghcAutogen lbi@LocalBuildInfo{..} = do + -- Get compiler/ root directory from the cabal file + let Just compilerRoot = takeDirectory <$> pkgDescrFile + + -- Require the necessary programs + (gcc ,withPrograms) <- requireProgram normal gccProgram withPrograms + (ghc ,withPrograms) <- requireProgram normal ghcProgram withPrograms + (ghcPkg,withPrograms) <- requireProgram normal ghcPkgProgram withPrograms + + -- Get compiler settings + settings <- read <$> getProgramOutput normal ghc ["--info"] + rtsInclude <- filter (not . isSpace) + <$> getProgramOutput normal ghcPkg ["--simple-output","--expand-pkgroot","field","rts","include-dirs"] + + -- Write primop-*.hs-incl + let hsCppOpts = case lookup "Haskell CPP flags" settings of + Just fs -> unescapeArgs fs + Nothing -> [] + primopsTxtPP = compilerRoot </> "GHC/Builtin/primops.txt.pp" + cppOpts = hsCppOpts ++ ["-P","-x","c"] + cppIncludes = map ("-I"++) [compilerRoot, rtsInclude] + -- Preprocess primops.txt.pp + primopsStr <- getProgramOutput normal gcc (cppOpts ++ cppIncludes ++ [primopsTxtPP]) + -- Call genprimopcode to generate *.hs-incl + forM_ primopIncls $ \(file,command) -> do + contents <- readProcess "genprimopcode" [command] primopsStr + writeFile (buildDir </> file) contents + + -- Write GHC.Platform.Constants + let platformConstantsPath = autogenPackageModulesDir lbi </> "GHC/Platform/Constants.hs" + targetOS = case lookup "target os" settings of + Nothing -> error "no target os in settings" + Just os -> os + createDirectoryIfMissing True (takeDirectory platformConstantsPath) + callProcess "deriveConstants" ["--gen-haskell-type","-o",platformConstantsPath,"--target-os",targetOS] + + -- Write GHC.Settings.Config + let configHsPath = autogenPackageModulesDir lbi </> "GHC/Settings/Config.hs" + configHs = generateConfigHs settings + createDirectoryIfMissing True (takeDirectory configHsPath) + writeFile configHsPath configHs + + +generateConfigHs :: [(String,String)] -> String +generateConfigHs settings = either error id $ do + let getSetting k = case lookup k settings of + Nothing -> Left (show k ++ " not found in settings") + Just v -> Right v + buildPlatform <- getSetting "Host platform" + hostPlatform <- getSetting "Target platform" + cProjectName <- getSetting "Project name" + cBooterVersion <- getSetting "Project version" + return $ unlines + [ "module GHC.Settings.Config" + , " ( module GHC.Version" + , " , cBuildPlatformString" + , " , cHostPlatformString" + , " , cProjectName" + , " , cBooterVersion" + , " , cStage" + , " ) where" + , "" + , "import GHC.Prelude" + , "" + , "import GHC.Version" + , "" + , "cBuildPlatformString :: String" + , "cBuildPlatformString = " ++ show buildPlatform + , "" + , "cHostPlatformString :: String" + , "cHostPlatformString = " ++ show hostPlatform + , "" + , "cProjectName :: String" + , "cProjectName = " ++ show cProjectName + , "" + , "cBooterVersion :: String" + , "cBooterVersion = " ++ show cBooterVersion + , "" + , "cStage :: String" + , "cStage = show (2 :: Int)" + ] diff --git a/compiler/cabal.project b/compiler/cabal.project new file mode 100644 index 0000000000..076876df68 --- /dev/null +++ b/compiler/cabal.project @@ -0,0 +1 @@ +packages: . ../utils/genprimopcode/ ../utils/deriveConstants/ diff --git a/compiler/ghc.cabal.in b/compiler/ghc.cabal.in index 2520576498..70bc138650 100644 --- a/compiler/ghc.cabal.in +++ b/compiler/ghc.cabal.in @@ -1,9 +1,10 @@ +Cabal-Version: 2.2 -- WARNING: ghc.cabal is automatically generated from ghc.cabal.in by -- ./configure. Make sure you are editing ghc.cabal.in, not ghc.cabal. Name: ghc Version: @ProjectVersionMunged@ -License: BSD3 +License: BSD-3-Clause License-File: LICENSE Author: The GHC Team Maintainer: glasgow-haskell-users@haskell.org @@ -20,10 +21,14 @@ Description: See <https://gitlab.haskell.org/ghc/ghc/-/wikis/commentary/compiler> for more information. Category: Development -Build-Type: Simple -Cabal-Version: >=1.10 +Build-Type: Custom + +custom-setup + setup-depends: base >= 3 && < 5, Cabal >= 1.6 && <3.6, directory, process, filepath extra-source-files: + GHC/Builtin/primops.txt.pp + GHC/Builtin/bytearray-ops.txt.pp Unique.h CodeGen.Platform.h -- Shared with rts via hard-link at configure time. This is safer @@ -79,6 +84,8 @@ Library -- target sensative, should not be used MachDeps.h + build-tool-depends: alex:alex >= 3.2.6, happy:happy >= 1.20.0, genprimopcode:genprimopcode, deriveConstants:deriveConstants + Build-Depends: base >= 4.11 && < 4.17, deepseq >= 1.4 && < 1.5, directory >= 1 && < 1.4, @@ -783,6 +790,9 @@ Library Language.Haskell.Syntax.Pat Language.Haskell.Syntax.Type + autogen-modules: GHC.Platform.Constants + GHC.Settings.Config + reexported-modules: GHC.Platform.ArchOS , GHC.Platform.Host |