Skip to content

Commit

Permalink
Use docker to build static releases
Browse files Browse the repository at this point in the history
Static builds are possible with the musl C library.
glibc is capricious when it comes to static linking and DNS support (and
other things).
  • Loading branch information
nviennot committed Oct 12, 2019
1 parent d654ff2 commit 44635e7
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 94 deletions.
27 changes: 27 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM alpine:3.10

WORKDIR /build

RUN apk add --no-cache wget cmake make gcc g++ linux-headers zlib-dev openssl-dev \
automake autoconf libevent-dev ncurses-dev msgpack-c-dev libexecinfo-dev \
ncurses-static libexecinfo-static libevent-static msgpack-c ncurses-libs \
libevent libexecinfo openssl zlib

RUN set -ex; \
mkdir -p /src/libssh/build; \
cd /src; \
wget -O libssh.tar.xz https://www.libssh.org/files/0.9/libssh-0.9.0.tar.xz; \
tar -xf libssh.tar.xz -C /src/libssh --strip-components=1; \
cd /src/libssh/build; \
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr \
-DWITH_SFTP=OFF -DWITH_SERVER=OFF -DWITH_PCAP=OFF \
-DWITH_STATIC_LIB=ON -DWITH_GSSAPI=OFF ..; \
make -j $(nproc); \
make install

COPY . .

RUN ./autogen.sh
RUN ./configure --enable-static
RUN make -j $(nproc)
RUN strip tmate
61 changes: 0 additions & 61 deletions Makefile.static-build

This file was deleted.

9 changes: 0 additions & 9 deletions compat/clock_gettime.c

This file was deleted.

11 changes: 0 additions & 11 deletions compat/memcpy.c

This file was deleted.

15 changes: 2 additions & 13 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ AC_ARG_ENABLE(
found_static=$enable_static
)
if test "x$found_static" = xyes; then
# XXX Static build are only doable with the musl library
PKG_CONFIG="pkg-config --static"

CFLAGS="$CFLAGS -flto"
LDFLAGS="$LDFLAGS -flto"
LDFLAGS="$LDFLAGS -flto -static -no-pie"

PKG_CHECK_MODULES([ZLIB], [zlib], [
CPPFLAGS="$ZLIB_CFLAGS $CPPFLAGS"
Expand All @@ -61,7 +62,6 @@ if test "x$found_static" = xyes; then
CPPFLAGS="$LIBCRYPTO_CFLAGS $CPPFLAGS"
LIBS="$LIBCRYPTO_LIBS $LIBS"
])
# See more static settings below... (search for found_static)
fi

# Is this gcc?
Expand Down Expand Up @@ -462,17 +462,6 @@ if test "x$found_getopt" != xno; then
fi
AM_CONDITIONAL(NO_GETOPT, [test "x$found_getopt" = xno])

if test "x$found_static" = xyes; then
# libc and libdl should be dynamically linked.
# but we want to lower our requirements for libc's version.
# so we extract some symobls and add them here
if test `uname -m` = x86_64; then
LIBS="compat/memcpy.o -Wl,--wrap=memcpy $LIBS"
fi
LIBS="compat/clock_gettime.o libc/fdelt_chk.o $LIBS"
LIBS="-Wl,-Bstatic ${LIBS/-ldl/} -Wl,-Bdynamic -ldl"
fi

# Check for BSD-style integer types.
AC_MSG_CHECKING(for BSD-style unsigned types)
AC_COMPILE_IFELSE([AC_LANG_SOURCE(
Expand Down

0 comments on commit 44635e7

Please sign in to comment.