Auto merge of #13945 - mmatyas:android_libcpp_change, r=larsbergstrom,aneeshusa

Update the Android build system

A huge update for the Android build system, which makes the Android target build again.

There are still some runtime issues, see #13154. CC & created by @larsbergstrom.

Fixes #12562.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13945)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-10-28 16:11:26 -05:00 committed by GitHub
commit b9330151b9
5 changed files with 87 additions and 13 deletions

View file

@ -17,22 +17,46 @@ fn main() {
fn android_main() {
// Get the NDK path from NDK_HOME env.
let ndk_path = env::var("NDK_HOME").ok().expect("Please set the NDK_HOME environment variable");
let ndk_path = env::var("ANDROID_NDK").ok().expect("Please set the ANDROID_NDK environment variable");
let ndk_path = Path::new(&ndk_path);
// Get the standalone NDK path from NDK_STANDALONE env.
let standalone_path = env::var("NDK_STANDALONE").ok().expect("Please set the NDK_STANDALONE environment variable");
let standalone_path = Path::new(&standalone_path);
// Build up the path to the NDK compilers
// Options for host are: "linux-x86_64" "linux-x86" "darwin-x86_64" "darwin-x86"
// per: https://android.googlesource.com/platform/ndk/+/ics-mr0/docs/STANDALONE-TOOLCHAIN.html
// Get the standalone NDK path from NDK_STANDALONE env.
let host = env::var("HOST").unwrap();
let google_host = match host.as_ref() {
"i686-unknown-linux-gnu" => "linux-x86",
"x86_64-apple-darwin" => "darwin-x86_64",
"x86_64-unknown-linux-gnu" => "linux-x86_64",
_ => 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("x86") {
"arch-x86"
} else if target.contains("mips") {
"arch-mips"
} else {
panic!("Invalid target architecture {}", target);
};
// 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(standalone_path.join("bin").join("arm-linux-androideabi-gcc"))
if Command::new(toolchain_path.join("bin").join("arm-linux-androideabi-gcc"))
.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))
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.status().unwrap().code().unwrap() != 0
@ -42,7 +66,7 @@ fn android_main() {
}
// compiling libandroid_native_app_glue.a
if Command::new(standalone_path.join("bin").join("arm-linux-androideabi-ar"))
if Command::new(toolchain_path.join("bin").join("arm-linux-androideabi-ar"))
.arg("rcs")
.arg(directory.join("libandroid_native_app_glue.a"))
.arg(directory.join("android_native_app_glue.o"))

View file

@ -9,7 +9,25 @@ set -o nounset
set -o pipefail
TARGET_DIR="${OUT_DIR}/../../.."
arm-linux-androideabi-gcc "${@}" \
"${LDFLAGS-}" -lc -shared \
-o "${TARGET_DIR}/libservo.so"
touch "${TARGET_DIR}/servo"
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
ANDROID_CPU_ARCH_DIR=armeabi
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}"
"${ANDROID_TOOLCHAIN}/arm-linux-androideabi-gcc" \
--sysroot="${ANDROID_SYSROOT}" -L "${ANDROID_CXX_LIBS}" "${@}" -lc++ \
-o "${TARGET_DIR}/libservo.so" -shared && touch "${TARGET_DIR}/servo"