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

发布于 2024-10-23 19:48:05 字数 391 浏览 3 评论 0原文

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

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

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

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

I want to deploy an application on Windows that needs to access the GHC API. Using the first simple example from the Wiki:

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

results in the following error (compiled on one machine with haskell platform and executed on another clean windows install):
test.exe: can't find a package database at C:\haskell\lib\package.conf.d

I'd like to deploy my application as a simple zip file and not require the user to have anything installed. Is there a straightforward way to include the needed GHC things in that zip file so it will work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深海不蓝 2024-10-30 19:48:05

该程序会将必要的文件复制到指定的目录(仅适用于 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'

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

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

This program will copy necessary files to the specified directory (will work only on 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'

After running it with destination directory as argument you will have a local copy of lib and mingw (about 300 Mb total).

You can remove unused libraries from lib to save more space.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文