Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Static ghc executables with musl+alpine linux
FROM alpine:latest
RUN apk add --update curl xz alpine-sdk perl gmp-dev file gmp openssh openssl
RUN cd /tmp && su -l operator -c "curl -o /tmp/ghc.xz ''"
RUN su -l operator -c "cd /tmp && xz -c -d /tmp/ghc.xz | tar xf -"
RUN cd /tmp/ghc-7.10.1 && ./configure --prefix=/opt && make install
RUN echo 'main = putStrLn "Hello static world"' > /tmp/static.hs
RUN /opt/bin/ghc --make -O2 --make -static -optc-static -optl-static /tmp/static.hs -optl-pthread -o /tmp/test
RUN openssl sha1 /tmp/test
RUN ldd /tmp/test
RUN file /tmp/test

This comment has been minimized.

Copy link
Owner Author

mitchty commented May 29, 2015

 ---> 151a4fb6e17a
Removing intermediate container 7e6ab82c4b03
Step 6 : RUN /opt/bin/ghc --make -O2 --make -static -optc-static -optl-static /tmp/static.hs -optl-pthread -o /tmp/test
 ---> Running in d5ccc4e9e9dd
[1 of 1] Compiling Main             ( /tmp/static.hs, /tmp/static.o )
Linking /tmp/test ...
 ---> 985b2509064c
Removing intermediate container d5ccc4e9e9dd
Step 7 : RUN openssl sha1 /tmp/test
 ---> Running in b0ca9da8177a
SHA1(/tmp/test)= 4475e44304bee8ae067d56b713e621d29353720e
 ---> ae11136fabbd
Removing intermediate container b0ca9da8177a
Step 8 : RUN ldd /tmp/test
 ---> Running in 1794072a6464
ldd: /tmp/test: Not a valid dynamic program

Then from an ubuntu 12.04 image via:

vagrant init phusion/ubuntu-12.04-amd64

vagrant@ubuntu-12:~$ cd /vagrant
vagrant@ubuntu-12:/vagrant$ ./test
Hello static world
vagrant@ubuntu-12:/vagrant$ ldd test
    not a dynamic executable
vagrant@ubuntu-12:/vagrant$ file test
test: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped
vagrant@ubuntu-12:/vagrant$ openssl sha1 test
SHA1(test)= 4475e44304bee8ae067d56b713e621d29353720e
vagrant@ubuntu-12:/vagrant$ cat /etc/os-release
VERSION="12.04.4 LTS, Precise Pangolin"
PRETTY_NAME="Ubuntu precise (12.04.4 LTS)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.