11

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

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

导致以下错误(在具有 haskell 平台的一台机器上编译并在另一个干净的 Windows 安装上执行): test.exe: can't find a package database at C:\haskell\lib\package.conf.d

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

4

1 回答 1

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'

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

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

于 2011-03-31T11:41:19.983 回答