Skip to content

Commit 1cbd8cb

Browse files
authored
Slim docker musl (#233)
* Cleanup and bump rust-embedded cross base image from upstream in cross-rs/cross#452 to fix the debug symbols issue observed in #231 * Add test for non-release builds against all features (previously failing because of old toolchain) * Clean all the libs that are already handled via -sys crates. zlib cloudflare must be fixed upstream, not here. Only LLVM is needed at this point via docker, the (broken) htslib Makefile to build.rs transition that @pmarks did, simplified all this significantly, kudos
1 parent 8d0a761 commit 1cbd8cb

File tree

5 files changed

+15
-124
lines changed

5 files changed

+15
-124
lines changed

.github/workflows/rust.yml

+7
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,10 @@ jobs:
101101
use-cross: true
102102
command: build
103103
args: --release --target x86_64-unknown-linux-musl --all-features --verbose
104+
105+
- name: Test musl build with all features and debug symbols (non --release)
106+
uses: actions-rs/cargo@v1
107+
with:
108+
use-cross: true
109+
command: build
110+
args: --target x86_64-unknown-linux-musl --all-features --verbose

Cross.toml

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ passthrough = [
55
"CFLAGS"
66
]
77

8-
98
[target.x86_64-unknown-linux-musl]
10-
image = "brainstorm/cross-x86_64-unknown-linux-musl:1.0.2"
9+
image = "brainstorm/cross-x86_64-unknown-linux-musl:1.0.4"
1110
[target.x86_64-unknown-linux-gnu]
12-
image = "brainstorm/cross-x86_64-unknown-linux-gnu:1.0.0"
11+
image = "brainstorm/cross-x86_64-unknown-linux-gnu:1.0.4"

docker/Dockerfile.gnu

-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,3 @@ ENV LLVM_CONFIG_PATH /usr/bin
55
RUN apt-get update
66
RUN apt-get install -y build-essential wget gnupg lsb-release software-properties-common apt-transport-https ca-certificates # Otherwise LLVM bump below fails
77
RUN bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"
8-
RUN apt-get install -y libssl-dev libcurl4-openssl-dev zlib1g-dev libbz2-dev liblzma-dev # htslib deps
9-
RUN git clone --depth 1 https://github.com/ebiggers/libdeflate.git && \
10-
cd libdeflate && make -j40 CFLAGS="-fPIC -O3" install && \
11-
cd .. && rm -rf libdeflate

docker/Dockerfile.musl

+3-116
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,16 @@
1-
FROM rustembedded/cross:x86_64-unknown-linux-musl
1+
FROM brainstorm/cross-x86_64-unknown-linux-musl:upstream
22

3-
ENV MUSL_CROSS_MAKE_VERSION 0.9.9
3+
ENV DEBIAN_FRONTEND noninteractive
44
ENV PKG_CONFIG_ALLOW_CROSS 1
5-
ENV LZMA_VERSION 5.2.5
6-
ENV ZLIB_VERSION 1.2.11
7-
ENV OPENSSL_VERSION 1_1_1g
8-
ENV CURL_VERSION 7.70.0
95

106
ENV LIBCLANG_PATH /usr/lib/llvm-10/lib
117
ENV LLVM_CONFIG_PATH /usr/bin
128

13-
14-
# The default includes and packages from the Ubuntu distro that cross uses will generate all sorts of linux-headers related include errors, see:
15-
# https://github.com/rust-bio/rust-htslib/pull/184#commitcomment-37496651
16-
# Those are the packages installed, hopefully someone will find a good way to use the distro ones instead of compiling everything under /usr/local :/
17-
# apt-get install -y libssl-dev libcurl4-openssl-dev zlib1g-dev libbz2-dev liblzma-dev musl musl-dev musl-tools linux-libc-dev linux-headers-4.15.0-20-generic
18-
19-
# Install basics to locally compile htslib dependencies
20-
RUN apt-get update && \
21-
apt-get install -y build-essential autoconf automake autotools-dev git wget
9+
WORKDIR /root
2210

2311
# Otherwise LLVM bump below fails
2412
RUN apt-get install -y wget gnupg lsb-release software-properties-common apt-transport-https ca-certificates
2513

2614
# Autodetect and fetch latest LLVM repos for the current distro, avoids LLVM warnings and other issues, might generate slower builds for now though, see:
2715
# https://www.phoronix.com/scan.php?page=news_item&px=Rust-Hurt-On-LLVM-10
2816
RUN bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"
29-
#RUN apt-get install -y libssl-dev libcurl4-openssl-dev zlib1g-dev \
30-
# libbz2-dev liblzma-dev musl musl-dev musl-tools # htslib deps
31-
32-
# Remove pre-installed musl, to avoid cross-musl-make interference
33-
RUN apt-get remove -y musl
34-
35-
# For now we'll have to go nuts and not only build musl-1.2.0 from scratch but all the other libs too...
36-
# Updated musl-cross toolchain that does not fail on OpenSSL: https://github.com/openssl/openssl/issues/7207
37-
WORKDIR /root
38-
RUN wget https://github.com/richfelker/musl-cross-make/archive/v$MUSL_CROSS_MAKE_VERSION.tar.gz \
39-
&& tar xvfz v$MUSL_CROSS_MAKE_VERSION.tar.gz
40-
WORKDIR /root/musl-cross-make-$MUSL_CROSS_MAKE_VERSION
41-
COPY config-musl-cross-make.mak config.mak
42-
RUN make -j40 install && cd .. && rm v$MUSL_CROSS_MAKE_VERSION.tar.gz
43-
#&& rm -rf musl-cross-make-*
44-
45-
# Now we assume we have a properly configured musl-cross...
46-
ENV PATH "/usr/local/musl/bin:$PATH"
47-
ENV CFLAGS "-fPIC"
48-
ENV CROSS_COMPILE x86_64-linux-musl-
49-
ENV CC ${CROSS_COMPILE}cc
50-
ENV AR ${CROSS_COMPILE}ar
51-
ENV RANLIB ${CROSS_COMPILE}ranlib
52-
ENV CXX ${CROSS_COMPILE}g++
53-
ENV CPPFLAGS "-I/usr/local/musl/include -I/usr/local/include"
54-
ENV LDFLAGS "-L/usr/local/musl/lib -L/usr/local/lib"
55-
56-
# .. and carry on with the htslib deps
57-
WORKDIR /root
58-
RUN git clone --depth 1 https://github.com/ebiggers/libdeflate.git && \
59-
cd libdeflate && make -j40 CFLAGS="-fPIC -O3" PREFIX="/usr/local/musl" install && \
60-
cd .. && rm -rf libdeflate
61-
RUN git clone https://github.com/cloudflare/zlib cloudflare-zlib && \
62-
cd cloudflare-zlib && ./configure --static --prefix=/usr/local/musl && \
63-
make install && cd .. && rm -rf cloudflare-zlib
64-
#RUN wget https://www.zlib.net/zlib-$ZLIB_VERSION.tar.gz \
65-
# && tar xvfz zlib-$ZLIB_VERSION.tar.gz \
66-
# && cd zlib-$ZLIB_VERSION \
67-
# && ./configure --static --prefix=/usr/local/musl \
68-
# && make -j40 install
69-
RUN git clone git://sourceware.org/git/bzip2 \
70-
&& cd bzip2 \
71-
&& make -j40 CC=$CC AR=$AR RANLIB=$RANLIB CFLAGS=$CFLAGS bzip2 \
72-
&& make PREFIX=/usr/local/musl -j40 bzip2 \
73-
&& make -j40 install && cd .. && rm -rf bzip2
74-
RUN wget https://tukaani.org/xz/xz-$LZMA_VERSION.tar.bz2 \
75-
&& tar xvfj xz-$LZMA_VERSION.tar.bz2 \
76-
&& cd xz-$LZMA_VERSION \
77-
&& ./configure --prefix=/usr/local/musl \
78-
--enable-static --disable-shared \
79-
--host x86_64-unknown-linux-musl \
80-
&& make -j40 install && cd .. && rm -rf xz-$LZMA_VERSION xz-$LZMA_VERSION.tar.bz2
81-
82-
# A few gems from: https://wiki.openssl.org/index.php/Compilation_and_Installation
83-
# "OpenSSL has been around a long time, and it carries around a lot of cruft"
84-
# "SSLv2 is completely broken, and you should disable it during configuration"
85-
# "You should specify both --prefix and --openssldir to ensure make install works as expected."
86-
#
87-
# And also this:
88-
# https://github.com/openssl/openssl/issues/11362
89-
#
90-
# And having to redefine AR,CC & RANLIB because otherwise, this:
91-
#
92-
# make[1]: x86_64-linux-musl-x86_64-linux-musl-ar: Command not found
93-
RUN wget https://github.com/openssl/openssl/archive/OpenSSL_$OPENSSL_VERSION.tar.gz \
94-
&& tar xvfz OpenSSL_$OPENSSL_VERSION.tar.gz && cd openssl-OpenSSL_$OPENSSL_VERSION \
95-
&& ./Configure --prefix=/usr/local/musl --openssldir=/usr/local/musl \
96-
--with-zlib-lib=/usr/local/lib/zlib-$ZLIB_VERSION linux-x86_64 \
97-
no-shared no-dso no-gost no-engine no-ssl2 no-srp no-srtp no-tests zlib \
98-
no-weak-ssl-ciphers \
99-
&& make AR=x86_64-linux-musl-ar \
100-
CC=x86_64-linux-musl-cc \
101-
-j40 \
102-
&& make RANLIB=x86_64-linux-musl-ranlib -j40 install && cd .. \
103-
&& rm -rf OpenSSL_$OPENSSL_VERSION.tar.gz openssl-OpenSSL_$OPENSSL_VERSION
104-
105-
RUN wget https://curl.haxx.se/download/curl-$CURL_VERSION.tar.gz \
106-
&& tar xvfz curl-$CURL_VERSION.tar.gz && cd curl-$CURL_VERSION \
107-
&& ./configure --prefix=/usr/local/musl --host x86_64-linux-musl \
108-
--with-ssl=/usr/local/musl --with-zlib=/usr/local/musl --enable-static \
109-
--disable-dict --disable-ftp --disable-gopher --disable-imap \
110-
--disable-pop3 --disable-rtsp --disable-smb --disable-smtp --disable-telnet \
111-
--disable-tftp --disable-ntlm --disable-ldap \
112-
&& make -j40 install && cd .. \
113-
&& rm -rf curl-$CURL_VERSION.tar.gz curl-$CURL_VERSION
114-
115-
# To cater Rust's openssl-sys needs...
116-
ENV OPENSSL_DIR /usr/local/musl
117-
118-
# Hack to force ld stick to musl on the hts-sys/build.rs side, otherwise:
119-
# = note: /usr/bin/ld: /target/debug/deps/liblibloading-689161fea10b6234.rlib(global_static.o): unable to initialize decompress status for section .debug_info
120-
RUN rm /usr/bin/ld && ln -sf /usr/local/musl/bin/x86_64-linux-musl-ld /usr/bin/ld
121-
122-
# Prepare rustup and toolchain locally for easy manual intervention in this container
123-
#RUN wget https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init \
124-
# && chmod +x rustup-init \
125-
# && ./rustup-init -y \
126-
# && . $HOME/.cargo/env \
127-
# && rustup target add x86_64-unknown-linux-musl
128-
129-
CMD ["bash"]

docker/config-musl-cross-make.mak

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
TARGET = x86_64-linux-musl
22
OUTPUT = /usr/local/musl
33
GCC_VER = 9.2.0
4-
BINUTILS_VER = 2.33.1
4+
BINUTILS_VER = 2.33.1
5+
MUSL_VER=1.2.0
6+

0 commit comments

Comments
 (0)