Haskell静态编译

#Haskell

今天尝试了一下给Haskell应用打docker镜像部署,发现一套下来镜像有好几个GB,显然是太大了。相比起来,同一个应用静态编译之后部署只需要40MB左右。

Cabal文件中需要加入下列内容:

ghc-options: -Wall -O2 -static -threaded
cc-options: -static
ld-options: -static -pthread
extra-lib-dirs: ./static-libs

gmp需要静态链接库,archlinux不提供,所以要手动编译,然后把libgmp.a放入./static-libs目录。

./configure --enable-static --disable-shared
make
cp .libs/libgmp.a /path/to/project/static-libs/