From 1259167ae86e02566219ae11bc83bd4ce6797b10 Mon Sep 17 00:00:00 2001 From: Lloyd Cunningham Date: Tue, 17 Jul 2018 15:43:29 -0500 Subject: [PATCH] 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 --- Cabal/ChangeLog.md | 2 ++ Cabal/Distribution/Simple/GHC/Internal.hs | 10 ++++++++-- Cabal/Distribution/Simple/Program/GHC.hs | 4 ++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Cabal/ChangeLog.md b/Cabal/ChangeLog.md index 25043ca6603..f21524b14ae 100644 --- a/Cabal/ChangeLog.md +++ b/Cabal/ChangeLog.md @@ -70,6 +70,8 @@ ([#5386](https://github.com/haskell/cabal/issues/5386)). * `Distribution.PackageDescription.Check.checkPackageFiles` now accepts a `Verbosity` argument. + * `ghc-options` and `--with-gcc` are now passed to GHC when compiling + C and C++ sources ([#4439](https://github.com/haskell/cabal/issues/4439)). ---- diff --git a/Cabal/Distribution/Simple/GHC/Internal.hs b/Cabal/Distribution/Simple/GHC/Internal.hs index 118d551372e..a02864a5328 100644 --- a/Cabal/Distribution/Simple/GHC/Internal.hs +++ b/Cabal/Distribution/Simple/GHC/Internal.hs @@ -293,7 +293,10 @@ componentCcGhcOptions verbosity _implInfo lbi bi clbi odir filename = NormalDebugInfo -> ["-g"] MaximalDebugInfo -> ["-g3"]) ++ PD.ccOptions bi, - ghcOptObjDir = toFlag odir + ghcOptCcProgram = maybeToFlag $ programPath <$> + lookupProgram gccProgram (withPrograms lbi), + ghcOptObjDir = toFlag odir, + ghcOptExtra = hcOptions GHC bi } @@ -329,7 +332,10 @@ componentCxxGhcOptions verbosity _implInfo lbi bi clbi odir filename = NormalDebugInfo -> ["-g"] MaximalDebugInfo -> ["-g3"]) ++ PD.cxxOptions bi, - ghcOptObjDir = toFlag odir + ghcOptCcProgram = maybeToFlag $ programPath <$> + lookupProgram gccProgram (withPrograms lbi), + ghcOptObjDir = toFlag odir, + ghcOptExtra = hcOptions GHC bi } diff --git a/Cabal/Distribution/Simple/Program/GHC.hs b/Cabal/Distribution/Simple/Program/GHC.hs index 8d8c052968a..e3ab0a215dd 100644 --- a/Cabal/Distribution/Simple/Program/GHC.hs +++ b/Cabal/Distribution/Simple/Program/GHC.hs @@ -355,6 +355,9 @@ data GhcOptions = GhcOptions { -- | Extra header files to include for old-style FFI; the @ghc -#include@ flag. ghcOptFfiIncludes :: NubListR FilePath, + -- | Program to use for the C and C++ compiler; the @ghc -pgmc@ flag. + ghcOptCcProgram :: Flag FilePath, + ---------------------------- -- Language and extensions @@ -595,6 +598,7 @@ renderGhcOptions comp _platform@(Platform _arch os) opts | inc <- flags ghcOptCppIncludes ] , [ "-optc" ++ opt | opt <- ghcOptCcOptions opts] , [ "-optc" ++ opt | opt <- ghcOptCxxOptions opts] + , concat [ ["-pgmc", cc] | cc <- flag ghcOptCcProgram ] ----------------- -- Linker stuff