2012-11-15 72 views
3

(我的問題是有關分發二進制程序不哈斯克爾平臺,GHC,小集團,...)最小哈斯克爾(GHC)程序安裝(部署,而無需GHC /小集團)

我需要部署一個良好的陰謀形成哈斯克爾應用(一個Yesod腳手架),但我有磁盤空間限制。

GHC大小約爲1Gbytes,存儲所有陰謀的源代碼,包等...需要更多的磁盤空間,等等

顯然,哈斯克爾平臺,GHC,......是關於發展(不部署)。

在我的特定情況下,我可以生成

cabal clean && cabal configure && cabal build 

,併成功地運行(有些像)

./dist/build/MyEntryPoint/MyEntryPoint arg arg arg 

但是,這個依賴?如何將其移動到生產環境? (我的「dist」彙編)

我可以把沒有cabal的二進制依賴嗎?怎麼樣?

非常感謝!

+0

請參閱:[GHC編譯的二進制文件是否需要GHC或者它們是獨立的?](http://stackoverflow.com/questions/6389948/do-ghc-compiled-binaries-require-ghc-or-are-他們自包含) – hammar

+0

你認爲只檢查它將運行的ldd依賴關係嗎?我會盡力! :) – josejuan

+0

另請參閱有關二進制大小的說明:http://stackoverflow.com/questions/6115459/small-haskell-program-compiled-with-ghc-into-huge-binary –

回答

7

默認情況下,ghc使用Haskell庫的靜態鏈接。所以生成的二進制文件獨立於Haskell生態系統。如果你的程序不需要任何數據文件,剛剛走出從./dist/build/MyEntryPoint/MyEntryPoint複製二進制到主機

如果您也有通過使用數據路徑的二進制引用的數據文件(例如模板,圖片,靜態的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庫,請參閱hammar在其評論中鏈接的question

+0

「生成的二進制文件獨立於Haskell生態系統」謝謝!我會試試看! – josejuan

+0

你是對的Joachim,它是直接運行。再次感謝你! – josejuan