kaushalmodi/hello_musl

Figure out static linking of openssl

Closed this issue · 9 comments

Thanks @xmonader for https://gitter.im/nim-lang/Nim?at=5bbe573e271506518decaf88. I need to add this to the travis config now.

OPENSSL_DIR=/usr/lib/musl/ \
OPENSSL_INCLUDE_DIR=/usr/lib/musl/include/ \
DEP_OPENSSL_INCLUDE=/usr/lib/musl/include/ \
OPENSSL_LIB_DIR=/usr/lib/musl/lib/ \
OPENSSL_STATIC=1 

echo "Building OpenSSL" && \
cd /tmp && \
OPENSSL_VERSION=1.0.2o && \
curl -LO "https://www.openssl.org/source/openssl-$OPENSSL_VERSION.tar.gz" && \
tar xvzf "openssl-$OPENSSL_VERSION.tar.gz" && cd "openssl-$OPENSSL_VERSION" && \
env CC=musl-gcc ./Configure no-shared no-zlib -fPIC --prefix=/usr/lib/musl linux-x86_64 && \
env C_INCLUDE_PATH=/usr/lib/musl/include/ make depend && \
make && sudo make install

https://gitter.im/nim-lang/Nim?at=5bbe605d435c2a518e84b00a

As noted at https://gitter.im/nim-lang/Nim?at=5bbe64acf659e67772938a2a, libcrypto lib also needs to be built statically.

Libressl + musl build fails on Travis too: https://travis-ci.org/kaushalmodi/hello_musl/builds/440311276#L1420

  CC       compat/libcompatnoopt_la-explicit_bzero.lo
compat/getentropy_linux.c:31:26: fatal error: linux/sysctl.h: No such file or directory
 #include <linux/sysctl.h>
                          ^
compilation terminated.
make[2]: *** [compat/getentropy_linux.lo] Error 1

Ref: https://gitter.im/nim-lang/Nim?at=5bbf9370bbdc0b250524cf46

Finally got openssl+musl to compile on Travis!!

The magic solution:

hello_musl/config.nims

Lines 83 to 86 in eecd53e

# https://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html
# -idirafter /usr/include/ # Needed for Travis/Ubuntu build to pass, for linux/version.h, etc.
# -idirafter /usr/include/x86_64-linux-gnu/ # Needed for Travis/Ubuntu build to pass, for asm/types.h
putEnv("CC", "musl-gcc -static -idirafter /usr/include/ -idirafter /usr/include/x86_64-linux-gnu/")

But libressl+musl on Travis still fails:

Actually libressl+musl started building on Travis after the same two -dirafter switches!

Now optimize the libressl build using:

<leorize> small tips:
<leorize> build only the components that you use
<leorize> like this
<leorize> make -C crypto
<leorize> make -C ssl
<leorize> then install them with make -C crypto install

Ref: https://gitter.im/nim-lang/Nim?at=5bbf7b7b435c2a518e8ccbbe