forked from haskell/cabal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for C source depending on Haskell C stub
- Loading branch information
Showing
6 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
cabal-testsuite/PackageTests/FFI/CSourceDependsStub/Lib.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{-# LANGUAGE ForeignFunctionInterface #-} | ||
|
||
module Lib where | ||
|
||
import Foreign.C (CInt (..)) | ||
|
||
hello :: IO CInt | ||
hello = do | ||
putStrLn "hello!" | ||
return 11 | ||
|
||
foreign export ccall "hello" hello :: IO CInt | ||
|
16 changes: 16 additions & 0 deletions
16
cabal-testsuite/PackageTests/FFI/CSourceDependsStub/Main.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{-# LANGUAGE ForeignFunctionInterface #-} | ||
|
||
module Main where | ||
|
||
import Foreign.C (CInt (..)) | ||
|
||
foreign import ccall "meaning_of_life_c" | ||
meaning_of_life_c :: IO CInt | ||
|
||
main :: IO () | ||
main = do | ||
secret <- meaning_of_life_c | ||
-- The value 11 comes from the exported Lib.hello | ||
if (secret == 11) | ||
then putStrLn ("The secret is " ++ show secret) | ||
else error ("Expected value 11, got " ++ show secret) |
1 change: 1 addition & 0 deletions
1
cabal-testsuite/PackageTests/FFI/CSourceDependsStub/cabal.project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
packages: . |
6 changes: 6 additions & 0 deletions
6
cabal-testsuite/PackageTests/FFI/CSourceDependsStub/cabal.test.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
-- Tests whether an extra C source can depend on a _stub header generated by | ||
-- GHC compiling a Haskell module with a foreign export declaration | ||
|
||
import Test.Cabal.Prelude | ||
main = cabalTest $ do | ||
cabal "v2-build" [] |
5 changes: 5 additions & 0 deletions
5
cabal-testsuite/PackageTests/FFI/CSourceDependsStub/cbits/clib.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include "Lib_stub.h" | ||
|
||
int meaning_of_life_c() { | ||
return hello(); | ||
} |
16 changes: 16 additions & 0 deletions
16
cabal-testsuite/PackageTests/FFI/CSourceDependsStub/csourcedepsstub.cabal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
cabal-version: 2.2 | ||
name: csourcedepsstub | ||
version: 0.1 | ||
build-type: Simple | ||
|
||
library | ||
build-depends: base | ||
default-language: Haskell2010 | ||
include-dirs: cbits | ||
c-sources: cbits/clib.c | ||
exposed-modules: Lib | ||
|
||
executable csourcedeps-exe | ||
main-is: Main.hs | ||
build-depends: base, csourcedepsstub | ||
default-language: Haskell2010 |