forked from mozilla/application-services
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_toolchains_local.sh
executable file
·55 lines (47 loc) · 1.91 KB
/
setup_toolchains_local.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
#!/usr/bin/env bash
# This script sets up the necessary toolchains to build for Android.
set -eu
# Keep these 3 in sync.
TARGET_ARCHS=("x86" "arm64" "arm")
RUST_TARGETS=("i686-linux-android" "armv7-linux-androideabi" "aarch64-linux-android")
CLANG_BINS=("i686-linux-android-clang" "arm-linux-androideabi-clang" "aarch64-linux-android-clang")
if [ "$#" -ne 1 ]; then
echo "Usage:"
echo "./setup_toolchains_local.sh <ANDROID_NDK_HOME>"
exit 1
fi
ANDROID_NDK_HOME=$1
source "$(dirname "$0")/android_defaults.sh"
mkdir -p $ANDROID_NDK_TOOLCHAIN_DIR
echo "Installing toolchains for the following architectures: ${TARGET_ARCHS[@]}."
echo "The toolchains will be installed in $ANDROID_NDK_TOOLCHAIN_DIR (ANDROID_NDK_TOOLCHAIN_DIR)."
echo "The Android API version is set to $ANDROID_NDK_API_VERSION (ANDROID_NDK_API_VERSION)."
echo ""
# Toolchains installation
for ARCH in "${TARGET_ARCHS[@]}"; do
if [ ! -d "$ANDROID_NDK_TOOLCHAIN_DIR/$ARCH-$ANDROID_NDK_API_VERSION" ]; then
echo "Installing $ARCH toolchain..."
python "$ANDROID_NDK_HOME/build/tools/make_standalone_toolchain.py" --arch="$ARCH" --api="$ANDROID_NDK_API_VERSION" --install-dir="$ANDROID_NDK_TOOLCHAIN_DIR/$ARCH-$ANDROID_NDK_API_VERSION" --deprecated-headers --force
else
echo "$ARCH toolchain already exists. Skipping installation."
fi
done
# Setup cargo linkers
CONFIG_FILE="$(dirname "$0")/../.cargo/config"
read -p "Would you like to set-up the toolchain linkers in .cargo/config? (you should say yes) " -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
exit 0
fi
mkdir -p "$(dirname "$0")/../.cargo"
echo -n "" > $CONFIG_FILE # Clear the file first
for i in "${!TARGET_ARCHS[@]}"; do
ARCH=${TARGET_ARCHS[$i]}
RUST_TARGET=${RUST_TARGETS[$i]}
CLANG_BIN=${CLANG_BINS[$i]}
echo "[target.$RUST_TARGET]
linker = \"$ANDROID_NDK_TOOLCHAIN_DIR/$ARCH-$ANDROID_NDK_API_VERSION/bin/$CLANG_BIN\"
" >> $CONFIG_FILE
done
echo "Cargo config written to $CONFIG_FILE."