]> git.lizzy.rs Git - rust.git/blob - src/ci/docker/scripts/musl-toolchain.sh
Rollup merge of #106886 - dtolnay:fastinstall, r=Mark-Simulacrum
[rust.git] / src / ci / docker / scripts / musl-toolchain.sh
1 #!/bin/sh
2 # This script runs `musl-cross-make` to prepare C toolchain (Binutils, GCC, musl itself)
3 # and builds static libunwind that we distribute for static target.
4 #
5 # Versions of the toolchain components are configurable in `musl-cross-make/Makefile` and
6 # musl unlike GLIBC is forward compatible so upgrading it shouldn't break old distributions.
7 # Right now we have: Binutils 2.31.1, GCC 9.2.0, musl 1.1.24.
8
9 # ignore-tidy-linelength
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 ARCH=$1
31 TARGET=$ARCH-linux-musl
32
33 # Don't depend on the mirrors of sabotage linux that musl-cross-make uses.
34 LINUX_HEADERS_SITE=https://ci-mirrors.rust-lang.org/rustc/sabotage-linux-tarballs
35
36 OUTPUT=/usr/local
37 shift
38
39 # Ancient binutils versions don't understand debug symbols produced by more recent tools.
40 # Apparently applying `-fPIC` everywhere allows them to link successfully.
41 # Enable debug info. If we don't do so, users can't debug into musl code,
42 # debuggers can't walk the stack, etc. Fixes #90103.
43 export CFLAGS="-fPIC -g1 $CFLAGS"
44
45 git clone https://github.com/richfelker/musl-cross-make # -b v0.9.9
46 cd musl-cross-make
47 # A few commits ahead of v0.9.9 to include the cowpatch fix:
48 git checkout a54eb56f33f255dfca60be045f12a5cfaf5a72a9
49
50 # Fix the cfi detection script in musl's configure so cfi is generated
51 # when debug info is asked for. This patch is derived from
52 # https://git.musl-libc.org/cgit/musl/commit/?id=c4d4028dde90562f631edf559fbc42d8ec1b29de.
53 # When we upgrade to a version that includes this commit, we can remove the patch.
54 mkdir patches/musl-1.1.24
55 cp ../musl-patch-configure.diff patches/musl-1.1.24/0001-fix-cfi-detection.diff
56
57 hide_output make -j$(nproc) TARGET=$TARGET MUSL_VER=1.1.24 LINUX_HEADERS_SITE=$LINUX_HEADERS_SITE
58 hide_output make install TARGET=$TARGET MUSL_VER=1.1.24 LINUX_HEADERS_SITE=$LINUX_HEADERS_SITE OUTPUT=$OUTPUT
59
60 cd -
61
62 # Install musl library to make binaries executable
63 ln -s $OUTPUT/$TARGET/lib/libc.so /lib/ld-musl-$ARCH.so.1
64 echo $OUTPUT/$TARGET/lib >> /etc/ld-musl-$ARCH.path
65
66 # Now when musl bootstraps itself create proper toolchain symlinks to make build and tests easier
67 if [ "$REPLACE_CC" = "1" ]; then
68     for exec in cc gcc; do
69         ln -s $TARGET-gcc /usr/local/bin/$exec
70     done
71     for exec in cpp c++ g++; do
72         ln -s $TARGET-g++ /usr/local/bin/$exec
73     done
74 fi