-
Notifications
You must be signed in to change notification settings - Fork 715
/
Copy pathinstall-build-tools.sh
executable file
·240 lines (230 loc) · 6.26 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#!/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'
toolchain=stable
for arg in $*; do
case $arg in
--target=*)
target=${arg#*=}
;;
+*)
toolchain=${arg#*+}
;;
*)
;;
esac
done
function install_packages {
sudo apt-get -yq --no-install-suggests --no-install-recommends install "$@"
}
use_clang=
case ${target-} in
*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."
#
# https://github.com/actions/runner-images/issues/10614 indicates that GitHub
# actions doesn't intend to keep unsupported versions around, so in general
# we'll end up only supporting the latest NDK even for MSRV builds.
#
# https://developer.android.com/ndk/guides/other_build_systems explains how
# to set the API level.
#
# Keep the following line in sync with the corresponding line in cargo.sh.
#
ndk_version=27.1.12297006
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
aarch64-apple-tvos | aarch64-apple-tvos-sim | \
aarch64-apple-visionos | aarch64-apple-visionos-sim | \
aarch64-apple-watchos | aarch64-apple-watchos-sim)
build_std=1
;;
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
;;
aarch64-unknown-linux-musl|armv7-unknown-linux-musleabihf)
use_clang=1
install_packages \
qemu-user
;;
arm-unknown-linux-gnueabi)
install_packages \
qemu-user \
gcc-arm-linux-gnueabi \
libc6-dev-armel-cross
;;
arm-unknown-linux-gnueabihf|armv7-unknown-linux-gnueabihf)
install_packages \
qemu-user \
gcc-arm-linux-gnueabihf \
libc6-dev-armhf-cross
;;
i686-unknown-linux-gnu)
use_clang=1
install_packages \
gcc-multilib \
libc6-dev-i386
if [ -n "${RING_CPU_MODEL-}" ]; then
install_packages qemu-user
fi
;;
i686-unknown-linux-musl|x86_64-unknown-linux-musl)
use_clang=1
;;
loongarch64-unknown-linux-gnu)
use_clang=1
install_packages \
gcc-14-loongarch64-linux-gnu \
libc6-dev-loong64-cross \
qemu-user
;;
loongarch64-unknown-linux-musl)
use_clang=1
install_packages \
qemu-user
;;
mips-unknown-linux-gnu)
install_packages \
gcc-mips-linux-gnu \
libc6-dev-mips-cross \
qemu-user
;;
mips64-unknown-linux-gnuabi64)
install_packages \
gcc-mips64-linux-gnuabi64 \
libc6-dev-mips64-cross \
qemu-user
;;
mips64el-unknown-linux-gnuabi64)
install_packages \
gcc-mips64el-linux-gnuabi64 \
libc6-dev-mips64el-cross \
qemu-user
;;
mipsel-unknown-linux-gnu)
install_packages \
gcc-mipsel-linux-gnu \
libc6-dev-mipsel-cross \
qemu-user
;;
powerpc-unknown-linux-gnu)
use_clang=1
install_packages \
gcc-powerpc-linux-gnu \
libc6-dev-powerpc-cross \
qemu-user
;;
powerpc64-unknown-linux-gnu)
use_clang=1
install_packages \
gcc-powerpc64-linux-gnu \
libc6-dev-ppc64-cross \
qemu-user
;;
powerpc64le-unknown-linux-gnu)
use_clang=1
install_packages \
gcc-powerpc64le-linux-gnu \
libc6-dev-ppc64el-cross \
qemu-user
;;
riscv64gc-unknown-linux-gnu)
use_clang=1
install_packages \
gcc-riscv64-linux-gnu \
libc6-dev-riscv64-cross \
qemu-user
;;
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
;;
sparc64-unknown-linux-gnu)
install_packages \
qemu-user \
gcc-sparc64-linux-gnu \
libc6-dev-sparc64-cross
;;
wasm32-unknown-unknown)
cargo install wasm-bindgen-cli --bin wasm-bindgen-test-runner
use_clang=1
;;
wasm32-wasi|wasm32-wasip1|wasm32-wasip2)
use_clang=1
git clone \
--branch linux-x86_64 \
--depth 1 \
https://github.com/briansmith/ring-toolchain \
target/tools/linux-x86_64
;;
x86_64-unknown-linux-gnu)
if [ -n "${RING_CPU_MODEL-}" ]; then
install_packages qemu-user
fi
;;
*)
;;
esac
if [ -n "${RING_COVERAGE-}" ]; then
use_clang=1
fi
case "${OSTYPE-}" in
linux*)
if [ -n "$use_clang" ]; then
ubuntu_codename=$(lsb_release --codename --short)
llvm_version=19
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
install_packages clang-$llvm_version llvm-$llvm_version
fi
;;
esac
rustup toolchain install --no-self-update --profile=minimal ${toolchain}
if [ -n "${target-}" ]; then
if [ -n "${build_std-}" ]; then
rustup +${toolchain} component add rust-src
else
rustup +${toolchain} target add ${target}
fi
fi
if [ -n "${RING_COVERAGE-}" ]; then
rustup +${toolchain} component add llvm-tools-preview
fi