]> git.lizzy.rs Git - rust.git/blob - src/ci/docker/dist-fuchsia/build-toolchain.sh
Rollup merge of #39918 - petrhosek:fuchsia-ci, r=alexcrichton
[rust.git] / src / ci / docker / dist-fuchsia / build-toolchain.sh
1 #!/bin/bash
2 # Copyright 2017 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 source shared.sh
14
15 # Download sources
16 SRCS=(
17   "https://fuchsia.googlesource.com/magenta magenta ac69119"
18   "https://fuchsia.googlesource.com/third_party/llvm llvm 5463083"
19   "https://fuchsia.googlesource.com/third_party/clang llvm/tools/clang 4ff7b4b"
20   "https://fuchsia.googlesource.com/third_party/lld llvm/tools/lld fd465a3"
21   "https://fuchsia.googlesource.com/third_party/lldb llvm/tools/lldb 6bb11f8"
22   "https://fuchsia.googlesource.com/third_party/compiler-rt llvm/runtimes/compiler-rt 52d4ecc"
23   "https://fuchsia.googlesource.com/third_party/libcxx llvm/runtimes/libcxx e891cc8"
24   "https://fuchsia.googlesource.com/third_party/libcxxabi llvm/runtimes/libcxxabi f0f0257"
25   "https://fuchsia.googlesource.com/third_party/libunwind llvm/runtimes/libunwind 50bddc1"
26 )
27
28 fetch() {
29   mkdir -p $2
30   pushd $2 > /dev/null
31   curl -sL $1/+archive/$3.tar.gz | tar xzf -
32   popd > /dev/null
33 }
34
35 for i in "${SRCS[@]}"; do
36   fetch $i
37 done
38
39 # Build toolchain
40 cd llvm
41 mkdir build
42 cd build
43 hide_output cmake -GNinja \
44   -DFUCHSIA_SYSROOT=${PWD}/../../magenta/third_party/ulib/musl \
45   -DLLVM_ENABLE_LTO=OFF \
46   -DCLANG_BOOTSTRAP_PASSTHROUGH=LLVM_ENABLE_LTO \
47   -C ../tools/clang/cmake/caches/Fuchsia.cmake \
48   ..
49 hide_output ninja stage2-distribution
50 hide_output ninja stage2-install-distribution
51 cd ../..
52
53 # Build sysroot
54 rm -rf llvm/runtimes/compiler-rt
55 ./magenta/scripts/download-toolchain
56
57 build_sysroot() {
58   local arch="$1"
59
60   case "${arch}" in
61     x86_64) tgt="magenta-pc-x86-64" ;;
62     aarch64) tgt="magenta-qemu-arm64" ;;
63   esac
64
65   hide_output make -C magenta -j$(getconf _NPROCESSORS_ONLN) $tgt
66   dst=/usr/local/${arch}-unknown-fuchsia
67   mkdir -p $dst
68   cp -r magenta/build-${tgt}/sysroot/include $dst/
69   cp -r magenta/build-${tgt}/sysroot/lib $dst/
70
71   cd llvm
72   mkdir build-runtimes-${arch}
73   cd build-runtimes-${arch}
74   hide_output cmake -GNinja \
75     -DCMAKE_C_COMPILER=clang \
76     -DCMAKE_CXX_COMPILER=clang++ \
77     -DCMAKE_AR=/usr/local/bin/llvm-ar \
78     -DCMAKE_RANLIB=/usr/local/bin/llvm-ranlib \
79     -DCMAKE_INSTALL_PREFIX= \
80     -DLLVM_MAIN_SRC_DIR=${PWD}/.. \
81     -DLLVM_BINARY_DIR=${PWD}/../build \
82     -DLLVM_ENABLE_WERROR=OFF \
83     -DCMAKE_BUILD_TYPE=Release \
84     -DLLVM_INCLUDE_TESTS=ON \
85     -DCMAKE_SYSTEM_NAME=Fuchsia \
86     -DCMAKE_C_COMPILER_TARGET=${arch}-fuchsia \
87     -DCMAKE_CXX_COMPILER_TARGET=${arch}-fuchsia \
88     -DUNIX=1 \
89     -DLIBCXX_HAS_MUSL_LIBC=ON \
90     -DLIBCXXABI_USE_LLVM_UNWINDER=ON \
91     -DCMAKE_SYSROOT=${dst} \
92     -DCMAKE_C_COMPILER_FORCED=TRUE \
93     -DCMAKE_CXX_COMPILER_FORCED=TRUE \
94     -DLLVM_ENABLE_LIBCXX=ON \
95     -DCMAKE_EXE_LINKER_FLAGS="-nodefaultlibs -lc" \
96     -DCMAKE_SHARED_LINKER_FLAGS="$(clang --target=${arch}-fuchsia -print-libgcc-file-name)" \
97     ../runtimes
98   hide_output env DESTDIR="${dst}" ninja install
99   cd ../..
100 }
101
102 build_sysroot "x86_64"
103 build_sysroot "aarch64"
104
105 rm -rf magenta llvm
106
107 for arch in x86_64 aarch64; do
108   for tool in clang clang++; do
109     cat >/usr/local/bin/${arch}-unknown-fuchsia-${tool} <<EOF
110 #!/bin/sh
111 ${tool} --target=${arch}-unknown-fuchsia --sysroot=/usr/local/${arch}-unknown-fuchsia "\$@"
112 EOF
113     chmod +x /usr/local/bin/${arch}-unknown-fuchsia-${tool}
114   done
115   ln -s /usr/local/bin/llvm-ar /usr/local/bin/${arch}-unknown-fuchsia-ar
116 done