Use Android NDK 25 since that's GitHub Actions is moving to. SDK level is the minimum supported, and there are no longer target-specific allases for `llvm-ar`; update cargo.sh accordingly. Use the environment variables recommended by the Android documentation. Work around compatibility issue with Rust and Android NDKs. Remove out-of-date documentation aboud building for Android.
94 lines
3.1 KiB
Bash
Executable File
94 lines
3.1 KiB
Bash
Executable File
#!/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*)
|
|
mkdir -p "${ANDROID_HOME}/licenses"
|
|
ndk_version=25.1.8937393
|
|
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"
|
|
|
|
ANDROID_NDK_ROOT=
|
|
# 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-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=wasm32-unknown-unknown)
|
|
# The version of wasm-bindgen-cli must match the wasm-bindgen version.
|
|
wasm_bindgen_version=$(cargo metadata --format-version 1 | jq -r '.packages | map(select( .name == "wasm-bindgen")) | map(.version) | .[0]')
|
|
cargo install wasm-bindgen-cli --vers "$wasm_bindgen_version" --bin wasm-bindgen-test-runner
|
|
use_clang=1
|
|
;;
|
|
--target=*)
|
|
;;
|
|
esac
|
|
|
|
if [ -n "$use_clang" ]; then
|
|
# https://github.com/rustls/rustls/pull/1009 upgraded Rust's LLVM version to
|
|
# 14
|
|
llvm_version=14
|
|
sudo apt-key add mk/llvm-snapshot.gpg.key
|
|
sudo add-apt-repository "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-$llvm_version main"
|
|
sudo apt-get update
|
|
install_packages clang-$llvm_version llvm-$llvm_version
|
|
fi
|