]> git.lizzy.rs Git - rust.git/blob - src/ci/docker/scripts/musl-toolchain.sh
build a proper c++-enabled musl toolchain with musl-cross-make
[rust.git] / src / ci / docker / scripts / musl-toolchain.sh
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