Skip to content
Snippets Groups Projects
Commit b4c99ac2 authored by Rodrigo Mesquita's avatar Rodrigo Mesquita :seedling:
Browse files

Add test for C source depending on Haskell C stub

parent 72a91600
No related branches found
No related tags found
No related merge requests found
{-# 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
{-# 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)
# cabal v2-build
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- csourcedepsstub-0.1 (lib) (first run)
- csourcedepsstub-0.1 (exe:csourcedeps-exe) (first run)
Configuring library for csourcedepsstub-0.1...
Preprocessing library for csourcedepsstub-0.1...
Building library for csourcedepsstub-0.1...
Configuring executable 'csourcedeps-exe' for csourcedepsstub-0.1...
Preprocessing executable 'csourcedeps-exe' for csourcedepsstub-0.1...
Building executable 'csourcedeps-exe' for csourcedepsstub-0.1...
packages: .
-- 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" []
#include "Lib_stub.h"
int meaning_of_life_c() {
return hello();
}
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment