Skip to content
This repository has been archived by the owner on Aug 2, 2020. It is now read-only.

Use GHC to compile C files #380

Merged
merged 1 commit into from
Jul 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Builder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import Stage
-- * Extracting source dependencies, e.g. by passing @-M@ command line argument;
-- * Linking object files & static libraries into an executable.
-- We have CcMode for C compiler and GhcMode for GHC.
data CcMode = CompileC | FindCDependencies deriving (Eq, Generic, Show)
data GhcMode = CompileHs | FindHsDependencies | LinkHs
data CcMode = CompileC | FindCDependencies deriving (Eq, Generic, Show)
data GhcMode = CompileCWithGhc | CompileHs | FindHsDependencies | LinkHs
deriving (Eq, Generic, Show)

-- | GhcPkg can initialise a package database and register packages in it.
Expand Down
6 changes: 3 additions & 3 deletions src/Rules/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ compilePackage rs context@Context {..} = do
buildWithResources rs $ Target context (Ghc CompileHs stage) [src] [obj]

priority 2.0 $ do
nonHs "c" %> compile (Cc CompileC ) (obj2src "c" isGeneratedCFile )
nonHs "cmm" %> compile (Ghc CompileHs) (obj2src "cmm" isGeneratedCmmFile)
nonHs "s" %> compile (Ghc CompileHs) (obj2src "S" $ const False )
nonHs "c" %> compile (Ghc CompileCWithGhc) (obj2src "c" isGeneratedCFile )
nonHs "cmm" %> compile (Ghc CompileHs) (obj2src "cmm" isGeneratedCmmFile)
nonHs "s" %> compile (Ghc CompileHs) (obj2src "S" $ const False )

-- TODO: Add dependencies for #include of .h and .hs-incl files (gcc -MM?).
[ path <//> "*" <.> suf way | suf <- [ osuf, hisuf] ] &%> compileHs
Expand Down
24 changes: 23 additions & 1 deletion src/Settings/Builders/Ghc.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
module Settings.Builders.Ghc (ghcBuilderArgs, ghcMBuilderArgs, haddockGhcArgs) where
module Settings.Builders.Ghc (
ghcBuilderArgs, ghcMBuilderArgs, haddockGhcArgs,
ghcCbuilderArgs
) where

import Flavour
import GHC
Expand All @@ -15,6 +18,25 @@ ghcBuilderArgs = (builder (Ghc CompileHs) ||^ builder (Ghc LinkHs)) ? do
, append =<< getInputs
, arg "-o", arg =<< getOutput ]

ghcCbuilderArgs :: Args
ghcCbuilderArgs =
builder (Ghc CompileCWithGhc) ? do
way <- getWay
let ccArgs = [ append =<< getPkgDataList CcArgs
, getSettingList . ConfCcArgs =<< getStage
, cIncludeArgs
, arg "-Werror"
, Dynamic `wayUnit` way ? append [ "-fPIC", "-DDYNAMIC" ] ]

mconcat [ arg "-Wall"
, ghcLinkArgs
, commonGhcArgs
, mconcat (map (map ("-optc" ++) <$>) ccArgs)
, arg "-c"
, append =<< getInputs
, arg "-o"
, arg =<< getOutput ]

ghcLinkArgs :: Args
ghcLinkArgs = builder (Ghc LinkHs) ? do
stage <- getStage
Expand Down
1 change: 1 addition & 0 deletions src/Settings/Default.hs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ defaultBuilderArgs = mconcat
, deriveConstantsBuilderArgs
, genPrimopCodeBuilderArgs
, ghcBuilderArgs
, ghcCbuilderArgs
, ghcCabalBuilderArgs
, ghcCabalHsColourBuilderArgs
, ghcMBuilderArgs
Expand Down
2 changes: 1 addition & 1 deletion src/Settings/Packages/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ import Settings
basePackageArgs :: Args
basePackageArgs = package base ? mconcat
[ builder GhcCabal ? arg ("--flags=" ++ integerLibraryName)
, builder Cc ? arg "-O2" ] -- Fix the 'unknown symbol stat' issue, see #259.
, builder (Ghc CompileCWithGhc) ? arg "-optc-O2" ] -- Fix the 'unknown symbol stat' issue, see #259.
7 changes: 4 additions & 3 deletions src/Settings/Packages/Rts.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ rtsPackageArgs = package rts ? do
ffiIncludeDir <- getSetting FfiIncludeDir
ffiLibraryDir <- getSetting FfiLibDir
ghclibDir <- expr installGhcLibDir
mconcat
[ builder Cc ? mconcat
let cArgs =
[ arg "-Irts"
, arg $ "-I" ++ path
, arg $ "-DRtsWay=\"rts_" ++ show way ++ "\""
Expand Down Expand Up @@ -96,8 +95,10 @@ rtsPackageArgs = package rts ? do
append [ "-Wno-incompatible-pointer-types" ]
]

mconcat
[ builder (Cc FindCDependencies) ? mconcat cArgs
, builder (Ghc CompileCWithGhc) ? mconcat (map (map ("-optc" ++) <$>) cArgs)
, builder Ghc ? arg "-Irts"

, builder HsCpp ? append
[ "-DTOP=" ++ show top
, "-DFFI_INCLUDE_DIR=" ++ show ffiIncludeDir
Expand Down