1 -- Test for #19350, #7339 originally by @bgamari
2 -- =============================================
6 -- We build a C shared library (`libhello`, contained in ./clib) and then build
7 -- a Haskell library (`T19350-lib`, in ./lib) which depends upon it via `foreign
8 -- import`. We make sure that the libhello shared object can only be found via
9 -- the extra-lib-dirs from the package database registration (which we do by
10 -- moving libhello.so from its original place).
12 -- Finally, we enter GHCi, load the Haskell library, and try to use it to call
15 import System
.Directory
16 import Distribution
.System
17 import Test
.Cabal
.Prelude
21 skipIfNoSharedLibraries
22 skipUnlessGhcVersion
">= 8.4"
25 cwd
<- takeDirectory
. testCurrentDir
<$> getTestEnv
26 plat
<- testPlatform
<$> getTestEnv
27 let libExt
= case plat
of
28 Platform _ OSX
-> "dylib"
29 Platform _ Windows
-> "dll"
30 Platform _ _other
-> "so"
33 -- Link a C program against the library
34 _
<- runProgramM ghcProgram
35 [ "-fPIC", "-c", "clib/lib.c"
36 , "-o", "clib/lib.o" ]
38 _
<- runProgramM ghcProgram
39 [ "-shared", "-no-hs-main", "clib/lib.o"
40 , "-o", "clib/libhello" <.> libExt
]
43 withDirectory
"lib" $ do
44 setup
"configure" ["-v0"
45 , "--extra-lib-dirs=" ++ (cwd
</> "clib")
46 , "--extra-lib-dirs=" ++ (cwd
</> "clib-install")
47 , "--disable-library-vanilla"
50 setup
"register" ["--inplace"]
52 -- Move libhello from its original place to ensure it isn't found via RPATH
54 createDirectoryIfMissing
False (cwd
</> "clib-install")
55 copyFile
(cwd
</> "clib/libhello" <.> libExt
) ( cwd
</> "clib-install/libhello" <.> libExt
)
56 removeFile (cwd
</> "clib/libhello" <.> libExt
)
58 pkgDb
<- testPackageDbDir
<$> getTestEnv
59 ghciScript
<- liftIO
$ readFile (cwd
</> "T19350.script")
60 _
<- runProgramM ghcProgram
63 , "-package-db", pkgDb