Skip to content

Commit

Permalink
build: interrogate OSX version numbers on startup so we can supply th…
Browse files Browse the repository at this point in the history
…e correct -triple to llvm-mc
  • Loading branch information
benl23x5 committed May 3, 2016
1 parent 16ed46c commit 32034f3
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 27 deletions.
50 changes: 36 additions & 14 deletions packages/ddc-build/DDC/Build/Builder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ instance Pretty Builder where
--
builders :: BuilderConfig -> BuilderHost -> [Builder]
builders config host
= [ builder_X8632_Darwin config host
, builder_X8664_Darwin 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 ]
Expand All @@ -160,11 +160,11 @@ determineDefaultBuilder config
mHost <- determineDefaultBuilderHost

case (mPlatform, mHost) of
(Just (Platform ArchX86_32 OsDarwin), Just host)
-> return $ Just (builder_X8632_Darwin config host)
(Just (Platform ArchX86_32 (OsDarwin mVersion)), Just host)
-> return $ Just (builder_X8632_Darwin config host mVersion)

(Just (Platform ArchX86_64 OsDarwin), Just host)
-> return $ Just (builder_X8664_Darwin config host)
(Just (Platform ArchX86_64 (OsDarwin mVersion)), Just host)
-> return $ Just (builder_X8664_Darwin config host mVersion)

(Just (Platform ArchX86_32 OsLinux), Just host)
-> return $ Just (builder_X8632_Linux config host)
Expand Down Expand Up @@ -201,11 +201,11 @@ determineDefaultBuilderHost


-- x86_32-darwin ----------------------------------------------------------------
builder_X8632_Darwin config host
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
Expand All @@ -231,7 +231,18 @@ builder_X8632_Darwin config host
, 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 ]

Expand Down Expand Up @@ -259,11 +270,11 @@ builder_X8632_Darwin config host
}

-- x86_64-darwin --------------------------------------------------------------
builder_X8664_Darwin config host
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
Expand All @@ -289,7 +300,18 @@ builder_X8664_Darwin config host
, 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 ]

Expand Down
56 changes: 43 additions & 13 deletions packages/ddc-build/DDC/Build/Platform.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ instance Pretty Platform where
staticFileExtensionOfPlatform :: Platform -> String
staticFileExtensionOfPlatform pp
= case platformOs pp of
OsDarwin -> "a"
OsDarwin{} -> "a"
OsLinux -> "a"
OsCygwin -> "a"
OsMingw -> "a"
Expand All @@ -52,7 +52,7 @@ staticFileExtensionOfPlatform pp
sharedFileExtensionOfPlatform :: Platform -> String
sharedFileExtensionOfPlatform pp
= case platformOs pp of
OsDarwin -> "dylib"
OsDarwin{} -> "dylib"
OsLinux -> "so"
OsCygwin -> "so"
OsMingw -> "dll"
Expand Down Expand Up @@ -89,16 +89,24 @@ archPointerWidth arch
-------------------------------------------------------------------------------
-- | 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"
Expand Down Expand Up @@ -154,17 +162,39 @@ determineHostOs
= do (exitCode, strOs, _)
<- System.readProcessWithExitCode "uname" [] ""

let result
| System.ExitFailure{} <- exitCode
= Nothing
case exitCode of
System.ExitFailure{}
-> return Nothing

| isPrefixOf "Darwin" strOs = Just OsDarwin
| isPrefixOf "Linux" strOs = Just OsLinux
| isPrefixOf "CYGWIN" strOs = Just OsCygwin
| isPrefixOf "MINGW" strOs = Just OsMingw
| otherwise = Nothing
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

return result

-- | 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"
Expand Down

0 comments on commit 32034f3

Please sign in to comment.