Skip to content

Commit

Permalink
WIP support asm/cmm/js sources in executable components (haskell#8639)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshMeredith authored and ulysses4ever committed Jul 16, 2023
1 parent 6eed6f5 commit 2eac4c1
Showing 1 changed file with 136 additions and 0 deletions.
136 changes: 136 additions & 0 deletions Cabal/src/Distribution/Simple/GHC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1550,6 +1550,9 @@ decodeMainIsArg arg
data BuildSources = BuildSources
{ cSourcesFiles :: [FilePath]
, cxxSourceFiles :: [FilePath]
, jsSourceFiles :: [FilePath]
, asmSourceFiles :: [FilePath]
, cmmSourceFiles :: [FilePath]
, inputSourceFiles :: [FilePath]
, inputSourceModules :: [ModuleName]
}
Expand Down Expand Up @@ -1600,6 +1603,9 @@ gbuildSources verbosity pkgId specVer tmpDir bm =
BuildSources
{ cSourcesFiles = cSources bnfo
, cxxSourceFiles = cxxSources bnfo
, jsSourceFiles = jsSources bnfo
, asmSourceFiles = asmSources bnfo
, cmmSourceFiles = cmmSources bnfo
, inputSourceFiles = [main]
, inputSourceModules =
filter (/= mainModName) $
Expand All @@ -1610,6 +1616,9 @@ gbuildSources verbosity pkgId specVer tmpDir bm =
BuildSources
{ cSourcesFiles = cSources bnfo
, cxxSourceFiles = cxxSources bnfo
, jsSourceFiles = jsSources bnfo
, asmSourceFiles = asmSources bnfo
, cmmSourceFiles = cmmSources bnfo
, inputSourceFiles = [main]
, inputSourceModules = exeModules exe
}
Expand All @@ -1624,6 +1633,9 @@ gbuildSources verbosity pkgId specVer tmpDir bm =
BuildSources
{ cSourcesFiles = csf
, cxxSourceFiles = cxxsf
, jsSourceFiles = jsSources bnfo
, asmSourceFiles = asmSources bnfo
, cmmSourceFiles = cmmSources bnfo
, inputSourceFiles = []
, inputSourceModules = exeModules exe
}
Expand All @@ -1633,6 +1645,9 @@ gbuildSources verbosity pkgId specVer tmpDir bm =
BuildSources
{ cSourcesFiles = cSources bnfo
, cxxSourceFiles = cxxSources bnfo
, jsSourceFiles = jsSources bnfo
, asmSourceFiles = asmSources bnfo
, cmmSourceFiles = cmmSources bnfo
, inputSourceFiles = []
, inputSourceModules = foreignLibModules flib
}
Expand Down Expand Up @@ -1966,6 +1981,127 @@ gbuild verbosity numJobs pkg_descr lbi bm clbi = do
| filename <- cSrcs
]

-- build any JS sources
unless (null $ jsSourceFiles buildSources) $ do
info verbosity "Building JS Sources..."
sequence_
[ do
let vanillaJsOpts =
Internal.componentJsGhcOptions
verbosity
implInfo
lbi
bnfo
clbi
tmpDir
filename
profJsOpts =
vanillaJsOpts
`mappend` mempty
{ ghcOptProfilingMode = toFlag True
, ghcOptObjSuffix = toFlag "p_o"
}
opts
| needProfiling = profJsOpts
| otherwise = vanillaJsOpts
odir = fromFlag (ghcOptObjDir vanillaJsOpts)
createDirectoryIfMissingVerbose verbosity True odir
needsRecomp <- checkNeedsRecompilation filename opts
when needsRecomp $
runGhcProg opts
| filename <- jsSourceFiles buildSources
]

-- build any ASM sources
unless (null $ asmSourceFiles buildSources) $ do
info verbosity "Building Assembler Sources..."
sequence_
[ do
let baseAsmOpts =
Internal.componentAsmGhcOptions
verbosity
implInfo
lbi
bnfo
clbi
tmpDir
filename
vanillaAsmOpts =
if isGhcDynamic
then -- Dynamic GHC requires objects to be built
-- with -fPIC for REPL to work. See #2207.
baseAsmOpts{ghcOptFPic = toFlag True}
else baseAsmOpts
profAsmOpts =
vanillaAsmOpts
`mappend` mempty
{ ghcOptProfilingMode = toFlag True
, ghcOptObjSuffix = toFlag "p_o"
}
sharedAsmOpts =
vanillaAsmOpts
`mappend` mempty
{ ghcOptFPic = toFlag True
, ghcOptDynLinkMode = toFlag GhcDynamicOnly
, ghcOptObjSuffix = toFlag "dyn_o"
}
opts
| needProfiling = profAsmOpts
| needDynamic = sharedAsmOpts
| otherwise = vanillaAsmOpts
odir = fromFlag (ghcOptObjDir vanillaAsmOpts)
createDirectoryIfMissingVerbose verbosity True odir
needsRecomp <- checkNeedsRecompilation filename opts
when needsRecomp $
runGhcProg opts
| filename <- asmSourceFiles buildSources
]

-- build any Cmm sources
unless (null $ cmmSourceFiles buildSources) $ do
info verbosity "Building C-- Sources..."
sequence_
[ do
let baseCmmOpts =
Internal.componentCmmGhcOptions
verbosity
implInfo
lbi
bnfo
clbi
tmpDir
filename
vanillaCmmOpts =
if isGhcDynamic
then -- Dynamic GHC requires C sources to be built
-- with -fPIC for REPL to work. See #2207.
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"
}
opts
| needProfiling = profCmmOpts
| needDynamic = sharedCmmOpts
| otherwise = vanillaCmmOpts
odir = fromFlag (ghcOptObjDir vanillaCmmOpts)
createDirectoryIfMissingVerbose verbosity True odir
needsRecomp <- checkNeedsRecompilation filename opts
when needsRecomp $
runGhcProg opts
| filename <- cmmSourceFiles buildSources
]

-- 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
-- exports.
Expand Down

0 comments on commit 2eac4c1

Please sign in to comment.