Skip to content

Commit 25aa866

Browse files
syntheoremsergv
authored andcommitted
Respect ghc-options and with-gcc when compiling C sources
This fix allows users to override the C/C++ compiler, either by passing --with-gcc to configure or adding -pgmc to ghc-options in their Cabal file. Tested manually with a project using C++ sources that require a more recent version of clang than the default install (macOS). Inspected the output of `Setup.hs build -v` to confirm that the correct arguments are being passed to GHC when compiling the C++ sources. Resolves: #4439
1 parent 2ae46a3 commit 25aa866

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

Cabal/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@
215215
([#5431](https://github.com/haskell/cabal/pull/5431)).
216216
* Pass command line arguments to `hsc2hs` using response files when possible
217217
([#3122](https://github.com/haskell/cabal/issues/3122)).
218+
* `ghc-options` and `--with-gcc` are now passed to GHC when compiling
219+
C and C++ sources ([#4439](https://github.com/haskell/cabal/issues/4439)).
218220

219221
----
220222

Cabal/src/Distribution/Simple/GHC/Internal.hs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,10 @@ componentCcGhcOptions verbosity _implInfo lbi bi clbi odir filename =
301301
NormalDebugInfo -> ["-g"]
302302
MaximalDebugInfo -> ["-g3"]) ++
303303
ccOptions bi,
304-
ghcOptObjDir = toFlag odir
304+
ghcOptCcProgram = maybeToFlag $ programPath <$>
305+
lookupProgram gccProgram (withPrograms lbi),
306+
ghcOptObjDir = toFlag odir,
307+
ghcOptExtra = hcOptions GHC bi
305308
}
306309

307310

@@ -337,7 +340,10 @@ componentCxxGhcOptions verbosity _implInfo lbi bi clbi odir filename =
337340
NormalDebugInfo -> ["-g"]
338341
MaximalDebugInfo -> ["-g3"]) ++
339342
cxxOptions bi,
340-
ghcOptObjDir = toFlag odir
343+
ghcOptCcProgram = maybeToFlag $ programPath <$>
344+
lookupProgram gccProgram (withPrograms lbi),
345+
ghcOptObjDir = toFlag odir,
346+
ghcOptExtra = hcOptions GHC bi
341347
}
342348

343349

Cabal/src/Distribution/Simple/Program/GHC.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,9 @@ data GhcOptions = GhcOptions {
446446
-- | Extra header files to include for old-style FFI; the @ghc -#include@ flag.
447447
ghcOptFfiIncludes :: NubListR FilePath,
448448

449+
-- | Program to use for the C and C++ compiler; the @ghc -pgmc@ flag.
450+
ghcOptCcProgram :: Flag FilePath,
451+
449452
----------------------------
450453
-- Language and extensions
451454

@@ -691,6 +694,7 @@ renderGhcOptions comp _platform@(Platform _arch os) opts
691694
_ -> "-optc"
692695
in [ cxxflag ++ opt | opt <- ghcOptCxxOptions opts]
693696
, [ "-opta" ++ opt | opt <- ghcOptAsmOptions opts]
697+
, concat [ ["-pgmc", cc] | cc <- flag ghcOptCcProgram ]
694698

695699
-----------------
696700
-- Linker stuff

0 commit comments

Comments
 (0)