|
| 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 29f09e6" |
| 18 | + "https://fuchsia.googlesource.com/third_party/llvm llvm 0f6af23" |
| 19 | + "https://fuchsia.googlesource.com/third_party/clang llvm/tools/clang 71b73d0" |
| 20 | + "https://fuchsia.googlesource.com/third_party/lld llvm/tools/lld af25ab9" |
| 21 | + "https://fuchsia.googlesource.com/third_party/lldb llvm/tools/lldb 90fe975" |
| 22 | + "https://fuchsia.googlesource.com/third_party/compiler-rt llvm/runtimes/compiler-rt 2edda55" |
| 23 | + "https://fuchsia.googlesource.com/third_party/libcxx llvm/runtimes/libcxx b7fd0be" |
| 24 | + "https://fuchsia.googlesource.com/third_party/libcxxabi llvm/runtimes/libcxxabi 66c8647" |
| 25 | + "https://fuchsia.googlesource.com/third_party/libunwind llvm/runtimes/libunwind 43ce8ac" |
| 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 | + -C ../tools/clang/cmake/caches/Fuchsia.cmake \ |
| 46 | + .. |
| 47 | +hide_output ninja stage2-distribution |
| 48 | +hide_output ninja stage2-install-distribution |
| 49 | +cd ../.. |
| 50 | + |
| 51 | +# Build sysroot |
| 52 | +rm -rf llvm/runtimes/compiler-rt |
| 53 | +./magenta/scripts/download-toolchain |
| 54 | + |
| 55 | +build_sysroot() { |
| 56 | + local arch="$1" |
| 57 | + |
| 58 | + case "${arch}" in |
| 59 | + x86_64) tgt="magenta-pc-x86-64" ;; |
| 60 | + aarch64) tgt="magenta-qemu-arm64" ;; |
| 61 | + esac |
| 62 | + |
| 63 | + hide_output make -C magenta -j$(getconf _NPROCESSORS_ONLN) $tgt |
| 64 | + dst=/usr/local/${arch}-unknown-fuchsia |
| 65 | + mkdir -p $dst |
| 66 | + cp -r magenta/build-${tgt}/sysroot/include $dst/ |
| 67 | + cp -r magenta/build-${tgt}/sysroot/lib $dst/ |
| 68 | + |
| 69 | + cd llvm |
| 70 | + mkdir build-runtimes-${arch} |
| 71 | + cd build-runtimes-${arch} |
| 72 | + hide_output cmake -GNinja \ |
| 73 | + -DCMAKE_C_COMPILER=clang \ |
| 74 | + -DCMAKE_CXX_COMPILER=clang++ \ |
| 75 | + -DCMAKE_AR=/usr/local/bin/llvm-ar \ |
| 76 | + -DCMAKE_RANLIB=/usr/local/bin/llvm-ranlib \ |
| 77 | + -DCMAKE_INSTALL_PREFIX= \ |
| 78 | + -DLLVM_MAIN_SRC_DIR=${PWD}/.. \ |
| 79 | + -DLLVM_BINARY_DIR=${PWD}/../build \ |
| 80 | + -DLLVM_ENABLE_WERROR=OFF \ |
| 81 | + -DCMAKE_BUILD_TYPE=Release \ |
| 82 | + -DLLVM_INCLUDE_TESTS=ON \ |
| 83 | + -DCMAKE_SYSTEM_NAME=Fuchsia \ |
| 84 | + -DCMAKE_C_COMPILER_TARGET=${arch}-fuchsia \ |
| 85 | + -DCMAKE_CXX_COMPILER_TARGET=${arch}-fuchsia \ |
| 86 | + -DUNIX=1 \ |
| 87 | + -DLIBCXX_HAS_MUSL_LIBC=ON \ |
| 88 | + -DLIBCXXABI_USE_LLVM_UNWINDER=ON \ |
| 89 | + -DCMAKE_SYSROOT=${dst} \ |
| 90 | + -DCMAKE_C_COMPILER_FORCED=TRUE \ |
| 91 | + -DCMAKE_CXX_COMPILER_FORCED=TRUE \ |
| 92 | + -DLLVM_ENABLE_LIBCXX=ON \ |
| 93 | + -DCMAKE_EXE_LINKER_FLAGS="-nodefaultlibs -lc" \ |
| 94 | + -DCMAKE_SHARED_LINKER_FLAGS="$(clang --target=${arch}-fuchsia -print-libgcc-file-name)" \ |
| 95 | + ../runtimes |
| 96 | + hide_output env DESTDIR="${dst}" ninja install |
| 97 | + cd ../.. |
| 98 | +} |
| 99 | + |
| 100 | +build_sysroot "x86_64" |
| 101 | +build_sysroot "aarch64" |
| 102 | + |
| 103 | +rm -rf magenta llvm |
| 104 | + |
| 105 | +for arch in x86_64 aarch64; do |
| 106 | + for tool in clang clang++; do |
| 107 | + cat >/usr/local/bin/${arch}-unknown-fuchsia-${tool} <<EOF |
| 108 | +#!/bin/sh |
| 109 | +${tool} --target=${arch}-unknown-fuchsia --sysroot=/usr/local/${arch}-unknown-fuchsia "\$@" |
| 110 | +EOF |
| 111 | + chmod +x /usr/local/bin/${arch}-unknown-fuchsia-${tool} |
| 112 | + done |
| 113 | + ln -s /usr/local/bin/llvm-ar /usr/local/bin/${arch}-unknown-fuchsia-ar |
| 114 | +done |
0 commit comments