(我的问题是关于分发没有 haskell-platform、ghc、cabal 等的二进制文件……)
我需要部署一个结构良好的 haskell 应用程序(一个 Yesod 脚手架),但我有磁盘空间限制。
GHC 大小约为 1Gbytes,存储所有 cabal 源代码、包等...需要更多磁盘空间等...
显然,haskell-platform, ghc, ... 是关于开发(而不是部署)的。
在我的具体情况下,我可以生成
cabal clean && cabal configure && cabal build
并成功运行(有些喜欢)
./dist/build/MyEntryPoint/MyEntryPoint arg arg arg
但是,依赖关系如何?如何将其移动到生产环境? (连同我的“dist”汇编)
我可以在没有 cabal 的情况下放置二进制依赖项吗?如何?
非常感谢你!
最佳答案
默认情况下,ghc 使用 Haskell 库的静态链接。因此生成的二进制文件独立于 Haskell 生态系统。如果您的程序不需要任何数据文件,只需将二进制文件从 ./dist/build/MyEntryPoint/MyEntryPoint
复制到主机
如果您还有数据文件(例如模板、图像、静态 html 页面)被使用 Cabal 的数据路径查找逻辑的二进制文件引用,您可以使用 Setup copy
如下(以happy 为例):
/tmp/happy-1.18.10 $ ./Setup 配置
警告:不推荐使用安装脚本中的 defaultUserHooks。
配置happy-1.18.10...
/tmp/happy-1.18.10 $ ./Setup build
构建happy-1.18.10...
为happy-1.18.10 预处理可执行文件“happy”...
[ 1 of 18] 编译 NameSet ( src/NameSet.hs, dist/build/happy/happy-tmp/NameSet.o )
[..]
[18 of 18] 编译 Main ( src/Main.lhs, dist/build/happy/happy-tmp/Main.o )
链接 dist/build/happy/happy ...
/tmp/happy-1.18.10 $ ./Setup copy --destdir=/tmp/to_be_deployed/
在/tmp/to_be_deployed/usr/local/bin 中安装可执行文件
/tmp/happy-1.18.10 $ 查找/tmp/to_be_deployed
/tmp/to_be_deployed
/tmp/to_be_deployed/usr
/tmp/to_be_deployed/usr/local
/tmp/to_be_deployed/usr/local/bin
/tmp/to_be_deployed/usr/local/bin/happy
/tmp/to_be_deployed/usr/local/share
/tmp/to_be_deployed/usr/local/share/doc
/tmp/to_be_deployed/usr/local/share/doc/happy-1.18.10
/tmp/to_be_deployed/usr/local/share/doc/happy-1.18.10/LICENSE
/tmp/to_be_deployed/usr/local/share/happy-1.18.10
/tmp/to_be_deployed/usr/local/share/happy-1.18.10/GLR_Lib-ghc-debug
/tmp/to_be_deployed/usr/local/share/happy-1.18.10/GLR_Lib-ghc
/tmp/to_be_deployed/usr/local/share/happy-1.18.10/GLR_Lib
/tmp/to_be_deployed/usr/local/share/happy-1.18.10/GLR_Base
/tmp/to_be_deployed/usr/local/share/happy-1.18.10/HappyTemplate-arrays-coerce-debug
/tmp/to_be_deployed/usr/local/share/happy-1.18.10/HappyTemplate-arrays-ghc-debug
/tmp/to_be_deployed/usr/local/share/happy-1.18.10/HappyTemplate-arrays-debug
/tmp/to_be_deployed/usr/local/share/happy-1.18.10/HappyTemplate-arrays-coerce
/tmp/to_be_deployed/usr/local/share/happy-1.18.10/HappyTemplate-arrays-ghc
/tmp/to_be_deployed/usr/local/share/happy-1.18.10/HappyTemplate-arrays
/tmp/to_be_deployed/usr/local/share/happy-1.18.10/HappyTemplate-coerce
/tmp/to_be_deployed/usr/local/share/happy-1.18.10/HappyTemplate-ghc
/tmp/to_be_deployed/usr/local/share/happy-1.18.10/HappyTemplate
/tmp/happy-1.18.10 $ rsync -rva/tmp/to_be_deployed/production.host:/
[..]
如果您不想安装到 /usr/local
中,则将所需的前缀传递给 Setup configure
。
如果目标主机在其他方面相似(安装了相同版本的 C 库,例如 gmp 和 ffi),这将很有效。如果您还需要静态链接某个 C 库,请参阅 hammar 在其评论中链接的 question。