在Windows上部署应用程序的GHC API的简单方法

men*_*ics 11 windows deployment haskell ghc-api

我想在Windows上部署需要访问GHC API的应用程序.使用Wiki中的第一个简单示例:

http://www.haskell.org/haskellwiki/GHC/As_a_library

导致以下错误(在具有haskell平台的一台机器上编译并在另一个干净的Windows安装上执行):test.exe:在C:\ haskell\lib\package.conf.d中找不到包数据库

我想将我的应用程序部署为一个简单的zip文件,而不是要求用户安装任何东西.是否有一种简单的方法可以在该zip文件中包含所需的GHC内容,以便它可以工作?

max*_*kin 2

该程序会将必要的文件复制到指定目录(仅适用于Windows):

import Data.List (isSuffixOf)
import System.Environment (getArgs)
import GHC.Paths (libdir)
import System.Directory
import System.FilePath 
import System.Cmd

main = do
  [to] <- getArgs
  let libdir' = to </> "lib"
  createDirectoryIfMissing True libdir'
  copy libdir libdir'
  rawSystem "xcopy"
    [ "/e", "/q"
    , dropFileName libdir </> "mingw"
    , to </> "mingw\\"]


-- | skip some files while copying
uselessFile f
  = or $ map (`isSuffixOf` f)
    [ "."
    , "_debug.a"
    , "_p.a", ".p_hi"    -- libraries built with profiling
    , ".dyn_hi", ".dll"] -- dynamic libraries


copy from to
  = getDirectoryContents from
  >>= mapM_ copy' . filter (not . uselessFile)
  where
    copy' f = do
      let (from', to') = (from </> f, to </> f)
      isDir <- doesDirectoryExist from'
      if isDir
          then createDirectory to' >> copy from' to'
          else copyFile from' to'
Run Code Online (Sandbox Code Playgroud)

lib使用目标目录作为参数运行它后,您将获得和的本地副本mingw(总共约 300 Mb)。

您可以从中删除未使用的库lib以节省更多空间。