on master help sign in
Make libffi support a cabal flag

It has quite a specific use at the minute and can make installation a bit awkward, so this means it's not required for installation.

commitee06cf1ce445f5dd3e68c2c6734431f4a64366f9 authorEdwin Brady <ecb10@st-andrews.ac.uk> dateThu 31 Oct 2013, 20:47 (13 years ago) parentb7b55b7
3 files changed+33−2
idris.cabal+9−1 src/Core/Execute.hs+9−1 src/Util/DynamicLinker.hs+15
idris.cabal+9−1
@@ -289,6 +289,11 @@ Flag LLVM
289289 Default: True
290290 manual: True
291291
292+Flag FFI
293+ Description: Build support for libffi
294+ Default: True
295+ manual: True
296+
292297Executable idris
293298 Main-is: Main.hs
294299 hs-source-dirs: src
@@ -381,7 +386,6 @@ Executable idris
381386 , filepath
382387 , haskeline >= 0.7
383388 , language-java >= 0.2.2
384− , libffi
385389 , mtl
386390 , parsec >= 3
387391 , parsers == 0.9
@@ -422,3 +426,7 @@ Executable idris
422426 , llvm-general-pure == 3.3.8.*
423427 else
424428 other-modules: Util.LLVMStubs
429+ if flag(FFI)
430+ build-depends: libffi
431+ cpp-options: -DIDRIS_FFI
432+
src/Core/Execute.hs+9−1
@@ -1,4 +1,4 @@
1−{-# LANGUAGE PatternGuards, ExistentialQuantification #-}
1+{-# LANGUAGE PatternGuards, ExistentialQuantification, CPP #-}
22module Core.Execute (execute) where
33
44import Idris.AbsSyntax
@@ -25,13 +25,19 @@ import Data.Maybe
2525import Data.Bits
2626import qualified Data.Map as M
2727
28+#ifdef IDRIS_FFI
2829import Foreign.LibFFI
2930import Foreign.C.String
3031import Foreign.Marshal.Alloc (free)
3132import Foreign.Ptr
33+#endif
3234
3335import System.IO
3436
37+#ifndef IDRIS_FFI
38+execute :: Term -> Idris Term
39+execute tm = fail "libffi not supported, rebuild Idris with -f FFI"
40+#else -- rest of file
3541readMay :: (Read a) => String -> Maybe a
3642readMay s = case reads s of
3743 [(x, "")] -> Just x
@@ -529,3 +535,5 @@ findForeign fn = do est <- getExecState
529535 show (length fs) ++ " occurrences."
530536 return Nothing
531537 where getFn lib = execIO $ catchIO (tryLoadFn fn lib) (\_ -> return Nothing)
538+
539+#endif
src/Util/DynamicLinker.hs+15
@@ -3,6 +3,7 @@
33{-# LANGUAGE ExistentialQuantification, CPP #-}
44module Util.DynamicLinker where
55
6+#ifdef IDRIS_FFI
67import Foreign.LibFFI
78import Foreign.Ptr (nullPtr, FunPtr, nullFunPtr,castPtrToFunPtr)
89import System.Directory
@@ -69,3 +70,17 @@ tryLoadFn fn (Lib _ h) = do cFn <- getProcAddress h fn
6970 then return Nothing
7071 else return . Just $ Fun fn (castPtrToFunPtr cFn)
7172#endif
73+#else -- no libffi, just add stubbs.
74+
75+data DynamicLib = Lib { lib_name :: String
76+ , lib_handle :: ()
77+ }
78+ deriving Eq
79+
80+tryLoadLib :: String -> IO (Maybe DynamicLib)
81+tryLoadLib _ = return Nothing
82+
83+
84+#endif
85+
86+