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
As noted at https://gitter.im/nim-lang/Nim?at=5bbe64acf659e67772938a2a, libcrypto lib also needs to be built statically.
- Works on RHEL 6.8 with openssl: https://github.com/kaushalmodi/hello_musl/tree/ssl-works-rhel-6-8, but fails on Travis
- Issue for openssl + musl build on Travis: travis-ci/travis-ci#10226
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
Another tip by leorize: https://gitter.im/nim-lang/Nim?at=5bc00dfebbdc0b2505282b3d
Finally got openssl+musl to compile on Travis!!
The magic solution:
Lines 83 to 86 in eecd53e
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