-
Notifications
You must be signed in to change notification settings - Fork 696
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9639 from haskell/mergify/bp/3.10/pr-9554
Add extraLibDirs to runtime lib search paths of library (backport #9554)
- Loading branch information
Showing
8 changed files
with
100 additions
and
2 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
3 changes: 3 additions & 0 deletions
3
cabal-testsuite/PackageTests/LinkerOptions/T7339/T19350.script
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,3 @@ | ||
import Hello | ||
hello | ||
:q |
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 @@ | ||
#include <stdio.h> | ||
|
||
void hello_world(void) { | ||
printf("hello world!"); | ||
} | ||
|
3 changes: 3 additions & 0 deletions
3
cabal-testsuite/PackageTests/LinkerOptions/T7339/lib/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,3 @@ | ||
module Hello (hello) where | ||
|
||
foreign import ccall "hello_world" hello :: IO () |
2 changes: 2 additions & 0 deletions
2
cabal-testsuite/PackageTests/LinkerOptions/T7339/lib/Setup.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,2 @@ | ||
import Distribution.Simple | ||
main = defaultMain |
11 changes: 11 additions & 0 deletions
11
cabal-testsuite/PackageTests/LinkerOptions/T7339/lib/T7339.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,11 @@ | ||
cabal-version: >=1.10 | ||
name: T7339 | ||
version: 1.0 | ||
build-type: Simple | ||
|
||
library | ||
build-depends: base | ||
exposed-modules: Hello | ||
default-language: Haskell2010 | ||
extra-libraries: hello | ||
|
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 @@ | ||
# Setup configure | ||
# Setup build | ||
Preprocessing library for T7339-1.0.. | ||
Building library for T7339-1.0.. | ||
# Setup register | ||
Registering library for T7339-1.0.. |
67 changes: 67 additions & 0 deletions
67
cabal-testsuite/PackageTests/LinkerOptions/T7339/setup.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,67 @@ | ||
-- Test for #19350, #7339 originally by @bgamari | ||
-- ============================================= | ||
-- | ||
-- The plan | ||
-- --------- | ||
-- We build a C shared library (`libhello`, contained in ./clib) and then build | ||
-- a Haskell library (`T19350-lib`, in ./lib) which depends upon it via `foreign | ||
-- import`. We make sure that the libhello shared object can only be found via | ||
-- the extra-lib-dirs from the package database registration (which we do by | ||
-- moving libhello.so from its original place). | ||
-- | ||
-- Finally, we enter GHCi, load the Haskell library, and try to use it to call | ||
-- into libhello. | ||
|
||
import System.Directory | ||
import Distribution.System | ||
import Test.Cabal.Prelude | ||
|
||
|
||
main = setupTest $ do | ||
|
||
skipIfWindows | ||
skipUnlessGhcVersion ">= 8.4" | ||
|
||
withPackageDb $ do | ||
cwd <- takeDirectory . testCurrentDir <$> getTestEnv | ||
plat <- testPlatform <$> getTestEnv | ||
let libExt = case plat of | ||
Platform _ OSX -> "dylib" | ||
Platform _ Windows -> "dll" | ||
Platform _ _other -> "so" | ||
|
||
|
||
-- Link a C program against the library | ||
_ <- runProgramM ghcProgram | ||
[ "-fPIC", "-c", "clib/lib.c" | ||
, "-o", "clib/lib.o" ] | ||
Nothing | ||
_ <- runProgramM ghcProgram | ||
[ "-shared", "-no-hs-main", "clib/lib.o" | ||
, "-o", "clib/libhello" <.> libExt ] | ||
Nothing | ||
|
||
withDirectory "lib" $ do | ||
setup "configure" ["-v0" | ||
, "--extra-lib-dirs=" ++ (cwd </> "clib") | ||
, "--extra-lib-dirs=" ++ (cwd </> "clib-install") | ||
, "--disable-library-vanilla" | ||
, "--enable-shared"] | ||
setup "build" [] | ||
setup "register" ["--inplace"] | ||
|
||
-- Move libhello from its original place to ensure it isn't found via RPATH | ||
liftIO $ do | ||
createDirectoryIfMissing False (cwd </> "clib-install") | ||
copyFile (cwd </> "clib/libhello" <.> libExt) ( cwd </> "clib-install/libhello" <.> libExt) | ||
removeFile (cwd </> "clib/libhello" <.> libExt) | ||
|
||
pkgDb <- testPackageDbDir <$> getTestEnv | ||
ghciScript <- liftIO $ readFile (cwd </> "T19350.script") | ||
_ <- runProgramM ghcProgram | ||
[ "--interactive" | ||
, "-package", "T7339" | ||
, "-package-db", pkgDb | ||
] (Just ghciScript) | ||
|
||
return () |