(我的问题是关于没有haskell-platform,ghc,cabal等的分发二进制文件)
我需要部署一个良好的cabal形成haskell应用程序(Yesod脚手架),但我有磁盘空间限制。
GHC大小约为1Gbytes,存储所有cabal源代码,软件包等...需要更多磁盘空间等...
显然,haskell-platform,ghc,...是关于开发(不是部署)。
在我的具体情况下,我可以生成
cabal clean && cabal configure && cabal build
并成功运行(有些像)
./dist/build/MyEntryPoint/MyEntryPoint arg arg arg
但是,依赖关系呢?如何将其转移到生产环境? (我的“dist”汇编)
我可以在没有cabal的情况下放置二进制依赖项吗?怎么样?
非常感谢!
答案 0 :(得分:7)
默认情况下,ghc使用Haskell库的静态链接。因此,生成的二进制文件独立于Haskell生态系统。如果您的程序不需要任何数据文件,只需将二进制文件从./dist/build/MyEntryPoint/MyEntryPoint
复制到主机
如果您还拥有使用Cabal的数据路径查找逻辑由二进制文件引用的数据文件(例如模板,图像,静态html页面),则可以使用Setup copy
,如下所示(以happy为例) ):
/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库,请参阅hammar在其评论中链接的question。