我想在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内容,以便它可以工作?
答案 0 :(得分: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
中删除未使用的库以节省更多空间。