forked from ActivityWatch/aw-server-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-ndk.sh
executable file
·66 lines (54 loc) · 2.6 KB
/
install-ndk.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
#!/bin/bash
# Based on https://mozilla.github.io/firefox-browser-architecture/experiments/2017-09-21-rust-on-android.html
# Depended on by aw-android/scripts/setup-rust-with-ndk.sh
set -e;
NDK_VERSION=r25c
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
project_path="$(readlink -f "$script_dir/.")"
platform="$(uname -s | tr '[:upper:]' '[:lower:]')"
if [ -z "$ANDROID_NDK_HOME" ]; then
if [ -d `pwd`/"NDK" ]; then
echo "Found NDK folder in root, using."
else
echo 'ANDROID_NDK_HOME not set, downloading NDK...';
# Download Linux NDK or macOS NDK, depending on OS
wget --no-verbose -O android-ndk.zip https://dl.google.com/android/repository/android-ndk-$NDK_VERSION-$platform.zip;
unzip -q -d NDK android-ndk.zip;
ls NDK;
mv NDK/*/* NDK/;
fi
ANDROID_NDK_HOME=`pwd`/NDK;
fi
# Needed since dependency 'ring' doesn't respect .cargo/config
echo "Setting up toolchain binary symlinks..."
NDK_TOOLCHAIN_BIN=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/$platform-x86_64/bin
for arch in \
'aarch64' \
'x86_64' \
'i686' \
; do
ln -s -f $NDK_TOOLCHAIN_BIN/$arch-linux-android26-clang $NDK_TOOLCHAIN_BIN/$arch-linux-android-clang
done
# This has a slightly different path from the ones above
ln -s -f $NDK_TOOLCHAIN_BIN/armv7a-linux-androideabi26-clang $NDK_TOOLCHAIN_BIN/armv7a-linux-androideabi-clang
ln -s -f $NDK_TOOLCHAIN_BIN/armv7a-linux-androideabi26-clang $NDK_TOOLCHAIN_BIN/arm-linux-androideabi-clang
# Add to Rust
echo "Setting up Rust toolchains..."
rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android;
# Creates cargo config
echo "Creating cargo config..."
mkdir -p $project_path/.cargo
echo "
[target.aarch64-linux-android]
ar = '$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/$platform-x86_64/bin/llvm-ar'
linker = '$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/$platform-x86_64/bin/aarch64-linux-android26-clang'
[target.armv7-linux-androideabi]
ar = '$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/$platform-x86_64/bin/llvm-ar'
linker = '$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/$platform-x86_64/bin/armv7a-linux-androideabi-clang'
[target.i686-linux-android]
ar = '$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/$platform-x86_64/bin/llvm-ar'
linker = '$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/$platform-x86_64/bin/i686-linux-android26-clang'
[target.x86_64-linux-android]
ar = '$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/$platform-x86_64/bin/llvm-ar'
linker = '$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/$platform-x86_64/bin/x86_64-linux-android26-clang'
" > $project_path/.cargo/config