(我的问题是在没有 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
复制到主机
如果您还有使用 Cabal 的数据路径查找逻辑由二进制文件引用的数据文件(例如模板、图像、静态 html 页面),则可以使用 Setup copy
如下(使用以快乐为例):
/tmp/happy-1.18.10 $ ./Setup configure Warning: defaultUserHooks in Setup script is deprecated. Configuring happy-1.18.10... /tmp/happy-1.18.10 $ ./Setup build Building happy-1.18.10... Preprocessing executable 'happy' for happy-1.18.10... [ 1 of 18] Compiling NameSet ( src/NameSet.hs, dist/build/happy/happy-tmp/NameSet.o ) [..] [18 of 18] Compiling Main ( src/Main.lhs, dist/build/happy/happy-tmp/Main.o ) Linking dist/build/happy/happy ... /tmp/happy-1.18.10 $ ./Setup copy --destdir=/tmp/to_be_deployed/ Installing executable(s) in /tmp/to_be_deployed/usr/local/bin /tmp/happy-1.18.10 $ find /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 库,请参阅 question哈马尔在他的评论中链接了。
关于haskell - 最小的 haskell (ghc) 程序安装(无需 ghc/cabal 进行部署),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13395615/