Skip to content

Commit 1624dc0

Browse files
strfrymati865
authored andcommitted
build a proper c++-enabled musl toolchain with musl-cross-make
1 parent 2fe5d46 commit 1624dc0

File tree

2 files changed

+79
-9
lines changed

2 files changed

+79
-9
lines changed

src/ci/docker/dist-x86_64-musl/Dockerfile

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
44
g++ \
55
make \
66
file \
7+
wget \
78
curl \
89
ca-certificates \
910
python2.7 \
@@ -18,19 +19,17 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
1819

1920
WORKDIR /build/
2021

21-
COPY scripts/musl.sh /build/
22+
COPY scripts/musl-toolchain.sh /build/
2223
# We need to mitigate rust-lang/rust#34978 when compiling musl itself as well
23-
RUN CC=gcc \
24-
CFLAGS="-Wa,-mrelax-relocations=no" \
25-
CXX=g++ \
26-
CXXFLAGS="-Wa,-mrelax-relocations=no" \
27-
bash musl.sh x86_64 && rm -rf /build
24+
# TODO: Check what this issue is and if we can ignore it
25+
26+
RUN bash musl-toolchain.sh x86_64-linux-musl && rm -rf build
2827

2928
COPY scripts/sccache.sh /scripts/
3029
RUN sh /scripts/sccache.sh
3130

3231
ENV RUST_CONFIGURE_ARGS \
33-
--musl-root-x86_64=/musl-x86_64 \
32+
--musl-root-x86_64=/usr/local/x86_64-linux-musl \
3433
--enable-extended \
3534
--disable-docs
3635

@@ -39,9 +38,14 @@ ENV RUST_CONFIGURE_ARGS \
3938
# way to produce "super compatible" binaries.
4039
#
4140
# See: https://github.com/rust-lang/rust/issues/34978
42-
ENV CFLAGS_x86_64_unknown_linux_musl=-Wa,-mrelax-relocations=no
41+
#ENV CFLAGS_x86_64_unknown_linux_musl=-Wa,-mrelax-relocations=no
42+
43+
ENV HOSTS=x86_64-unknown-linux-musl \
44+
CC_x86_64_unknown_linux_musl=x86_64-linux-musl-gcc \
45+
CXX_x86_64_unknown_linux_musl=x86_64-linux-musl-g++
4346

44-
ENV HOSTS=x86_64-unknown-linux-musl
47+
# CARGO_TARGET_ARM_UNKNOWN_LINUX_MUSLEABIHF_LINKER=musl-gcc \
48+
# CARGO_TARGET_ARM_UNKNOWN_LINUX_MUSLEABIHF_RUNNER="qemu-arm -L /musl-arm"
4549

4650
ENV RUSTFLAGS="-C target-feature=-crt-static"
4751

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
# file at the top-level directory of this distribution and at
3+
# http://rust-lang.org/COPYRIGHT.
4+
#
5+
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
# option. This file may not be copied, modified, or distributed
9+
# except according to those terms.
10+
11+
set -ex
12+
13+
hide_output() {
14+
set +x
15+
on_err="
16+
echo ERROR: An error was encountered with the build.
17+
cat /tmp/build.log
18+
exit 1
19+
"
20+
trap "$on_err" ERR
21+
bash -c "while true; do sleep 30; echo \$(date) - building ...; done" &
22+
PING_LOOP_PID=$!
23+
$@ &> /tmp/build.log
24+
trap - ERR
25+
kill $PING_LOOP_PID
26+
rm /tmp/build.log
27+
set -x
28+
}
29+
30+
TARGET=$1
31+
OUTPUT=/usr/local
32+
shift
33+
34+
git clone https://github.com/richfelker/musl-cross-make -b v0.9.7
35+
cd musl-cross-make
36+
37+
hide_output make -j$(nproc) TARGET=$TARGET
38+
hide_output make install TARGET=$TARGET OUTPUT=$OUTPUT
39+
40+
cd ..
41+
42+
export CC=$TARGET-gcc
43+
export CXX=$TARGET-g++
44+
45+
LLVM=60
46+
47+
# may have been downloaded in a previous run
48+
if [ ! -d libunwind-release_$LLVM ]; then
49+
curl -L https://github.com/llvm-mirror/llvm/archive/release_$LLVM.tar.gz | tar xzf -
50+
curl -L https://github.com/llvm-mirror/libunwind/archive/release_$LLVM.tar.gz | tar xzf -
51+
fi
52+
53+
mkdir libunwind-build
54+
cd libunwind-build
55+
cmake ../libunwind-release_$LLVM \
56+
-DLLVM_PATH=/build/llvm-release_$LLVM \
57+
-DLIBUNWIND_ENABLE_SHARED=0 \
58+
-DCMAKE_C_COMPILER=$CC \
59+
-DCMAKE_CXX_COMPILER=$CXX \
60+
-DCMAKE_C_FLAGS="$CFLAGS" \
61+
-DCMAKE_CXX_FLAGS="$CXXFLAGS"
62+
63+
hide_output make -j$(nproc)
64+
cp lib/libunwind.a $OUTPUT/$TARGET/lib
65+
cd ../ && rm -rf libunwind-build
66+

0 commit comments

Comments
 (0)