Use docker to build static releases

Static builds are possible with the musl C library.
glibc is capricious when it comes to static linking and DNS support (and
other things).
This commit is contained in:
Nicolas Viennot 2019-10-12 13:50:27 -04:00
parent d654ff2219
commit 44635e752d
5 changed files with 29 additions and 94 deletions

27
Dockerfile Normal file
View File

@ -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

View File

@ -1,61 +0,0 @@
LIBSSH=libssh-0.7.2
LIBSSH_URL=https://red.libssh.org/attachments/download/177/$(LIBSSH).tar.xz
LIBSSH_LIB=ext/lib/libssh.a
MSGPACK=msgpack-1.3.0
MSGPACK_URL=https://github.com/msgpack/msgpack-c/releases/download/cpp-1.3.0/$(MSGPACK).tar.gz
MSGPACK_LIB=ext/lib/libmsgpack.a
TMATE_CONFIGURE=PKG_CONFIG_PATH=./ext/lib/pkgconfig
LIBC=$(shell gcc -print-file-name=libc.a)
STATIC_LIBC_OBJECTS=fdelt_chk
STATIC_COMPAT_OBJECTS=memcpy clock_gettime
all: tmate
dependencies:
apt-get install build-essential cmake libssl-dev autoconf automake pkg-config libtool libevent-dev libncurses-dev zlib1g-dev
downloads/$(notdir $(LIBSSH_URL)):
mkdir -p downloads
wget -O $@ $(LIBSSH_URL)
$(LIBSSH)/.ready: downloads/$(notdir $(LIBSSH_URL))
tar xf $<
touch $@
downloads/$(notdir $(MSGPACK_URL)):
mkdir -p downloads
wget -O $@ $(MSGPACK_URL)
$(MSGPACK)/.ready: downloads/$(notdir $(MSGPACK_URL))
tar xf $<
touch $@
$(LIBSSH_LIB): $(LIBSSH)/.ready
mkdir -p $(LIBSSH)/build
cd $(LIBSSH)/build; ([ -f Makefile ] || cmake -DCMAKE_INSTALL_PREFIX:PATH=$(shell pwd)/ext .. -DWITH_SFTP=OFF -DWITH_SERVER=OFF -DWITH_PCAP=OFF -DWITH_STATIC_LIB=ON -DWITH_GSSAPI=OFF)
+make -C $(LIBSSH)/build install
$(MSGPACK_LIB): $(MSGPACK)/.ready
mkdir -p $(MSGPACK)/build
cd $(MSGPACK)/build; ([ -f Makefile ] || cmake -DCMAKE_INSTALL_PREFIX:PATH=$(shell pwd)/ext ..)
+make -C $(MSGPACK)/build install
libc/%.o:
mkdir -p libc
cd libc; ar x $(LIBC) $(notdir $@)
compat/%.o: compat/%.c
gcc -c -o $@ $<
tmate: $(MSGPACK_LIB) $(LIBSSH_LIB) $(patsubst %,libc/%.o,$(STATIC_LIBC_OBJECTS)) $(patsubst %,compat/%.o,$(STATIC_COMPAT_OBJECTS))
./autogen.sh
$(TMATE_CONFIGURE) ./configure --enable-static
+make
strip tmate
clean:
rm -rf ext libc $(LIBSSH) $(MSGPACK)
+make clean

View File

@ -1,9 +0,0 @@
#define _GNU_SOURCE
#include <time.h>
#include <unistd.h>
#include <sys/syscall.h>
int clock_gettime(clockid_t clk_id, struct timespec *tp)
{
return syscall(SYS_clock_gettime, clk_id, tp);
}

View File

@ -1,11 +0,0 @@
// http://stackoverflow.com/questions/8823267/linking-against-older-symbol-version-in-a-so-file
#include <string.h>
/* some systems do not have newest memcpy@@GLIBC_2.14 - stay with old good one */
asm (".symver memcpy, memcpy@GLIBC_2.2.5");
void *__wrap_memcpy(void *dest, const void *src, size_t n)
{
return memcpy(dest, src, n);
}

View File

@ -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"
@ -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?
@ -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(