File tree Expand file tree Collapse file tree 11 files changed +121
-2
lines changed
Cabal/src/Distribution/Simple
cabal-testsuite/PackageTests/CCompilerOverride Expand file tree Collapse file tree 11 files changed +121
-2
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 1+ {-# LANGUAGE ForeignFunctionInterface #-}
2+
3+ module Main (main ) where
4+
5+ foreign import ccall " foo" foo :: Int -> Int
6+
7+ main :: IO ()
8+ main = do
9+ let x = foo 0
10+ y = x
11+ let x = y
12+ print x
13+ pure ()
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ if which cc > /dev/null 2>&1 ; then
4+ cc -DNOERROR6 " ${@ } "
5+ elif which gcc > /dev/null 2>&1 ; then
6+ gcc -DNOERROR6 " ${@ } "
7+ elif which clang > /dev/null 2>&1 ; then
8+ clang -DNOERROR6 " ${@ } "
9+ else
10+ echo " Cannot find C compiler" >&2
11+ exit 1
12+ fi
13+
Original file line number Diff line number Diff line change 1+ @ echo OFF
2+
3+ where /q gcc.exe
4+
5+ IF %ERRORLEVEL% EQU 0 (
6+ call gcc.exe -DNOERROR6 %*
7+ EXIT /B %ERRORLEVEL%
8+ )
9+
10+ ECHO " Cannot find C compiler"
11+ EXIT /B 1
Original file line number Diff line number Diff line change 1+
2+ #ifndef NOERROR1
3+ #error "NOERROR1 was not passed"
4+ #endif
5+
6+ #ifndef NOERROR2
7+ #error "NOERROR2 was not passed"
8+ #endif
9+
10+ #ifndef NOERROR3
11+ #error "NOERROR3 was not passed"
12+ #endif
13+
14+ #ifndef NOERROR4
15+ #error "NOERROR4 was not passed"
16+ #endif
17+
18+ #ifndef NOERROR5
19+ #error "NOERROR5 was not passed"
20+ #endif
21+
22+ #ifndef NOERROR6
23+ #error "NOERROR6 was not passed"
24+ #endif
25+
26+ int foo (int x ) {
27+ return x + 42 ;
28+ }
Original file line number Diff line number Diff line change 1+ name : my
2+ version : 0.1
3+ license : BSD3
4+ cabal-version : >= 1.10
5+ build-type : Simple
6+
7+ executable foo
8+ default-language : Haskell2010
9+ main-is : Main.hs
10+ c-sources : foo.c
11+ build-depends : base
12+ ghc-options : -DNOERROR4
13+ cc-options : -DNOERROR5 -march=native
Original file line number Diff line number Diff line change 1+ # Setup configure
2+ Configuring my-0.1...
3+ Warning: Instead of 'ghc-options: -DNOERROR4' use 'cpp-options: -DNOERROR4'
4+ # Setup build
Original file line number Diff line number Diff line change 1+ # Setup configure
2+ Configuring my-0.1...
3+ Warning: Instead of 'ghc-options: -DNOERROR4' use 'cpp-options: -DNOERROR4'
4+ # Setup build
Original file line number Diff line number Diff line change 1+ import Test.Cabal.Prelude
2+
3+ -- Test that all the respective defines -DNOERROR... specified in variosu ways
4+ -- all end up routed to the C compiler. Otherwise the C file we depend on will
5+ -- not compile.
6+ main = setupAndCabalTest $ do
7+ skipUnlessGhcVersion " >= 8.8"
8+ isWin <- isWindows
9+ env <- getTestEnv
10+ let pwd = testCurrentDir env
11+ customCC = pwd ++ " /custom-cc" ++ if isWin then " .bat" else " "
12+
13+ setup " configure"
14+ [ " --ghc-option=-DNOERROR1"
15+ , " --ghc-option=-optc=-DNOERROR2"
16+ , " --ghc-option=-optP=-DNOERROR3"
17+ , " --with-gcc=" ++ customCC
18+ ]
19+ setup " build" [" -v2" ]
You can’t perform that action at this time.
0 commit comments