Skip to content

Instantly share code, notes, and snippets.

@mitchty
Created May 29, 2015 02:21
Show Gist options
  • Save mitchty/b6dcc2b919249637b365 to your computer and use it in GitHub Desktop.
Save mitchty/b6dcc2b919249637b365 to your computer and use it in GitHub Desktop.
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 'http://10.11.12.2:8000/ghc-7.10.1-x86_64-unknown-linux-musl.tar.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
@mitchty
Copy link
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
NAME="Ubuntu"
VERSION="12.04.4 LTS, Precise Pangolin"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu precise (12.04.4 LTS)"
VERSION_ID="12.04"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment