ddc-build 0.4.2.1 → 0.4.2.2
raw patch · 4 files changed
+198/−66 lines, 4 filesdep ~ddc-core-llvmPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: ddc-core-llvm
API changes (from Hackage documentation)
+ DDC.Build.Builder: BuilderHost :: String -> BuilderHost
+ DDC.Build.Builder: [buildLlvmVersion] :: Builder -> String
+ DDC.Build.Builder: [builderHostLlvmVersion] :: BuilderHost -> String
+ DDC.Build.Builder: data BuilderHost
+ DDC.Build.Builder: determineDefaultBuilderHost :: IO (Maybe BuilderHost)
+ DDC.Build.Platform: determineHostLlvmVersion :: Maybe FilePath -> IO (Maybe String)
- DDC.Build.Builder: Builder :: String -> Platform -> Platform -> Platform -> FilePath -> FilePath -> (FilePath -> FilePath -> IO ()) -> (FilePath -> FilePath -> IO ()) -> (FilePath -> FilePath -> IO ()) -> ([FilePath] -> FilePath -> IO ()) -> ([FilePath] -> FilePath -> IO ()) -> ([FilePath] -> FilePath -> IO ()) -> Builder
+ DDC.Build.Builder: Builder :: String -> Platform -> Platform -> Platform -> FilePath -> FilePath -> (FilePath -> FilePath -> IO ()) -> (FilePath -> FilePath -> IO ()) -> String -> (FilePath -> FilePath -> IO ()) -> ([FilePath] -> FilePath -> IO ()) -> ([FilePath] -> FilePath -> IO ()) -> ([FilePath] -> FilePath -> IO ()) -> Builder
- DDC.Build.Builder: builders :: BuilderConfig -> [Builder]
+ DDC.Build.Builder: builders :: BuilderConfig -> BuilderHost -> [Builder]
- DDC.Build.Platform: OsDarwin :: Os
+ DDC.Build.Platform: OsDarwin :: (Maybe (Int, Int, Int)) -> Os
Files
- DDC/Build/Builder.hs +96/−37
- DDC/Build/Pipeline/Llvm.hs +16/−8
- DDC/Build/Platform.hs +84/−19
- ddc-build.cabal +2/−2
DDC/Build/Builder.hs view
@@ -1,11 +1,13 @@ module DDC.Build.Builder ( BuilderConfig (..)+ , BuilderHost (..) , Builder (..) , BuilderResult (..) , builders - , determineDefaultBuilder)+ , determineDefaultBuilder+ , determineDefaultBuilderHost) where import DDC.Build.Platform import DDC.Base.Pretty hiding ((</>))@@ -27,10 +29,18 @@ -- system and base library. , builderConfigBaseLibDir :: FilePath - -- | Runtime library link with.+ -- | Runtime library to link with. , builderConfigLibFile :: FilePath -> FilePath -> FilePath } +-- | Builder information that we determine by interrogating the host platform.+-- This tells us what we need to know about the environment that we're +-- building in, versions of software tools etc. This is separate +data BuilderHost+ = BuilderHost+ { builderHostLlvmVersion :: String }++ -- | Actions to use to invoke external compilation tools. data Builder = Builder@@ -63,6 +73,9 @@ -- to compile a .ll file into a .s file. , buildLlc :: FilePath -> FilePath -> IO () + -- | Version string of the LLVM compiler suite we are using.+ , buildLlvmVersion :: String + -- | Invoke the system assembler -- to assemble a .s file into a .o file. , buildAs :: FilePath -> FilePath -> IO ()@@ -126,13 +139,13 @@ -- @x86_32-cygwin@, -- @ppc32-linux@ ---builders :: BuilderConfig -> [Builder]-builders config- = [ builder_X8632_Darwin config- , builder_X8664_Darwin config- , builder_X8632_Linux config - , builder_X8664_Linux config- , builder_PPC32_Linux config ]+builders :: BuilderConfig -> BuilderHost -> [Builder]+builders config host+ = [ builder_X8632_Darwin config host Nothing+ , builder_X8664_Darwin config host Nothing+ , builder_X8632_Linux config host+ , builder_X8664_Linux config host+ , builder_PPC32_Linux config host ] -- defaultBuilder -------------------------------------------------------------@@ -144,42 +157,60 @@ determineDefaultBuilder :: BuilderConfig -> IO (Maybe Builder) determineDefaultBuilder config = do mPlatform <- determineHostPlatform+ mHost <- determineDefaultBuilderHost - case mPlatform of- Just (Platform ArchX86_32 OsDarwin) - -> return $ Just (builder_X8632_Darwin config)+ case (mPlatform, mHost) of+ (Just (Platform ArchX86_32 (OsDarwin mVersion)), Just host)+ -> return $ Just (builder_X8632_Darwin config host mVersion) - Just (Platform ArchX86_64 OsDarwin) - -> return $ Just (builder_X8664_Darwin config)+ (Just (Platform ArchX86_64 (OsDarwin mVersion)), Just host)+ -> return $ Just (builder_X8664_Darwin config host mVersion) - Just (Platform ArchX86_32 OsLinux)- -> return $ Just (builder_X8632_Linux config)+ (Just (Platform ArchX86_32 OsLinux), Just host)+ -> return $ Just (builder_X8632_Linux config host) - Just (Platform ArchX86_64 OsLinux)- -> return $ Just (builder_X8664_Linux config)+ (Just (Platform ArchX86_64 OsLinux), Just host)+ -> return $ Just (builder_X8664_Linux config host) - Just (Platform ArchPPC_32 OsLinux)- -> return $ Just (builder_PPC32_Linux config)+ (Just (Platform ArchPPC_32 OsLinux), Just host)+ -> return $ Just (builder_PPC32_Linux config host) - Just (Platform ArchX86_32 OsCygwin)- -> return $ Just (builder_X8632_Cygwin config)+ (Just (Platform ArchX86_32 OsCygwin), Just host)+ -> return $ Just (builder_X8632_Cygwin config host) - Just (Platform ArchX86_32 OsMingw)- -> return $ Just (builder_X8632_Mingw config)+ (Just (Platform ArchX86_32 OsMingw), Just host)+ -> return $ Just (builder_X8632_Mingw config host) _ -> return Nothing +-- | Determine the default builder host configuration, +-- this the default set of build tools that we can see in the current path.+determineDefaultBuilderHost :: IO (Maybe BuilderHost)+determineDefaultBuilderHost+ = do + -- Get the version of the LLVM suite in the current path.+ mStrLlvmVersion <- determineHostLlvmVersion Nothing+ case mStrLlvmVersion of+ Nothing + -> return Nothing++ Just strLlvmVersion+ -> return $ Just $ BuilderHost+ { builderHostLlvmVersion = strLlvmVersion }++ -- x86_32-darwin -----------------------------------------------------------------builder_X8632_Darwin config+builder_X8632_Darwin config host mVersion = Builder { builderName = "x86_32-darwin" - , buildHost = Platform ArchX86_32 OsDarwin- , buildTarget = Platform ArchX86_32 OsDarwin+ , buildHost = Platform ArchX86_32 (OsDarwin mVersion)+ , buildTarget = Platform ArchX86_32 (OsDarwin mVersion) , buildSpec = Llvm.platform32 , buildBaseSrcDir = builderConfigBaseSrcDir config , buildBaseLibDir = builderConfigBaseLibDir config + , buildLlvmVersion = builderHostLlvmVersion host , buildLlc = \llFile sFile -> doCmd "LLVM compiler" [(2, BuilderCanceled)]@@ -200,7 +231,18 @@ , buildAs = \sFile oFile -> doCmd "assembler" [(2, BuilderCanceled)]- [ "llvm-mc -arch x86 -filetype=obj" + [ "llvm-mc -arch x86 -filetype=obj"++ -- From LLVM 3.8 we need to set the -triple explicitly which includes+ -- the macosx OS specifier. llc inserts a pragma into the output+ -- .s files saying they're for a specific version of macosx. If we+ -- don't set the same version in the triple passed to llvm-mc then+ -- it throws a warning. Note that Darwin v14.5 is OSX v10.10.5 etc.+ , case mVersion of+ Nothing -> ""+ Just (major, _minor, _patch)+ -> "-triple=x86-apple-macosx10." ++ show (major - 4)+ , "-o", oFile , sFile ] @@ -228,15 +270,16 @@ } -- x86_64-darwin ---------------------------------------------------------------builder_X8664_Darwin config+builder_X8664_Darwin config host mVersion = Builder { builderName = "x86_64-darwin"- , buildHost = Platform ArchX86_64 OsDarwin- , buildTarget = Platform ArchX86_64 OsDarwin+ , buildHost = Platform ArchX86_64 (OsDarwin mVersion)+ , buildTarget = Platform ArchX86_64 (OsDarwin mVersion) , buildSpec = Llvm.platform64 , buildBaseSrcDir = builderConfigBaseSrcDir config , buildBaseLibDir = builderConfigBaseLibDir config + , buildLlvmVersion = builderHostLlvmVersion host , buildLlc = \llFile sFile -> doCmd "LLVM compiler" [(2, BuilderCanceled)]@@ -257,7 +300,18 @@ , buildAs = \sFile oFile -> doCmd "assembler" [(2, BuilderCanceled)]- [ "llvm-mc -arch x86-64 -filetype=obj" + [ "llvm-mc -filetype=obj"++ -- From LLVM 3.8 we need to set the -triple explicitly which includes+ -- the macosx OS specifier. llc inserts a pragma into the output+ -- .s files saying they're for a specific version of macosx. If we+ -- don't set the same version in the triple passed to llvm-mc then+ -- it throws a warning. Note that Darwin v14.5 is OSX v10.10.5 etc.+ , case mVersion of+ Nothing -> ""+ Just (major, _minor, _patch)+ -> "-triple=x86_64-apple-macosx10." ++ show (major - 4)+ , "-o", oFile , sFile ] @@ -286,7 +340,7 @@ -- x86_32-linux ----------------------------------------------------------------builder_X8632_Linux config+builder_X8632_Linux config host = Builder { builderName = "x86_32-linux" , buildHost = Platform ArchX86_32 OsLinux@@ -295,6 +349,7 @@ , buildBaseSrcDir = builderConfigBaseSrcDir config , buildBaseLibDir = builderConfigBaseLibDir config + , buildLlvmVersion = builderHostLlvmVersion host , buildLlc = \llFile sFile -> doCmd "LLVM compiler" [(2, BuilderCanceled)]@@ -343,7 +398,7 @@ -- x86_64-linux ----------------------------------------------------------------builder_X8664_Linux config+builder_X8664_Linux config host = Builder { builderName = "x86_64-linux" , buildHost = Platform ArchX86_64 OsLinux@@ -352,6 +407,7 @@ , buildBaseSrcDir = builderConfigBaseSrcDir config , buildBaseLibDir = builderConfigBaseLibDir config + , buildLlvmVersion = builderHostLlvmVersion host , buildLlc = \llFile sFile -> doCmd "LLVM compiler" [(2, BuilderCanceled)]@@ -400,7 +456,7 @@ -- ppc32-linux ----------------------------------------------------------------builder_PPC32_Linux config+builder_PPC32_Linux config host = Builder { builderName = "ppc32-linux" , buildHost = Platform ArchPPC_32 OsLinux@@ -409,6 +465,7 @@ , buildBaseSrcDir = builderConfigBaseSrcDir config , buildBaseLibDir = builderConfigBaseLibDir config + , buildLlvmVersion = builderHostLlvmVersion host , buildLlc = \llFile sFile -> doCmd "LLVM compiler" [(2, BuilderCanceled)]@@ -456,7 +513,7 @@ -- x86_32-cygwin ----------------------------------------------------------------builder_X8632_Cygwin config+builder_X8632_Cygwin config host = Builder { builderName = "x86_32-cygwin" , buildHost = Platform ArchX86_32 OsCygwin@@ -465,6 +522,7 @@ , buildBaseSrcDir = builderConfigBaseSrcDir config , buildBaseLibDir = builderConfigBaseLibDir config + , buildLlvmVersion = builderHostLlvmVersion host , buildLlc = \llFile sFile -> doCmd "LLVM compiler" [(2, BuilderCanceled)]@@ -513,7 +571,7 @@ -- x86_32-mingw -----------------------------------------------------------------builder_X8632_Mingw config+builder_X8632_Mingw config host = Builder { builderName = "x86_32-mingw" , buildHost = Platform ArchX86_32 OsMingw@@ -522,6 +580,7 @@ , buildBaseSrcDir = builderConfigBaseSrcDir config , buildBaseLibDir = builderConfigBaseLibDir config + , buildLlvmVersion = builderHostLlvmVersion host , buildLlc = \llFile sFile -> doCmd "LLVM compiler" [(2, BuilderCanceled)]
DDC/Build/Pipeline/Llvm.hs view
@@ -5,10 +5,10 @@ where import DDC.Build.Pipeline.Error import DDC.Build.Pipeline.Sink-import DDC.Build.Builder-import DDC.Llvm.Pretty () import DDC.Base.Pretty import Control.Monad+import qualified DDC.Build.Builder as Build+import qualified DDC.Llvm.Pretty as Llvm import qualified DDC.Llvm.Syntax as Llvm import System.Directory @@ -18,7 +18,7 @@ = PipeLlvmPrint Sink | PipeLlvmCompile - { pipeBuilder :: Builder+ { pipeBuilder :: Build.Builder , pipeFileLlvm :: FilePath , pipeFileAsm :: FilePath , pipeFileObject :: FilePath@@ -47,15 +47,23 @@ !builder !llPath !sPath !oPath !mExePath !osLinkOther !keepLlvmFiles !keepAsmFiles -> {-# SCC "PipeLlvmCompile" #-}- do -- Write out the LLVM source file.- let llSrc = renderIndent $ ppr mm+ do + -- LLVM config.+ let llConfig = Llvm.configOfVersion+ $ Just $ Build.buildLlvmVersion builder++ -- Pretty printer mode to use for the current LLVM version.+ let llMode = Llvm.prettyModeModuleOfConfig llConfig++ -- Write out the LLVM source file.+ let llSrc = renderIndent $ pprModePrec llMode (0 :: Int) mm writeFile llPath llSrc -- Compile LLVM source file into .s file.- buildLlc builder llPath sPath+ Build.buildLlc builder llPath sPath -- Assemble .s file into .o file- buildAs builder sPath oPath+ Build.buildAs builder sPath oPath -- Link .o file into an executable if we were asked for one. (case mExePath of@@ -63,7 +71,7 @@ -> return () Just exePath- -> do buildLdExe builder (oPath : osLinkOther) exePath+ -> do Build.buildLdExe builder (oPath : osLinkOther) exePath return ()) -- Remove LLVM IR files if we weren't asked for them.
DDC/Build/Platform.hs view
@@ -12,12 +12,15 @@ -- * Host platform , determineHostPlatform , determineHostArch- , determineHostOs)+ , determineHostOs+ , determineHostLlvmVersion) where import DDC.Base.Pretty-import System.Process-import System.Exit-import Data.List+import Data.List as List+import Data.Maybe as Maybe+import Data.Char as Char+import qualified System.Process as System+import qualified System.Exit as System -------------------------------------------------------------------------------@@ -39,7 +42,7 @@ staticFileExtensionOfPlatform :: Platform -> String staticFileExtensionOfPlatform pp = case platformOs pp of- OsDarwin -> "a"+ OsDarwin{} -> "a" OsLinux -> "a" OsCygwin -> "a" OsMingw -> "a"@@ -49,7 +52,7 @@ sharedFileExtensionOfPlatform :: Platform -> String sharedFileExtensionOfPlatform pp = case platformOs pp of- OsDarwin -> "dylib"+ OsDarwin{} -> "dylib" OsLinux -> "so" OsCygwin -> "so" OsMingw -> "dll"@@ -86,16 +89,24 @@ ------------------------------------------------------------------------------- -- | Operating System. data Os- = OsDarwin+ -- | Darwin, including the major, minor and patch numbers, + -- if specified.+ = OsDarwin (Maybe (Int, Int, Int))++ -- | Generic Linux. | OsLinux++ -- | Cygwin on Windows. | OsCygwin++ -- | MinGW on Windows. | OsMingw deriving (Eq, Show) instance Pretty Os where ppr os = case os of- OsDarwin -> text "Darwin"+ OsDarwin{} -> text "Darwin" OsLinux -> text "Linux" OsCygwin -> text "Cygwin" OsMingw -> text "Mingw"@@ -126,10 +137,12 @@ determineHostArch :: IO (Maybe Arch) determineHostArch = do (exitCode, strArch, _) - <- readProcessWithExitCode "uname" ["-m"] ""+ <- System.readProcessWithExitCode "uname" ["-m"] "" let result- | ExitFailure{} <- exitCode = Nothing+ | System.ExitFailure{} <- exitCode + = Nothing+ | isPrefixOf "i386" strArch = Just ArchX86_32 | isPrefixOf "i486" strArch = Just ArchX86_32 | isPrefixOf "i586" strArch = Just ArchX86_32@@ -147,15 +160,67 @@ determineHostOs :: IO (Maybe Os) determineHostOs = do (exitCode, strOs, _)- <- readProcessWithExitCode "uname" [] ""+ <- System.readProcessWithExitCode "uname" [] "" - let result- | ExitFailure{} <- exitCode = Nothing- | isPrefixOf "Darwin" strOs = Just OsDarwin- | isPrefixOf "Linux" strOs = Just OsLinux- | isPrefixOf "CYGWIN" strOs = Just OsCygwin- | isPrefixOf "MINGW" strOs = Just OsMingw- | otherwise = Nothing+ case exitCode of+ System.ExitFailure{}+ -> return Nothing - return result+ System.ExitSuccess+ | isPrefixOf "Darwin" strOs -> determineHostOsDarwin+ | isPrefixOf "Linux" strOs -> return $ Just OsLinux+ | isPrefixOf "CYGWIN" strOs -> return $ Just OsCygwin+ | isPrefixOf "MINGW" strOs -> return $ Just OsMingw+ | otherwise -> return Nothing+++-- | Given that we're running on Darwin, determine the version numbers.+determineHostOsDarwin :: IO (Maybe Os)+determineHostOsDarwin + = do (exitCode, strVersion, _)+ <- System.readProcessWithExitCode "uname" ["-r"] ""++ case exitCode of+ System.ExitFailure{}+ -> return Nothing++ System.ExitSuccess+ | (dsMajor, '.' : rest1) <- List.span isDigit strVersion+ , nMajor <- read dsMajor+ , (dsMinor, '.' : rest2) <- List.span isDigit rest1+ , nMinor <- read dsMinor+ , (dsPatch, _) <- List.span isDigit rest2+ , nPatch <- read dsPatch+ -> return $ Just $ OsDarwin (Just (nMajor, nMinor, nPatch))++ | otherwise+ -> return $ Nothing+++-- | Determine the host LLVM version string, eg "3.5.2"+-- Takes the path to the LLVM compiler to use, +-- or `Nothing` to use whatever is in the current path.+determineHostLlvmVersion :: Maybe FilePath -> IO (Maybe String)+determineHostLlvmVersion mpath+ = do+ let path = fromMaybe "llc" mpath+ (exitCode, strAll, _)+ <- System.readProcessWithExitCode path ["-version"] ""++ case exitCode of + System.ExitFailure{}+ -> return Nothing++ System.ExitSuccess+ -> do -- Supplying -version gives us the LLVM title as well as+ -- a list of all registered targets.+ let ls = map (takeWhile $ not . Char.isSpace)+ $ map (dropWhile Char.isSpace)+ $ mapMaybe (stripPrefix "LLVM version")+ $ map (dropWhile Char.isSpace)+ $ lines strAll++ case ls of+ [str] -> return $ Just str+ _ -> return Nothing
ddc-build.cabal view
@@ -1,5 +1,5 @@ Name: ddc-build-Version: 0.4.2.1+Version: 0.4.2.2 License: MIT License-file: LICENSE Author: The Disciplined Disciple Compiler Strike Force@@ -26,7 +26,7 @@ ddc-core == 0.4.2.*, ddc-core-simpl == 0.4.2.*, ddc-core-salt == 0.4.2.*,- ddc-core-llvm == 0.4.2.*,+ ddc-core-llvm >= 0.4.2.2 && < 0.4.3, ddc-core-flow == 0.4.2.*, ddc-core-tetra == 0.4.2.*, ddc-core-babel == 0.4.2.*,