Skip to content
Snippets Groups Projects
Unverified Commit 1861eff7 authored by Ben Gamari's avatar Ben Gamari Committed by Zubin
Browse files

hadrian: Clean up handling of libffi dependencies

(cherry picked from commit b2721819)
parent df3dc72c
No related branches found
No related tags found
No related merge requests found
......@@ -199,6 +199,15 @@ outputLlvm logger dflags filenm cmm_stream =
************************************************************************
-}
{-
Note [Packaging libffi headers]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The C code emitted by GHC for libffi adjustors must depend upon the ffi_arg type,
defined in <ffi.h>. For this reason, we must ensure that <ffi.h> is available
in binary distributions. To do so, we install these headers as part of the
`rts` package.
-}
outputForeignStubs
:: Logger
-> TmpFs
......
......@@ -95,6 +95,9 @@ libffiName' dynamic = (if dynamic then "" else "C")
libffiLibrary :: FilePath
libffiLibrary = "inst/lib/libffi.a"
-- | These are the headers that we must package with GHC since foreign export
-- adjustor code produced by GHC depends upon them.
-- See Note [Packaging libffi headers] in GHC.Driver.CodeOutput.
libffiHeaderFiles :: [FilePath]
libffiHeaderFiles = ["ffi.h", "ffitarget.h"]
......
......@@ -26,6 +26,7 @@ rtsRules = priority 3 $ do
let buildPath = root -/- buildDir (rtsContext stage)
-- Header files
-- See Note [Packaging libffi headers] in GHC.Driver.CodeOutput.
(fmap (buildPath -/-) libffiHeaderFiles) &%> const (copyLibffiHeaders stage)
-- Static libraries.
......@@ -43,6 +44,7 @@ withLibffi stage action = needLibffi stage
-- | Copy all header files wither from the system libffi or from the libffi
-- build dir to the rts build dir.
-- See Note [Packaging libffi headers] in GHC.Driver.CodeOutput.
copyLibffiHeaders :: Stage -> Action ()
copyLibffiHeaders stage = do
rtsPath <- rtsBuildPath stage
......
......@@ -24,6 +24,8 @@ packageArgs = do
cursesIncludeDir <- getSetting CursesIncludeDir
cursesLibraryDir <- getSetting CursesLibDir
ffiIncludeDir <- getSetting FfiIncludeDir
ffiLibraryDir <- getSetting FfiLibDir
mconcat
--------------------------------- base ---------------------------------
......@@ -132,7 +134,8 @@ packageArgs = do
-- the Stage1 libraries, as we already know that the bootstrap
-- compiler comes with the same versions as the one we are building.
--
builder (Cabal Flags) ? ifM stage0
builder (Cabal Setup) ? cabalExtraDirs ffiIncludeDir ffiLibraryDir
, builder (Cabal Flags) ? ifM stage0
(andM [cross, bootCross] `cabalFlag` "internal-interpreter")
(arg "internal-interpreter")
......@@ -250,7 +253,6 @@ rtsPackageArgs = package rts ? do
path <- getBuildPath
top <- expr topDirectory
useSystemFfi <- expr $ flag UseSystemFfi
libffiName <- expr libffiLibraryName
ffiIncludeDir <- getSetting FfiIncludeDir
ffiLibraryDir <- getSetting FfiLibDir
libdwIncludeDir <- getSetting LibdwIncludeDir
......@@ -277,8 +279,6 @@ rtsPackageArgs = package rts ? do
let cArgs = mconcat
[ rtsWarnings
, flag UseSystemFfi ? not (null ffiIncludeDir) ? arg ("-I" ++ ffiIncludeDir)
, flag WithLibdw ? not (null libdwIncludeDir) ? arg ("-I" ++ libdwIncludeDir)
, arg "-fomit-frame-pointer"
-- RTS *must* be compiled with optimisations. The INLINE_HEADER macro
-- requires that functions are inlined to work as expected. Inlining
......@@ -372,6 +372,7 @@ rtsPackageArgs = package rts ? do
, builder (Cabal Setup) ? mconcat
[ cabalExtraDirs libdwIncludeDir libdwLibraryDir
, cabalExtraDirs libnumaIncludeDir libnumaLibraryDir
, useSystemFfi ? cabalExtraDirs ffiIncludeDir ffiLibraryDir
]
, builder (Cc FindCDependencies) ? cArgs
, builder (Ghc CompileCWithGhc) ? map ("-optc" ++) <$> cArgs
......@@ -379,11 +380,7 @@ rtsPackageArgs = package rts ? do
, builder Ghc ? ghcArgs
, builder HsCpp ? pure
[ "-DTOP=" ++ show top
, "-DFFI_INCLUDE_DIR=" ++ show ffiIncludeDir
, "-DFFI_LIB_DIR=" ++ show ffiLibraryDir
, "-DFFI_LIB=" ++ show libffiName
, "-DLIBDW_LIB_DIR=" ++ show libdwLibraryDir ]
[ "-DTOP=" ++ show top ]
, builder HsCpp ? flag WithLibdw ? arg "-DUSE_LIBDW"
, builder HsCpp ? flag HaveLibMingwEx ? arg "-DHAVE_LIBMINGWEX" ]
......
......@@ -58,8 +58,6 @@ library
GHCi.StaticPtrTable
GHCi.TH
include-dirs: @FFIIncludeDir@
exposed-modules:
GHCi.BreakArray
GHCi.BinaryArray
......
......@@ -151,7 +151,10 @@ library
install-includes: Cmm.h HsFFI.h MachDeps.h Rts.h RtsAPI.h Stg.h
ghcautoconf.h ghcconfig.h ghcplatform.h ghcversion.h
-- ^ from ../includes
DerivedConstants.h ffi.h ffitarget.h
DerivedConstants.h
ffi.h ffitarget.h
-- ^ see Note [Packaging libffi headers] in
-- GHC.Driver.CodeOutput.
-- ^ generated
rts/Adjustor.h
rts/ExecPage.h
......
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