From 0fb6140304573f50299079d4c8334736b3f8f6f6 Mon Sep 17 00:00:00 2001 From: eagletmt Date: Sat, 24 Mar 2012 02:05:38 +0900 Subject: [PATCH] enable dynamic linking for FFI --- Cabal.hs | 22 ++++++++-------------- GHCApi.hs | 2 +- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/Cabal.hs b/Cabal.hs index 9433de4..bad0f36 100644 --- a/Cabal.hs +++ b/Cabal.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE OverloadedStrings, RecordWildCards #-} module Cabal (initializeGHC) where @@ -16,7 +16,6 @@ import GHC import GHCApi import GHCChoice import qualified Gap -import Language.Haskell.Extension import System.Directory import System.FilePath import Types @@ -34,12 +33,13 @@ initializeGHC opt fileName ghcOptions logging = withCabal ||> withoutCabal return (fileName,logReader) withCabal = do (owdir,cdir,cfile) <- liftIO getDirs - binfo <- liftIO $ parseCabalFile cfile - let (idirs',exts',mlang) = extractBuildInfo binfo - exts = map (addX . Gap.extensionToString) exts' - lang = maybe "-XHaskell98" (addX . show) mlang - gopts = ghcOptions ++ exts ++ [lang] - idirs = case idirs' of + binfo@BuildInfo{..} <- liftIO $ parseCabalFile cfile + let exts = map (addX . Gap.extensionToString) $ usedExtensions binfo + lang = maybe "-XHaskell98" (addX . show) defaultLanguage + libs = map ("-l" ++) extraLibs + libDirs = map ("-L" ++) extraLibDirs + gopts = ghcOptions ++ exts ++ [lang] ++ libs ++ libDirs + idirs = case hsSourceDirs of [] -> [cdir,owdir] dirs -> map (cdir ) dirs ++ [owdir] logReader <- initSession opt gopts idirs logging @@ -59,12 +59,6 @@ parseCabalFile file = do toMaybe [] = Nothing toMaybe (x:_) = Just x --- SourceDirs, Extensions, and Language -extractBuildInfo :: BuildInfo -> ([String],[Extension],Maybe Language) -extractBuildInfo binfo = (hsSourceDirs binfo - ,usedExtensions binfo - ,defaultLanguage binfo) - ---------------------------------------------------------------- -- CurrentWorkingDir, CabalDir, CabalFile diff --git a/GHCApi.hs b/GHCApi.hs index ef2cb41..560facb 100644 --- a/GHCApi.hs +++ b/GHCApi.hs @@ -45,7 +45,7 @@ setFlags opt d idirs d' = d { packageFlags = ghcPackage : packageFlags d , importPaths = idirs - , ghcLink = NoLink + , ghcLink = LinkInMemory , hscTarget = HscInterpreted , flags = flags d }