]> git.lizzy.rs Git - rust.git/blob - src/ci/docker/dist-i586-gnu-i686-musl/build-musl.sh
Rollup merge of #41135 - japaric:unstable-docs, r=steveklabnik
[rust.git] / src / ci / docker / dist-i586-gnu-i686-musl / build-musl.sh
1 #!/bin/sh
2 # Copyright 2016 The Rust Project Developers. See the COPYRIGHT
3 # file at the top-level directory of this distribution and at
4 # http://rust-lang.org/COPYRIGHT.
5 #
6 # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
7 # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
8 # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
9 # option. This file may not be copied, modified, or distributed
10 # except according to those terms.
11
12 set -ex
13
14 # We need to mitigate rust-lang/rust#34978 when compiling musl itself as well
15 export CFLAGS="-fPIC -Wa,-mrelax-relocations=no"
16 export CXXFLAGS="-Wa,-mrelax-relocations=no"
17
18 MUSL=musl-1.1.16
19 curl https://www.musl-libc.org/releases/$MUSL.tar.gz | tar xzf -
20 cd $MUSL
21 CC=gcc \
22   CFLAGS="$CFLAGS -m32" \
23   ./configure --prefix=/musl-i686 --disable-shared \
24     --target=i686
25 make AR=ar RANLIB=ranlib -j10
26 make install
27 cd ..
28
29 # To build MUSL we're going to need a libunwind lying around, so acquire that
30 # here and build it.
31 curl -L https://github.com/llvm-mirror/llvm/archive/release_37.tar.gz | tar xzf -
32 curl -L https://github.com/llvm-mirror/libunwind/archive/release_37.tar.gz | tar xzf -
33
34 # Whoa what's this mysterious patch we're applying to libunwind! Why are we
35 # swapping the values of ESP/EBP in libunwind?!
36 #
37 # Discovered in #35599 it turns out that the vanilla build of libunwind is not
38 # suitable for unwinding 32-bit musl. After some investigation it ended up
39 # looking like the register values for ESP/EBP were indeed incorrect (swapped)
40 # in the source. Similar commits in libunwind (r280099 and r282589) have noticed
41 # this for other platforms, and we just need to realize it for musl linux as
42 # well.
43 #
44 # More technical info can be found at #35599
45 cd libunwind-release_37
46 patch -Np1 < /build/musl-libunwind-patch.patch
47 cd ..
48
49 mkdir libunwind-build
50 cd libunwind-build
51 CFLAGS="$CFLAGS -m32" CXXFLAGS="$CXXFLAGS -m32" cmake ../libunwind-release_37 \
52           -DLLVM_PATH=/build/llvm-release_37 \
53           -DLIBUNWIND_ENABLE_SHARED=0
54 make -j10
55 cp lib/libunwind.a /musl-i686/lib