forked from haskell/cabal
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu> Signed-off-by: Auke Booij <auke@tulcod.com>
- Loading branch information
Showing
11 changed files
with
188 additions
and
64 deletions.
There are no files selected for viewing
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
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
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
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
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,12 @@ | ||
. ./common.sh | ||
|
||
require_ghc_ge 708 | ||
|
||
cd T4049 | ||
cabal sandbox init > /dev/null | ||
cabal install --enable-shared > /dev/null | ||
$GHC -no-hs-main UseLib.c -o UseLib -lmyforeignlib -L"$PWD/.cabal-sandbox/lib" | ||
find "$PWD/.cabal-sandbox/" | ||
$PWD/UseLib | ||
DYLD_LIBRARY_PATH="$PWD/.cabal-sandbox/lib" $PWD/UseLib | ||
cabal exec "$PWD/UseLib" |
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,9 @@ | ||
#include <stdio.h> | ||
|
||
int main() | ||
{ | ||
myForeignLibInit(); | ||
sayHi(); | ||
myForeignLibExit(); | ||
return 0; | ||
} |
23 changes: 23 additions & 0 deletions
23
cabal-install/tests/IntegrationTests/exec/T4049/csrc/MyForeignLibWrapper.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,23 @@ | ||
#include <stdlib.h> | ||
#include "HsFFI.h" | ||
|
||
HsBool myForeignLibInit(void){ | ||
int argc = 2; | ||
char *argv[] = { "+RTS", "-A32m", NULL }; | ||
char **pargv = argv; | ||
|
||
// Initialize Haskell runtime | ||
hs_init(&argc, &pargv); | ||
|
||
// do any other initialization here and | ||
// return false if there was a problem | ||
return HS_BOOL_TRUE; | ||
} | ||
|
||
void myForeignLibExit(void){ | ||
hs_exit(); | ||
} | ||
|
||
int cFoo2() { | ||
return 1234; | ||
} |
19 changes: 19 additions & 0 deletions
19
cabal-install/tests/IntegrationTests/exec/T4049/my-foreign-lib.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,19 @@ | ||
name: my-foreign-lib | ||
version: 0.1.0.0 | ||
author: Edsko de Vries | ||
maintainer: edsko@well-typed.com | ||
build-type: Simple | ||
cabal-version: >=1.10 | ||
|
||
foreign-library myforeignlib | ||
type: native-shared | ||
|
||
if os(windows) | ||
options: standalone | ||
|
||
other-modules: MyForeignLib.Hello | ||
MyForeignLib.SomeBindings | ||
build-depends: base | ||
hs-source-dirs: src | ||
c-sources: csrc/MyForeignLibWrapper.c | ||
default-language: Haskell2010 |
10 changes: 10 additions & 0 deletions
10
cabal-install/tests/IntegrationTests/exec/T4049/src/MyForeignLib/Hello.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,10 @@ | ||
-- | Module with single foreign export | ||
module MyForeignLib.Hello (sayHi) where | ||
|
||
import MyForeignLib.SomeBindings | ||
|
||
foreign export ccall sayHi :: IO () | ||
|
||
-- | Say hi! | ||
sayHi :: IO () | ||
sayHi = putStrLn $ "Hi from a foreign library! Foo has value " ++ show valueOfFoo |
10 changes: 10 additions & 0 deletions
10
cabal-install/tests/IntegrationTests/exec/T4049/src/MyForeignLib/SomeBindings.hsc
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,10 @@ | ||
-- | Module that needs the hsc2hs preprocessor | ||
module MyForeignLib.SomeBindings where | ||
|
||
#define FOO 1 | ||
|
||
#ifdef FOO | ||
-- | Value guarded by a CPP flag | ||
valueOfFoo :: Int | ||
valueOfFoo = 5678 | ||
#endif |
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,92 @@ | ||
#!/bin/sh | ||
|
||
# ATTENTION! Before editing this file, maybe you can make a | ||
# separate script to do your test? We don't want individual | ||
# Travis builds to take too long (they time out at 50min and | ||
# it's generally unpleasant if the build takes that long.) | ||
# If you make a separate matrix entry in .travis.yml it can | ||
# be run in parallel. | ||
|
||
. ./travis-common.sh | ||
|
||
CABAL_STORE_DB="${HOME}/.cabal/store/ghc-${GHCVER}/package.db" | ||
CABAL_LOCAL_DB="${PWD}/dist-newstyle/packagedb/ghc-${GHCVER}" | ||
CABAL_BDIR="${PWD}/dist-newstyle/build/Cabal-${CABAL_VERSION}" | ||
CABAL_TESTSUITE_BDIR="${PWD}/dist-newstyle/build/cabal-testsuite-${CABAL_VERSION}" | ||
CABAL_INSTALL_BDIR="${PWD}/dist-newstyle/build/cabal-install-${CABAL_VERSION}" | ||
CABAL_INSTALL_SETUP="${CABAL_INSTALL_BDIR}/setup/setup" | ||
# --hide-successes uses terminal control characters which mess up | ||
# Travis's log viewer. So just print them all! | ||
TEST_OPTIONS="" | ||
|
||
# --------------------------------------------------------------------- | ||
# Update the Cabal index | ||
# --------------------------------------------------------------------- | ||
|
||
timed cabal update | ||
|
||
# --------------------------------------------------------------------- | ||
# Install happy if necessary | ||
# --------------------------------------------------------------------- | ||
|
||
if ! command -v happy; then | ||
timed cabal install happy | ||
fi | ||
|
||
# --------------------------------------------------------------------- | ||
# Setup our local project | ||
# --------------------------------------------------------------------- | ||
|
||
cp cabal.project.travis cabal.project.local | ||
|
||
# --------------------------------------------------------------------- | ||
# Cabal | ||
# --------------------------------------------------------------------- | ||
|
||
# Needed to work around some bugs in nix-local-build code. | ||
export CABAL_BUILDDIR="${CABAL_BDIR}" | ||
|
||
# NB: Best to do everything for a single package together as it's | ||
# more efficient (since new-build will uselessly try to rebuild | ||
# Cabal otherwise). | ||
if [ "x$PARSEC" = "xYES" ]; then | ||
timed cabal new-build -fparsec Cabal Cabal:unit-tests Cabal:parser-tests Cabal:parser-hackage-tests | ||
else | ||
timed cabal new-build Cabal | ||
fi | ||
|
||
unset CABAL_BUILDDIR | ||
|
||
# --------------------------------------------------------------------- | ||
# cabal-install | ||
# --------------------------------------------------------------------- | ||
|
||
# Needed to work around some bugs in nix-local-build code. | ||
export CABAL_BUILDDIR="${CABAL_INSTALL_BDIR}" | ||
|
||
timed cabal new-build cabal-install:cabal \ | ||
cabal-install:integration-tests \ | ||
cabal-install:integration-tests2 \ | ||
cabal-install:unit-tests \ | ||
cabal-install:solver-quickcheck | ||
|
||
# The integration-tests2 need the hackage index, and need it in the secure | ||
# format, which is not necessarily the default format of the bootstrap cabal. | ||
# If the format does match then this will be very quick. | ||
timed ${CABAL_INSTALL_BDIR}/build/cabal/cabal update | ||
|
||
# Run tests | ||
(cd cabal-install && timed ${CABAL_INSTALL_BDIR}/build/integration-tests/integration-tests $TEST_OPTIONS) || exit $? | ||
(cd cabal-install && timed ${CABAL_INSTALL_BDIR}/build/unit-tests/unit-tests $TEST_OPTIONS) || exit $? | ||
(cd cabal-install && timed ${CABAL_INSTALL_BDIR}/build/solver-quickcheck/solver-quickcheck $TEST_OPTIONS --quickcheck-tests=1000) || exit $? | ||
(cd cabal-install && timed ${CABAL_INSTALL_BDIR}/build/integration-tests2/integration-tests2 $TEST_OPTIONS) || exit $? | ||
|
||
# Haddock | ||
(cd cabal-install && timed ${CABAL_INSTALL_SETUP} haddock --builddir=${CABAL_INSTALL_BDIR} ) || exit $? | ||
|
||
(cd cabal-install && timed cabal check) || exit $? | ||
|
||
unset CABAL_BUILDDIR | ||
|
||
# Check what we got | ||
${CABAL_INSTALL_BDIR}/build/cabal/cabal --version |