Support for Android armv7 and aarch64 target triples

This commit is contained in:
Imanol Fernandez 2017-05-08 14:26:07 +02:00
parent f6bd158fd4
commit 01228282cd
9 changed files with 145 additions and 34 deletions

View file

@ -1,7 +1,15 @@
[target.arm-linux-androideabi]
linker = "./fake-ld.sh"
linker = "./fake-ld-arm.sh"
ar = "arm-linux-androideabi-ar"
[target.armv7-linux-androideabi]
linker = "./fake-ld-armv7.sh"
ar = "arm-linux-androideabi-ar"
[target.aarch64-linux-android]
linker = "./fake-ld-arm64.sh"
ar = "aarch64-linux-android-ar"
[target.arm-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"
ar = "arm-linux-gnueabihf-ar"

View file

@ -32,13 +32,11 @@ fn android_main() {
_ => panic!("Unknown support android cross-compile host: {}", host)
};
let toolchain_path = ndk_path.join("toolchains").join("arm-linux-androideabi-4.9").join("prebuilt").
join(google_host);
println!("toolchain path is: {}", toolchain_path.to_str().unwrap());
let target = env::var("TARGET").unwrap();
let arch = if target.contains("arm") {
"arch-arm"
} else if target.contains("aarch64") {
"arch-arm64"
} else if target.contains("x86") {
"arch-x86"
} else if target.contains("mips") {
@ -47,16 +45,32 @@ fn android_main() {
panic!("Invalid target architecture {}", target);
};
let platform = if target.contains("aarch64") {
"android-21"
} else {
"android-18"
};
let toolchain = if target.contains("armv7") {
"arm-linux-androideabi".into()
} else {
target
};
let toolchain_path = ndk_path.join("toolchains").join(format!("{}-4.9", toolchain)).join("prebuilt").
join(google_host);
println!("toolchain path is: {}", toolchain_path.to_str().unwrap());
// Get the output directory.
let out_dir = env::var("OUT_DIR").ok().expect("Cargo should have set the OUT_DIR environment variable");
let directory = Path::new(&out_dir);
// compiling android_native_app_glue.c
if Command::new(toolchain_path.join("bin").join("arm-linux-androideabi-gcc"))
if Command::new(toolchain_path.join("bin").join(format!("{}-gcc", toolchain)))
.arg(ndk_path.join("sources").join("android").join("native_app_glue").join("android_native_app_glue.c"))
.arg("-c")
.arg("-o").arg(directory.join("android_native_app_glue.o"))
.arg("--sysroot").arg(ndk_path.join("platforms").join("android-18").join(arch))
.arg("--sysroot").arg(ndk_path.join("platforms").join(platform).join(arch))
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.status().unwrap().code().unwrap() != 0

14
ports/servo/fake-ld-arm.sh Executable file
View file

@ -0,0 +1,14 @@
#!/usr/bin/env bash
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
set -o errexit
set -o nounset
set -o pipefail
source fake-ld.sh
export _GCC_PARAMS="${@}"
call_gcc "arch-arm" "arm-linux-androideabi-4.9" "android-18" "armeabi"

14
ports/servo/fake-ld-arm64.sh Executable file
View file

@ -0,0 +1,14 @@
#!/usr/bin/env bash
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
set -o errexit
set -o nounset
set -o pipefail
source fake-ld.sh
export _GCC_PARAMS="${@}"
call_gcc "arch-arm64" "aarch64-linux-android-4.9" "android-21" "arm64-v8a"

14
ports/servo/fake-ld-armv7.sh Executable file
View file

@ -0,0 +1,14 @@
#!/usr/bin/env bash
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
set -o errexit
set -o nounset
set -o pipefail
source fake-ld.sh
export _GCC_PARAMS="${@}"
call_gcc "arch-arm" "arm-linux-androideabi-4.9" "android-18" "armeabi-v7a"

View file

@ -8,26 +8,31 @@ set -o errexit
set -o nounset
set -o pipefail
TARGET_DIR="${OUT_DIR}/../../.."
call_gcc()
{
TARGET_DIR="${OUT_DIR}/../../.."
export _ANDROID_ARCH=arch-arm
export ANDROID_SYSROOT="${ANDROID_NDK}/platforms/android-18/${_ANDROID_ARCH}"
export _ANDROID_EABI=arm-linux-androideabi-4.9
ANDROID_TOOLCHAIN=""
for host in "linux-x86_64" "linux-x86" "darwin-x86_64" "darwin-x86"; do
if [[ -d "${ANDROID_NDK}/toolchains/${_ANDROID_EABI}/prebuilt/${host}/bin" ]]; then
ANDROID_TOOLCHAIN="${ANDROID_NDK}/toolchains/${_ANDROID_EABI}/prebuilt/${host}/bin"
break
fi
done
export _ANDROID_ARCH=$1
export _ANDROID_EABI=$2
export _ANDROID_PLATFORM=$3
export ANDROID_SYSROOT="${ANDROID_NDK}/platforms/${_ANDROID_PLATFORM}/${_ANDROID_ARCH}"
ANDROID_TOOLCHAIN=""
for host in "linux-x86_64" "linux-x86" "darwin-x86_64" "darwin-x86"; do
if [[ -d "${ANDROID_NDK}/toolchains/${_ANDROID_EABI}/prebuilt/${host}/bin" ]]; then
ANDROID_TOOLCHAIN="${ANDROID_NDK}/toolchains/${_ANDROID_EABI}/prebuilt/${host}/bin"
break
fi
done
ANDROID_CPU_ARCH_DIR=armeabi
ANDROID_CXX_LIBS="${ANDROID_NDK}/sources/cxx-stl/llvm-libc++/libs/${ANDROID_CPU_ARCH_DIR}"
ANDROID_CPU_ARCH_DIR=$4
ANDROID_CXX_LIBS="${ANDROID_NDK}/sources/cxx-stl/llvm-libc++/libs/${ANDROID_CPU_ARCH_DIR}"
echo "toolchain: ${ANDROID_TOOLCHAIN}"
echo "libs dir: ${ANDROID_CXX_LIBS}"
echo "sysroot: ${ANDROID_SYSROOT}"
echo "toolchain: ${ANDROID_TOOLCHAIN}"
echo "libs dir: ${ANDROID_CXX_LIBS}"
echo "sysroot: ${ANDROID_SYSROOT}"
echo "targetdir: ${ANDROID_CXX_LIBS}"
"${ANDROID_TOOLCHAIN}/arm-linux-androideabi-gcc" \
--sysroot="${ANDROID_SYSROOT}" -L "${ANDROID_CXX_LIBS}" "${@}" -lc++ \
-o "${TARGET_DIR}/libservo.so" -shared && touch "${TARGET_DIR}/servo"
"${ANDROID_TOOLCHAIN}/arm-linux-androideabi-gcc" \
--sysroot="${ANDROID_SYSROOT}" -L "${ANDROID_CXX_LIBS}" ${_GCC_PARAMS} -lc++ \
-o "${TARGET_DIR}/libservo.so" -shared && touch "${TARGET_DIR}/servo"
}