7

我一直在玩插件包。我希望主机应用程序能够在沙盒环境中动态编译和加载 Haskell 源文件。编译工作得很好。只要插件引用仅在沙箱中可用的模块,加载就会失败。这是我为插件准备的:

module Plugin (resource) where

import ServerAPI
import System.Plugins -- this module is only available in the sandbox

resource = Interface { action = timesTwo }

timesTwo :: Integer -> IO Integer
timesTwo n = return $ n * 2

从主机应用程序加载插件如下所示:

pkgConfDir = "/home/me/plugins/.cabal-sandbox/x86_64-osx-ghc-7.8.4-packages.conf.d
loadedOk <- pdynload "Plugin.o" ["."] [pkgConfDir] "ServerAPI.Interface" "resource"

这是我在沙箱中得到的:

> cabal sandbox hc-pkg list
…
/home/me/plugins/.cabal-sandbox/x86_64-osx-ghc-7.8.4-packages.conf.d
    plugins-1.5.4.0
…

这是我在运行主机应用程序时得到的:

Failed to load interface for ‘System.Plugins.Env’
no package matching ‘plugins-1.5.4.0’ was found

如上所述,当我摆脱import System.Plugins插件中的语句时,代码会加载。我错过了什么?

编辑:

阴谋集团文件:

name:                plugins
version:             0.1.0.0
-- synopsis:
-- description:
-- license:
license-file:        LICENSE
author:              W. Davis
maintainer:          w.davis@spam.me.not
-- copyright:
-- category:
build-type:          Simple
-- extra-source-files:
cabal-version:       >=1.10

executable plugins
  main-is:             Main.hs
  -- other-modules:       
  -- other-extensions:
  build-depends:       base >=4.7 && <4.8, plugins >=1.5 && <1.6
  -- hs-source-dirs:
  default-language:    Haskell2010
4

0 回答 0