forked from briansmith/ring
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-build-tools.sh
executable file
·168 lines (160 loc) · 4.96 KB
/
install-build-tools.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/usr/bin/env bash
#
# Copyright 2020 Brian Smith.
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
# SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
# OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
set -eux -o pipefail
IFS=$'\n\t'
target=$1
features=${2-}
function install_packages {
sudo apt-get -yq --no-install-suggests --no-install-recommends install "$@"
}
use_clang=
case $target in
--target*android*)
# https://blog.rust-lang.org/2023/01/09/android-ndk-update-r25.html says
# "Going forward the Android platform will target the most recent LTS NDK,
# allowing Rust developers to access platform features sooner. These updates
# should occur yearly and will be announced in release notes." Assume that
# means that we should always prefer to be using the latest 25.x.y version of
# the NDK until the Rust project announces that we should use a higher major
# version number.
#
# TODO: This should probably be implemented as a map of Rust toolchain version
# to NDK version; e.g. our MSRV might (only) support an older NDK than the
# latest stable Rust toolchain.
#
# Keep the following line in sync with the corresponding line in cargo.sh.
ndk_version=25.2.9519653
mkdir -p "${ANDROID_HOME}/licenses"
android_license_file="${ANDROID_HOME}/licenses/android-sdk-license"
accept_android_license=24333f8a63b6825ea9c5514f83c2829b004d1fee
grep --quiet --no-messages "$accept_android_license" "$android_license_file" \
|| echo $accept_android_license >> "$android_license_file"
"${ANDROID_HOME}/cmdline-tools/latest/bin/sdkmanager" "ndk;$ndk_version"
# XXX: Older Rust toolchain versions link with `-lgcc` instead of `-lunwind`;
# see https://github.com/rust-lang/rust/pull/85806.
find -L ${ANDROID_NDK_ROOT:-${ANDROID_HOME}/ndk/$ndk_version} -name libunwind.a \
-execdir sh -c 'echo "INPUT(-lunwind)" > libgcc.a' \;
;;
esac
case $target in
--target=aarch64-unknown-linux-gnu)
# Clang is needed for code coverage.
use_clang=1
install_packages \
qemu-user \
gcc-aarch64-linux-gnu \
libc6-dev-arm64-cross
;;
--target=aarch64-unknown-linux-musl|--target=armv7-unknown-linux-musleabihf)
use_clang=1
install_packages \
qemu-user
;;
--target=arm-unknown-linux-gnueabi)
install_packages \
qemu-user \
gcc-arm-linux-gnueabi \
libc6-dev-armel-cross
;;
--target=arm-unknown-linux-gnueabihf|--target=armv7-unknown-linux-gnueabihf)
install_packages \
qemu-user \
gcc-arm-linux-gnueabihf \
libc6-dev-armhf-cross
;;
--target=i686-unknown-linux-gnu)
use_clang=1
install_packages \
gcc-multilib \
libc6-dev-i386
;;
--target=i686-unknown-linux-musl|--target=x86_64-unknown-linux-musl)
use_clang=1
;;
--target=loongarch64-unknown-linux-gnu)
use_clang=1
;;
--target=mipsel-unknown-linux-gnu)
install_packages \
gcc-mipsel-linux-gnu \
libc6-dev-mipsel-cross \
qemu-user
;;
--target=powerpc-unknown-linux-gnu)
use_clang=1
install_packages \
gcc-powerpc-linux-gnu \
libc6-dev-powerpc-cross \
qemu-user
;;
--target=powerpc64-unknown-linux-gnu)
use_clang=1
install_packages \
gcc-powerpc64-linux-gnu \
libc6-dev-ppc64-cross \
qemu-user
;;
--target=powerpc64le-unknown-linux-gnu)
use_clang=1
install_packages \
gcc-powerpc64le-linux-gnu \
libc6-dev-ppc64el-cross \
qemu-user
;;
--target=riscv64gc-unknown-linux-gnu)
use_clang=1
install_packages \
gcc-riscv64-linux-gnu \
libc6-dev-riscv64-cross \
qemu-user
;;
--target=s390x-unknown-linux-gnu)
# Clang is needed for code coverage.
use_clang=1
install_packages \
qemu-user \
gcc-s390x-linux-gnu \
libc6-dev-s390x-cross
;;
--target=wasm32-unknown-unknown)
cargo install wasm-bindgen-cli --bin wasm-bindgen-test-runner
use_clang=1
;;
--target=wasm32-wasi)
use_clang=1
git clone \
--branch linux-x86_64 \
--depth 1 \
https://github.com/briansmith/ring-toolchain \
target/tools/linux-x86_64
;;
--target=*)
;;
esac
case "$OSTYPE" in
linux*)
ubuntu_codename=$(lsb_release --codename --short)
llvm_version=16
sudo apt-key add mk/llvm-snapshot.gpg.key
sudo add-apt-repository "deb http://apt.llvm.org/$ubuntu_codename/ llvm-toolchain-$ubuntu_codename-$llvm_version main"
sudo apt-get update
# We need to use `llvm-nm` in `mk/check-symbol-prefixes.sh`.
install_packages llvm-$llvm_version
if [ -n "$use_clang" ]; then
install_packages clang-$llvm_version
fi
;;
esac