]> git.lizzy.rs Git - rust.git/blob - src/ci/docker/scripts/musl-toolchain.sh
Auto merge of #59887 - eddyb:safer-metadata, r=Zoxc
[rust.git] / src / ci / docker / scripts / musl-toolchain.sh
1 # This script runs `musl-cross-make` to prepare C toolchain (Binutils, GCC, musl itself)
2 # and builds static libunwind that we distribute for static target.
3 #
4 # Versions of the toolchain components are configurable in `musl-cross-make/Makefile` and
5 # musl unlike GLIBC is forward compatible so upgrading it shouldn't break old distributions.
6 # Right now we have: Binutils 2.27, GCC 6.3.0, musl 1.1.18
7 set -ex
8
9 hide_output() {
10   set +x
11   on_err="
12 echo ERROR: An error was encountered with the build.
13 cat /tmp/build.log
14 exit 1
15 "
16   trap "$on_err" ERR
17   bash -c "while true; do sleep 30; echo \$(date) - building ...; done" &
18   PING_LOOP_PID=$!
19   $@ &> /tmp/build.log
20   trap - ERR
21   kill $PING_LOOP_PID
22   rm /tmp/build.log
23   set -x
24 }
25
26 ARCH=$1
27 TARGET=$ARCH-linux-musl
28
29 OUTPUT=/usr/local
30 shift
31
32 # Ancient binutils versions don't understand debug symbols produced by more recent tools.
33 # Apparently applying `-fPIC` everywhere allows them to link successfully.
34 export CFLAGS="-fPIC $CFLAGS"
35
36 git clone https://github.com/richfelker/musl-cross-make -b v0.9.7
37 cd musl-cross-make
38
39 hide_output make -j$(nproc) TARGET=$TARGET
40 hide_output make install TARGET=$TARGET OUTPUT=$OUTPUT
41
42 cd -
43
44 # Install musl library to make binaries executable
45 ln -s $OUTPUT/$TARGET/lib/libc.so /lib/ld-musl-$ARCH.so.1
46 echo $OUTPUT/$TARGET/lib >> /etc/ld-musl-$ARCH.path
47
48
49 export CC=$TARGET-gcc
50 export CXX=$TARGET-g++
51
52 LLVM=70
53
54 # may have been downloaded in a previous run
55 if [ ! -d libunwind-release_$LLVM ]; then
56   curl -L https://github.com/llvm-mirror/llvm/archive/release_$LLVM.tar.gz | tar xzf -
57   curl -L https://github.com/llvm-mirror/libunwind/archive/release_$LLVM.tar.gz | tar xzf -
58 fi
59
60 # fixme(mati865): Replace it with https://github.com/rust-lang/rust/pull/59089
61 mkdir libunwind-build
62 cd libunwind-build
63 cmake ../libunwind-release_$LLVM \
64           -DLLVM_PATH=/build/llvm-release_$LLVM \
65           -DLIBUNWIND_ENABLE_SHARED=0 \
66           -DCMAKE_C_COMPILER=$CC \
67           -DCMAKE_CXX_COMPILER=$CXX \
68           -DCMAKE_C_FLAGS="$CFLAGS" \
69           -DCMAKE_CXX_FLAGS="$CXXFLAGS"
70
71 hide_output make -j$(nproc)
72 cp lib/libunwind.a $OUTPUT/$TARGET/lib
73 cd - && rm -rf libunwind-build