Skip to content

Commit

Permalink
Add C-- support bits for cmm-sources feature
Browse files Browse the repository at this point in the history
  • Loading branch information
hsyl20 authored and hvr committed Jun 26, 2019
1 parent 9b04149 commit 15f068c
Showing 2 changed files with 70 additions and 7 deletions.
33 changes: 30 additions & 3 deletions Cabal/Distribution/Simple/GHC.hs
Original file line number Diff line number Diff line change
@@ -732,9 +732,36 @@ buildOrReplLib mReplFlags verbosity numJobs pkg_descr lbi lib clbi = do
unless forRepl $ whenProfLib (runGhcProgIfNeeded profAsmOpts)
| filename <- asmSources libBi]

-- TODO -- TODO -- TODO -- TODO -- TODO -- TODO
-- TODO: Add missing support for CMM files
--
-- build any Cmm sources
unless (not has_code || null (cmmSources libBi)) $ do
info verbosity "Building C-- Sources..."
sequence_
[ do let baseCmmOpts = Internal.componentCmmGhcOptions verbosity implInfo
lbi libBi clbi libTargetDir filename
vanillaCmmOpts = if isGhcDynamic
-- Dynamic GHC requires C sources to be built
-- with -fPIC for REPL to work. See #2207.
then baseCmmOpts { ghcOptFPic = toFlag True }
else baseCmmOpts
profCmmOpts = vanillaCmmOpts `mappend` mempty {
ghcOptProfilingMode = toFlag True,
ghcOptObjSuffix = toFlag "p_o"
}
sharedCmmOpts = vanillaCmmOpts `mappend` mempty {
ghcOptFPic = toFlag True,
ghcOptDynLinkMode = toFlag GhcDynamicOnly,
ghcOptObjSuffix = toFlag "dyn_o"
}
odir = fromFlag (ghcOptObjDir vanillaCmmOpts)
createDirectoryIfMissingVerbose verbosity True odir
let runGhcProgIfNeeded cmmOpts = do
needsRecomp <- checkNeedsRecompilation filename cmmOpts
when needsRecomp $ runGhcProg cmmOpts
runGhcProgIfNeeded vanillaCmmOpts
unless forRepl $
whenSharedLib forceSharedLib (runGhcProgIfNeeded sharedCmmOpts)
unless forRepl $ whenProfLib (runGhcProgIfNeeded profCmmOpts)
| filename <- cmmSources libBi]

-- TODO: problem here is we need the .c files built first, so we can load them
-- with ghci, but .c files can depend on .h files generated by ghc by ffi
44 changes: 40 additions & 4 deletions Cabal/Distribution/Simple/GHC/Internal.hs
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ module Distribution.Simple.GHC.Internal (
targetPlatform,
getGhcInfo,
componentCcGhcOptions,
componentCmmGhcOptions,
componentCxxGhcOptions,
componentAsmGhcOptions,
componentGhcOptions,
@@ -433,15 +434,50 @@ componentGhcOptions verbosity implInfo lbi bi clbi odir =
ghcOptExtensionMap = Map.fromList . compilerExtensions $ (compiler lbi)
}
where
toGhcOptimisation NoOptimisation = mempty --TODO perhaps override?
toGhcOptimisation NormalOptimisation = toFlag GhcNormalOptimisation
toGhcOptimisation MaximumOptimisation = toFlag GhcMaximumOptimisation

exe_paths = [ componentBuildDir lbi (targetCLBI exe_tgt)
| uid <- componentExeDeps clbi
-- TODO: Ugh, localPkgDescr
, Just exe_tgt <- [unitIdTarget' (localPkgDescr lbi) lbi uid] ]

toGhcOptimisation :: OptimisationLevel -> Flag GhcOptimisation
toGhcOptimisation NoOptimisation = mempty --TODO perhaps override?
toGhcOptimisation NormalOptimisation = toFlag GhcNormalOptimisation
toGhcOptimisation MaximumOptimisation = toFlag GhcMaximumOptimisation


componentCmmGhcOptions :: Verbosity -> GhcImplInfo -> LocalBuildInfo
-> BuildInfo -> ComponentLocalBuildInfo
-> FilePath -> FilePath
-> GhcOptions
componentCmmGhcOptions verbosity _implInfo lbi bi clbi odir filename =
mempty {
-- Respect -v0, but don't crank up verbosity on GHC if
-- Cabal verbosity is requested. For that, use --ghc-option=-v instead!
ghcOptVerbosity = toFlag (min verbosity normal),
ghcOptMode = toFlag GhcModeCompile,
ghcOptInputFiles = toNubListR [filename],

ghcOptCppIncludePath = toNubListR $ [autogenComponentModulesDir lbi clbi
,autogenPackageModulesDir lbi
,odir]
-- includes relative to the package
++ PD.includeDirs bi
-- potential includes generated by `configure'
-- in the build directory
++ [buildDir lbi </> dir | dir <- PD.includeDirs bi],
ghcOptCppOptions = cppOptions bi,
ghcOptCppIncludes = toNubListR $
[autogenComponentModulesDir lbi clbi </> cppHeaderName],
ghcOptHideAllPackages= toFlag True,
ghcOptPackageDBs = withPackageDB lbi,
ghcOptPackages = toNubListR $ mkGhcOptPackages clbi,
ghcOptOptimisation = toGhcOptimisation (withOptimization lbi),
ghcOptDebugInfo = toFlag (withDebugInfo lbi),
ghcOptExtra = hcOptions GHC bi,
ghcOptObjDir = toFlag odir
}


-- | Strip out flags that are not supported in ghci
filterGhciFlags :: [String] -> [String]
filterGhciFlags = filter supported

0 comments on commit 15f068c

Please sign in to comment.