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.
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.
12 echo ERROR: An error was encountered with the build.
17 bash -c "while true; do sleep 30; echo \$(date) - building ...; done" &
27 TARGET=$ARCH-linux-musl
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"
36 git clone https://github.com/richfelker/musl-cross-make -b v0.9.8
39 hide_output make -j$(nproc) TARGET=$TARGET
40 hide_output make install TARGET=$TARGET OUTPUT=$OUTPUT
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
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
53 for exec in cpp c++ g++; do
54 ln -s $TARGET-g++ /usr/local/bin/$exec
59 export CXX=$TARGET-g++
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 -
69 # fixme(mati865): Replace it with https://github.com/rust-lang/rust/pull/59089
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"
80 hide_output make -j$(nproc)
81 cp lib/libunwind.a $OUTPUT/$TARGET/lib
82 cd - && rm -rf libunwind-build