]> git.lizzy.rs Git - rust.git/blob - src/ci/docker/scripts/musl-toolchain.sh
Rollup merge of #61389 - Zoxc:arena-cleanup, r=eddyb
[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.4.0, musl 1.1.22.
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.8
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 # Now when musl bootstraps itself create proper toolchain symlinks to make build and tests easier
49 if [ "$REPLACE_CC" = "1" ]; then
50     for exec in cc gcc; do
51         ln -s $TARGET-gcc /usr/local/bin/$exec
52     done
53     for exec in cpp c++ g++; do
54         ln -s $TARGET-g++ /usr/local/bin/$exec
55     done
56 fi
57
58 export CC=$TARGET-gcc
59 export CXX=$TARGET-g++
60
61 LLVM=70
62
63 # may have been downloaded in a previous run
64 if [ ! -d libunwind-release_$LLVM ]; then
65   curl -L https://github.com/llvm-mirror/llvm/archive/release_$LLVM.tar.gz | tar xzf -
66   curl -L https://github.com/llvm-mirror/libunwind/archive/release_$LLVM.tar.gz | tar xzf -
67 fi
68
69 # fixme(mati865): Replace it with https://github.com/rust-lang/rust/pull/59089
70 mkdir libunwind-build
71 cd libunwind-build
72 cmake ../libunwind-release_$LLVM \
73           -DLLVM_PATH=/build/llvm-release_$LLVM \
74           -DLIBUNWIND_ENABLE_SHARED=0 \
75           -DCMAKE_C_COMPILER=$CC \
76           -DCMAKE_CXX_COMPILER=$CXX \
77           -DCMAKE_C_FLAGS="$CFLAGS" \
78           -DCMAKE_CXX_FLAGS="$CXXFLAGS"
79
80 hide_output make -j$(nproc)
81 cp lib/libunwind.a $OUTPUT/$TARGET/lib
82 cd - && rm -rf libunwind-build