@@ -705,35 +705,45 @@ buildOrReplLib mReplFlags verbosity numJobs pkg_descr lbi lib clbi = do
705
705
| filename <- cxxSources libBi]
706
706
707
707
-- build any C sources
708
- unless (not has_code || null (cSources libBi)) $ do
708
+ let (cSrcs', others) = partition (\ filepath -> " .c" `isSuffixOf` filepath) (cSources libBi)
709
+ unless (not has_code || null cSrcs') $ do
709
710
info verbosity " Building C Sources..."
710
- sequence_
711
- [ do let baseCcOpts = Internal. componentCcGhcOptions verbosity implInfo
712
- lbi libBi clbi relLibTargetDir filename
713
- vanillaCcOpts = if isGhcDynamic
714
- -- Dynamic GHC requires C sources to be built
715
- -- with -fPIC for REPL to work. See #2207.
716
- then baseCcOpts { ghcOptFPic = toFlag True }
717
- else baseCcOpts
718
- profCcOpts = vanillaCcOpts `mappend` mempty {
719
- ghcOptProfilingMode = toFlag True ,
720
- ghcOptObjSuffix = toFlag " p_o"
721
- }
722
- sharedCcOpts = vanillaCcOpts `mappend` mempty {
723
- ghcOptFPic = toFlag True ,
724
- ghcOptDynLinkMode = toFlag GhcDynamicOnly ,
725
- ghcOptObjSuffix = toFlag " dyn_o"
726
- }
727
- odir = fromFlag (ghcOptObjDir vanillaCcOpts)
728
- createDirectoryIfMissingVerbose verbosity True odir
729
- let runGhcProgIfNeeded ccOpts = do
730
- needsRecomp <- checkNeedsRecompilation filename ccOpts
731
- when needsRecomp $ runGhcProg ccOpts
732
- runGhcProgIfNeeded vanillaCcOpts
733
- unless forRepl $
734
- whenSharedLib forceSharedLib (runGhcProgIfNeeded sharedCcOpts)
735
- unless forRepl $ whenProfLib (runGhcProgIfNeeded profCcOpts)
736
- | filename <- cSources libBi]
711
+ unless (null others) $ do
712
+ let files = intercalate " , " others
713
+ let libraryName = case libName lib of
714
+ LMainLibName -> " the main library"
715
+ LSubLibName name -> " library " <> prettyShow name
716
+ warn verbosity $ unlines
717
+ [ " The following files listed in " <> libraryName <> " 's c-sources will not be used: " <> files <> " ."
718
+ , " Header files should be in the 'include' or 'install-include' stanza."
719
+ , " See https://cabal.readthedocs.io/en/3.10/cabal-package.html#pkg-field-includes"
720
+ ]
721
+ forM_ cSrcs' $ \ filename -> do
722
+ let baseCcOpts = Internal. componentCcGhcOptions verbosity implInfo
723
+ lbi libBi clbi relLibTargetDir filename
724
+ vanillaCcOpts = if isGhcDynamic
725
+ -- Dynamic GHC requires C sources to be built
726
+ -- with -fPIC for REPL to work. See #2207.
727
+ then baseCcOpts { ghcOptFPic = toFlag True }
728
+ else baseCcOpts
729
+ profCcOpts = vanillaCcOpts `mappend` mempty {
730
+ ghcOptProfilingMode = toFlag True ,
731
+ ghcOptObjSuffix = toFlag " p_o"
732
+ }
733
+ sharedCcOpts = vanillaCcOpts `mappend` mempty {
734
+ ghcOptFPic = toFlag True ,
735
+ ghcOptDynLinkMode = toFlag GhcDynamicOnly ,
736
+ ghcOptObjSuffix = toFlag " dyn_o"
737
+ }
738
+ odir = fromFlag (ghcOptObjDir vanillaCcOpts)
739
+ createDirectoryIfMissingVerbose verbosity True odir
740
+ let runGhcProgIfNeeded ccOpts = do
741
+ needsRecomp <- checkNeedsRecompilation filename ccOpts
742
+ when needsRecomp $ runGhcProg ccOpts
743
+ runGhcProgIfNeeded vanillaCcOpts
744
+ unless forRepl $
745
+ whenSharedLib forceSharedLib (runGhcProgIfNeeded sharedCcOpts)
746
+ unless forRepl $ whenProfLib (runGhcProgIfNeeded profCcOpts)
737
747
738
748
-- build any JS sources
739
749
unless (not has_code || not hasJsSupport || null (jsSources libBi)) $ do
@@ -1527,32 +1537,40 @@ gbuild verbosity numJobs pkg_descr lbi bm clbi = do
1527
1537
| filename <- cxxSrcs ]
1528
1538
1529
1539
-- build any C sources
1530
- unless (null cSrcs) $ do
1531
- info verbosity " Building C Sources..."
1532
- sequence_
1533
- [ do let baseCcOpts = Internal. componentCcGhcOptions verbosity implInfo
1540
+ let (cSrcs', others) = partition (\ filepath -> " .c" `isSuffixOf` filepath) cSrcs
1541
+ unless (null cSrcs') $ do
1542
+ info verbosity " Building C Sources..."
1543
+ unless (null others) $ do
1544
+ let files = intercalate " , " others
1545
+ let currentComponentName = gbuildName bm
1546
+ warn verbosity $ unlines
1547
+ [ " The following files listed in " <> currentComponentName <> " 's c-sources will not be used: " <> files <> " ."
1548
+ , " Header files should be in the 'include' or 'install-include' stanza."
1549
+ , " See https://cabal.readthedocs.io/en/3.10/cabal-package.html#pkg-field-includes"
1550
+ ]
1551
+ forM_ cSrcs' $ \ filename -> do
1552
+ let baseCcOpts = Internal. componentCcGhcOptions verbosity implInfo
1534
1553
lbi bnfo clbi tmpDir filename
1535
- vanillaCcOpts = if isGhcDynamic
1536
- -- Dynamic GHC requires C sources to be built
1537
- -- with -fPIC for REPL to work. See #2207.
1538
- then baseCcOpts { ghcOptFPic = toFlag True }
1539
- else baseCcOpts
1540
- profCcOpts = vanillaCcOpts `mappend` mempty {
1541
- ghcOptProfilingMode = toFlag True
1542
- }
1543
- sharedCcOpts = vanillaCcOpts `mappend` mempty {
1544
- ghcOptFPic = toFlag True ,
1545
- ghcOptDynLinkMode = toFlag GhcDynamicOnly
1546
- }
1547
- opts | needProfiling = profCcOpts
1548
- | needDynamic = sharedCcOpts
1549
- | otherwise = vanillaCcOpts
1550
- odir = fromFlag (ghcOptObjDir opts)
1551
- createDirectoryIfMissingVerbose verbosity True odir
1552
- needsRecomp <- checkNeedsRecompilation filename opts
1553
- when needsRecomp $
1554
- runGhcProg opts
1555
- | filename <- cSrcs ]
1554
+ let vanillaCcOpts = if isGhcDynamic
1555
+ -- Dynamic GHC requires C sources to be built
1556
+ -- with -fPIC for REPL to work. See #2207.
1557
+ then baseCcOpts { ghcOptFPic = toFlag True }
1558
+ else baseCcOpts
1559
+ let profCcOpts = vanillaCcOpts `mappend` mempty {
1560
+ ghcOptProfilingMode = toFlag True
1561
+ }
1562
+ let sharedCcOpts = vanillaCcOpts `mappend` mempty {
1563
+ ghcOptFPic = toFlag True ,
1564
+ ghcOptDynLinkMode = toFlag GhcDynamicOnly
1565
+ }
1566
+ let opts | needProfiling = profCcOpts
1567
+ | needDynamic = sharedCcOpts
1568
+ | otherwise = vanillaCcOpts
1569
+ let odir = fromFlag (ghcOptObjDir opts)
1570
+ createDirectoryIfMissingVerbose verbosity True odir
1571
+ needsRecomp <- checkNeedsRecompilation filename opts
1572
+ when needsRecomp $
1573
+ runGhcProg opts
1556
1574
1557
1575
-- TODO: problem here is we need the .c files built first, so we can load them
1558
1576
-- with ghci, but .c files can depend on .h files generated by ghc by ffi
0 commit comments