Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Cabal/src/Distribution/Simple/GHC/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,10 @@ componentCcGhcOptions verbosity _implInfo lbi bi clbi odir filename =
NormalDebugInfo -> ["-g"]
MaximalDebugInfo -> ["-g3"]) ++
ccOptions bi,
ghcOptObjDir = toFlag odir
ghcOptCcProgram = maybeToFlag $ programPath <$>
lookupProgram gccProgram (withPrograms lbi),
ghcOptObjDir = toFlag odir,
ghcOptExtra = hcOptions GHC bi
}


Expand Down Expand Up @@ -337,7 +340,10 @@ componentCxxGhcOptions verbosity _implInfo lbi bi clbi odir filename =
NormalDebugInfo -> ["-g"]
MaximalDebugInfo -> ["-g3"]) ++
cxxOptions bi,
ghcOptObjDir = toFlag odir
ghcOptCcProgram = maybeToFlag $ programPath <$>
lookupProgram gccProgram (withPrograms lbi),
ghcOptObjDir = toFlag odir,
ghcOptExtra = hcOptions GHC bi
}


Expand Down
4 changes: 4 additions & 0 deletions Cabal/src/Distribution/Simple/Program/GHC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,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

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

-----------------
-- Linker stuff
Expand Down
13 changes: 13 additions & 0 deletions cabal-testsuite/PackageTests/CCompilerOverride/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{-# LANGUAGE ForeignFunctionInterface #-}

module Main (main) where

foreign import ccall "foo" foo :: Int -> Int

main :: IO ()
main = do
let x = foo 0
y = x
let x = y
print x
pure ()
13 changes: 13 additions & 0 deletions cabal-testsuite/PackageTests/CCompilerOverride/custom-cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

if which cc >/dev/null 2>&1; then
cc -DNOERROR6 "${@}"
elif which gcc >/dev/null 2>&1; then
gcc -DNOERROR6 "${@}"
elif which clang >/dev/null 2>&1; then
clang -DNOERROR6 "${@}"
else
echo "Cannot find C compiler" >&2
exit 1
fi

11 changes: 11 additions & 0 deletions cabal-testsuite/PackageTests/CCompilerOverride/custom-cc.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@echo OFF

where /q gcc.exe

IF %ERRORLEVEL% EQU 0 (
call gcc.exe -DNOERROR6 %*
EXIT /B %ERRORLEVEL%
)

ECHO "Cannot find C compiler"
EXIT /B 1
28 changes: 28 additions & 0 deletions cabal-testsuite/PackageTests/CCompilerOverride/foo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

#ifndef NOERROR1
#error "NOERROR1 was not passed"
#endif

#ifndef NOERROR2
#error "NOERROR2 was not passed"
#endif

#ifndef NOERROR3
#error "NOERROR3 was not passed"
#endif

#ifndef NOERROR4
#error "NOERROR4 was not passed"
#endif

#ifndef NOERROR5
#error "NOERROR5 was not passed"
#endif

#ifndef NOERROR6
#error "NOERROR6 was not passed"
#endif

int foo(int x) {
return x + 42;
}
13 changes: 13 additions & 0 deletions cabal-testsuite/PackageTests/CCompilerOverride/my.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: my
version: 0.1
license: BSD3
cabal-version: >= 1.10
build-type: Simple

executable foo
default-language: Haskell2010
main-is: Main.hs
c-sources: foo.c
build-depends: base
ghc-options: -DNOERROR4
cc-options: -DNOERROR5 -march=native
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Setup configure
Configuring my-0.1...
Warning: Instead of 'ghc-options: -DNOERROR4' use 'cpp-options: -DNOERROR4'
# Setup build
4 changes: 4 additions & 0 deletions cabal-testsuite/PackageTests/CCompilerOverride/setup.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Setup configure
Configuring my-0.1...
Warning: Instead of 'ghc-options: -DNOERROR4' use 'cpp-options: -DNOERROR4'
# Setup build
19 changes: 19 additions & 0 deletions cabal-testsuite/PackageTests/CCompilerOverride/setup.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Test.Cabal.Prelude

-- Test that all the respective defines -DNOERROR... specified in variosu ways
-- all end up routed to the C compiler. Otherwise the C file we depend on will
-- not compile.
main = setupAndCabalTest $ do
skipUnlessGhcVersion ">= 8.8"
isWin <- isWindows
env <- getTestEnv
let pwd = testCurrentDir env
customCC = pwd ++ "/custom-cc" ++ if isWin then ".bat" else ""

setup "configure"
[ "--ghc-option=-DNOERROR1"
, "--ghc-option=-optc=-DNOERROR2"
, "--ghc-option=-optP=-DNOERROR3"
, "--with-gcc=" ++ customCC
]
setup "build" ["-v2"]
4 changes: 4 additions & 0 deletions changelog.d/issue-4439
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
synopsis: `ghc-options` and `--with-gcc` are now passed to GHC when compiling C and C++ sources
packages: Cabal
issues: #4439
prs: #5440 #7874