Skip to content

Commit 7e46d03

Browse files
authored
Merge pull request #7900 from sergv/add-test-for-cc-override
Update #7874: Add test, fix changelog
2 parents 2ae46a3 + f45d4fe commit 7e46d03

File tree

11 files changed

+121
-2
lines changed

11 files changed

+121
-2
lines changed

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
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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 ()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Setup configure
2+
Configuring my-0.1...
3+
Warning: Instead of 'ghc-options: -DNOERROR4' use 'cpp-options: -DNOERROR4'
4+
# Setup build
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Setup configure
2+
Configuring my-0.1...
3+
Warning: Instead of 'ghc-options: -DNOERROR4' use 'cpp-options: -DNOERROR4'
4+
# Setup build
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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"]

0 commit comments

Comments
 (0)