on master help sign in
Make libffi support a cabal flag
ee06cf1Edwin Brady
idris.cabal+9−1
@@ -289,6 +289,11 @@ Flag LLVM
289 Default: True
289 Default: True
290 manual: True
290 manual: True
291
291
292+Flag FFI
293+ Description: Build support for libffi
294+ Default: True
295+ manual: True
296+
292Executable idris
297Executable idris
293 Main-is: Main.hs
298 Main-is: Main.hs
294 hs-source-dirs: src
299 hs-source-dirs: src
@@ -381,7 +386,6 @@ Executable idris
381 , filepath
386 , filepath
382 , haskeline >= 0.7
387 , haskeline >= 0.7
383 , language-java >= 0.2.2
388 , language-java >= 0.2.2
384− , libffi
385 , mtl
389 , mtl
386 , parsec >= 3
390 , parsec >= 3
387 , parsers == 0.9
391 , parsers == 0.9
@@ -422,3 +426,7 @@ Executable idris
422 , llvm-general-pure == 3.3.8.*
426 , llvm-general-pure == 3.3.8.*
423 else
427 else
424 other-modules: Util.LLVMStubs
428 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 #-}
2module Core.Execute (execute) where
2module Core.Execute (execute) where
3
3
4import Idris.AbsSyntax
4import Idris.AbsSyntax
@@ -25,13 +25,19 @@ import Data.Maybe
25import Data.Bits
25import Data.Bits
26import qualified Data.Map as M
26import qualified Data.Map as M
27
27
28+#ifdef IDRIS_FFI
28import Foreign.LibFFI
29import Foreign.LibFFI
29import Foreign.C.String
30import Foreign.C.String
30import Foreign.Marshal.Alloc (free)
31import Foreign.Marshal.Alloc (free)
31import Foreign.Ptr
32import Foreign.Ptr
33+#endif
32
34
33import System.IO
35import System.IO
34
36
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
35readMay :: (Read a) => String -> Maybe a
41readMay :: (Read a) => String -> Maybe a
36readMay s = case reads s of
42readMay s = case reads s of
37 [(x, "")] -> Just x
43 [(x, "")] -> Just x
@@ -529,3 +535,5 @@ findForeign fn = do est <- getExecState
529 show (length fs) ++ " occurrences."
535 show (length fs) ++ " occurrences."
530 return Nothing
536 return Nothing
531 where getFn lib = execIO $ catchIO (tryLoadFn fn lib) (\_ -> return Nothing)
537 where getFn lib = execIO $ catchIO (tryLoadFn fn lib) (\_ -> return Nothing)
538+
539+#endif
src/Util/DynamicLinker.hs+15
@@ -3,6 +3,7 @@
3{-# LANGUAGE ExistentialQuantification, CPP #-}
3{-# LANGUAGE ExistentialQuantification, CPP #-}
4module Util.DynamicLinker where
4module Util.DynamicLinker where
5
5
6+#ifdef IDRIS_FFI
6import Foreign.LibFFI
7import Foreign.LibFFI
7import Foreign.Ptr (nullPtr, FunPtr, nullFunPtr,castPtrToFunPtr)
8import Foreign.Ptr (nullPtr, FunPtr, nullFunPtr,castPtrToFunPtr)
8import System.Directory
9import System.Directory
@@ -69,3 +70,17 @@ tryLoadFn fn (Lib _ h) = do cFn <- getProcAddress h fn
69 then return Nothing
70 then return Nothing
70 else return . Just $ Fun fn (castPtrToFunPtr cFn)
71 else return . Just $ Fun fn (castPtrToFunPtr cFn)
71#endif
72#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+