-
Notifications
You must be signed in to change notification settings - Fork 723
Fix linking issue with cxx-options and cxx-sources fields in non-library components
#5315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7bd9c89
7787adc
c1efb8d
849d7ce
7396231
e4730ec
e5836e3
1ca8d24
082efbe
cd4e9a9
3f8c55c
76e93d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -657,14 +657,14 @@ buildOrReplLib forRepl verbosity numJobs pkg_descr lbi lib clbi = do | |
| info verbosity "Building C++ Sources..." | ||
| sequence_ | ||
| [ do let baseCxxOpts = Internal.componentCxxGhcOptions verbosity implInfo | ||
| lbi libBi clbi libTargetDir filename | ||
| lbi libBi clbi libTargetDir filename | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still a spurious whitespace change here
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we want the arguments to be vertically aligned the the function call above?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, sure. So long as it's deliberate and not just random reformatting noise. |
||
| vanillaCxxOpts = if isGhcDynamic | ||
| then baseCxxOpts { ghcOptFPic = toFlag True } | ||
| else baseCxxOpts | ||
| profCxxOpts = vanillaCxxOpts `mappend` mempty { | ||
| ghcOptProfilingMode = toFlag True, | ||
| ghcOptObjSuffix = toFlag "p_o" | ||
| } | ||
| ghcOptProfilingMode = toFlag True, | ||
| ghcOptObjSuffix = toFlag "p_o" | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And more whitespace changes here
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same deliberate, vertical alignment with this whitespace. |
||
| sharedCxxOpts = vanillaCxxOpts `mappend` mempty { | ||
| ghcOptFPic = toFlag True, | ||
| ghcOptDynLinkMode = toFlag GhcDynamicOnly, | ||
|
|
@@ -1083,20 +1083,35 @@ decodeMainIsArg arg | |
| -- 'tail' drops the char satisfying 'pred' | ||
| where (r_suf, r_pre) = break pred' (reverse str) | ||
|
|
||
| -- | Return C sources, GHC input files and GHC input modules | ||
|
|
||
| -- | A collection of: | ||
| -- * C input files | ||
| -- * C++ input files | ||
| -- * GHC input files | ||
| -- * GHC input modules | ||
| -- | ||
| -- Used to correctly build and link sources. | ||
| data BuildSources = BuildSources { | ||
| cSourcesFiles :: [FilePath], | ||
| cxxSourceFiles :: [FilePath], | ||
| inputSourceFiles :: [FilePath], | ||
| inputSourceModules :: [ModuleName] | ||
| } | ||
|
|
||
| -- | Locate and return the 'BuildSources' required to build and link. | ||
| gbuildSources :: Verbosity | ||
| -> Version -- ^ specVersion | ||
| -> FilePath | ||
| -> GBuildMode | ||
| -> IO ([FilePath], [FilePath], [ModuleName]) | ||
| -> IO BuildSources | ||
| gbuildSources verbosity specVer tmpDir bm = | ||
| case bm of | ||
| GBuildExe exe -> exeSources exe | ||
| GReplExe exe -> exeSources exe | ||
| GBuildFLib flib -> return $ flibSources flib | ||
| GReplFLib flib -> return $ flibSources flib | ||
| where | ||
| exeSources :: Executable -> IO ([FilePath], [FilePath], [ModuleName]) | ||
| exeSources :: Executable -> IO BuildSources | ||
| exeSources exe@Executable{buildInfo = bnfo, modulePath = modPath} = do | ||
| main <- findFile (tmpDir : hsSourceDirs bnfo) modPath | ||
| let mainModName = fromMaybe ModuleName.main $ exeMainModuleName exe | ||
|
|
@@ -1121,19 +1136,48 @@ gbuildSources verbosity specVer tmpDir bm = | |
| ++ display mainModName | ||
| ++ "' listed in 'other-modules' illegally!" | ||
|
|
||
| return (cSources bnfo, [main], | ||
| filter (/= mainModName) (exeModules exe)) | ||
|
|
||
| else return (cSources bnfo, [main], exeModules exe) | ||
| else return (main : cSources bnfo, [], exeModules exe) | ||
| return BuildSources { | ||
| cSourcesFiles = cSources bnfo, | ||
| cxxSourceFiles = cxxSources bnfo, | ||
| inputSourceFiles = [main], | ||
| inputSourceModules = filter (/= mainModName) $ exeModules exe | ||
| } | ||
|
|
||
| flibSources :: ForeignLib -> ([FilePath], [FilePath], [ModuleName]) | ||
| else return BuildSources { | ||
| cSourcesFiles = cSources bnfo, | ||
| cxxSourceFiles = cxxSources bnfo, | ||
| inputSourceFiles = [main], | ||
| inputSourceModules = exeModules exe | ||
| } | ||
| else let (csf, cxxsf) | ||
| | isCxx main = ( cSources bnfo, main : cxxSources bnfo) | ||
| -- if main is not a Haskell source | ||
| -- and main is not a C++ source | ||
| -- then we assume that it is a C source | ||
| | otherwise = (main : cSources bnfo, cxxSources bnfo) | ||
|
|
||
| in return BuildSources { | ||
| cSourcesFiles = csf, | ||
| cxxSourceFiles = cxxsf, | ||
| inputSourceFiles = [], | ||
| inputSourceModules = exeModules exe | ||
| } | ||
|
|
||
| flibSources :: ForeignLib -> BuildSources | ||
| flibSources flib@ForeignLib{foreignLibBuildInfo = bnfo} = | ||
| (cSources bnfo, [], foreignLibModules flib) | ||
| BuildSources { | ||
| cSourcesFiles = cSources bnfo, | ||
| cxxSourceFiles = cxxSources bnfo, | ||
| inputSourceFiles = [], | ||
| inputSourceModules = foreignLibModules flib | ||
| } | ||
|
|
||
| isHaskell :: FilePath -> Bool | ||
| isHaskell fp = elem (takeExtension fp) [".hs", ".lhs"] | ||
|
|
||
| isCxx :: FilePath -> Bool | ||
| isCxx fp = elem (takeExtension fp) [".cpp", ".cxx", ".c++"] | ||
|
|
||
| -- | Generic build function. See comment for 'GBuildMode'. | ||
| gbuild :: Verbosity -> Cabal.Flag (Maybe Int) | ||
| -> PackageDescription -> LocalBuildInfo | ||
|
|
@@ -1168,12 +1212,16 @@ gbuild verbosity numJobs pkg_descr lbi bm clbi = do | |
| | otherwise = mempty | ||
|
|
||
| rpaths <- getRPaths lbi clbi | ||
| (cSrcs, inputFiles, inputModules) <- gbuildSources verbosity | ||
| (specVersion pkg_descr) tmpDir bm | ||
| buildSources <- gbuildSources verbosity (specVersion pkg_descr) tmpDir bm | ||
|
|
||
| let isGhcDynamic = isDynamic comp | ||
| let cSrcs = cSourcesFiles buildSources | ||
| cxxSrcs = cxxSourceFiles buildSources | ||
| inputFiles = inputSourceFiles buildSources | ||
| inputModules = inputSourceModules buildSources | ||
| isGhcDynamic = isDynamic comp | ||
| dynamicTooSupported = supportsDynamicToo comp | ||
| cObjs = map (`replaceExtension` objExtension) cSrcs | ||
| cxxObjs = map (`replaceExtension` objExtension) cxxSrcs | ||
| needDynamic = gbuildNeedDynamic lbi bm | ||
| needProfiling = withProfExe lbi | ||
|
|
||
|
|
@@ -1223,7 +1271,7 @@ gbuild verbosity numJobs pkg_descr lbi bm clbi = do | |
| ghcOptLinkFrameworkDirs = toNubListR $ | ||
| PD.extraFrameworkDirs bnfo, | ||
| ghcOptInputFiles = toNubListR | ||
| [tmpDir </> x | x <- cObjs] | ||
| [tmpDir </> x | x <- cObjs ++ cxxObjs] | ||
| } | ||
| dynLinkerOpts = mempty { | ||
| ghcOptRPaths = rpaths | ||
|
|
@@ -1283,6 +1331,38 @@ gbuild verbosity numJobs pkg_descr lbi bm clbi = do | |
| runGhcProg compileOpts { ghcOptNoLink = toFlag True | ||
| , ghcOptNumJobs = numJobs } | ||
|
|
||
| -- build any C++ sources | ||
| unless (null cxxSrcs) $ do | ||
| info verbosity "Building C++ Sources..." | ||
| sequence_ | ||
| [ do let baseCxxOpts = Internal.componentCxxGhcOptions verbosity implInfo | ||
| lbi bnfo clbi tmpDir filename | ||
| vanillaCxxOpts = if isGhcDynamic | ||
| -- Dynamic GHC requires C++ sources to be built | ||
| -- with -fPIC for REPL to work. See #2207. | ||
| then baseCxxOpts { ghcOptFPic = toFlag True } | ||
| else baseCxxOpts | ||
| profCxxOpts = vanillaCxxOpts `mappend` mempty { | ||
| ghcOptProfilingMode = toFlag True | ||
| } | ||
| sharedCxxOpts = vanillaCxxOpts `mappend` mempty { | ||
| ghcOptFPic = toFlag True, | ||
| ghcOptDynLinkMode = toFlag GhcDynamicOnly | ||
| } | ||
| opts | needProfiling = profCxxOpts | ||
| | needDynamic = sharedCxxOpts | ||
| | otherwise = vanillaCxxOpts | ||
| -- TODO: Placing all Haskell, C, & C++ objects in a single directory | ||
| -- Has the potential for file collisions. In general we would | ||
| -- consider this a user error. However, we should strive to | ||
| -- add a warning if this occurs. | ||
| odir = fromFlag (ghcOptObjDir opts) | ||
| createDirectoryIfMissingVerbose verbosity True odir | ||
| needsRecomp <- checkNeedsRecompilation filename opts | ||
| when needsRecomp $ | ||
| runGhcProg opts | ||
| | filename <- cxxSrcs ] | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might be personal taste, but is this nicer than
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, never mind. I see it's patterned on the code below. Best to keep them obviously parallel. |
||
| -- build any C sources | ||
| unless (null cSrcs) $ do | ||
| info verbosity "Building C Sources..." | ||
|
|
@@ -1757,6 +1837,7 @@ installLib verbosity lbi targetDir dynlibTargetDir _builtDir _pkg lib clbi = do | |
|
|
||
| hasLib = not $ null (allLibModules lib clbi) | ||
| && null (cSources (libBuildInfo lib)) | ||
| && null (cxxSources (libBuildInfo lib)) | ||
| has_code = not (componentIsIndefinite clbi) | ||
| whenHasCode = when has_code | ||
| whenVanilla = when (hasLib && withVanillaLib lbi) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cabal/tests/ParserTestshas some tests for warnings fromcheck, which you might want to add to.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the following test files to ensure that the check provides correct warnings:
regressions/cc-options-with-optimizationregressions/cxx-options-with-optimization