servo: Merge #18031 - Fix Android build errors on macOS (from jhlin:android-build-on-macos); r=mbrubeck
authorJohn Lin <jolin@mozilla.com>
Fri, 15 Sep 2017 14:05:00 -0500
changeset 665714 f083cad6e8e6e96157ea3648062d62869caf04ef
parent 665713 6159e19a7c0fffd202134027abff82b6e0bd22e6
child 665715 9cc10d12de94bda1dee61a03e0681f5e73df5ee6
push id80148
push userbmo:emilio@crisal.io
push dateFri, 15 Sep 2017 20:59:22 +0000
reviewersmbrubeck
milestone57.0a1
servo: Merge #18031 - Fix Android build errors on macOS (from jhlin:android-build-on-macos); r=mbrubeck - Add sysroot path to environment variable 'CPPFLAGS': When checking C preprocessor, the 'configure' script of libbacktrace uses 'CPPFLAGS' rather than 'CFLAGS' and doesn't get the correct search path. (#15758) This check passes on Linux because the '/lib/cpp' fallback is available there. - Introduce CMake toolchain file for Android cross compiling: CMake needs several variables [1] to cross compile for Android. It works (accidentally) on Linux because cmake-rs sets compilers correctly and binutils for Linux & Android are pretty much the same. [1] https://cmake.org/cmake/help/v3.7/manual/cmake-toolchains.7.html#cross-compiling-for-android-with-the-ndk <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #15758 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [x] These changes do not require tests because it's a fix to build errors. <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: a3b85cbd6cd74090b6e9f09e3d0980045e8f6a1b
servo/python/servo/build_commands.py
servo/support/android/toolchain.cmake
--- a/servo/python/servo/build_commands.py
+++ b/servo/python/servo/build_commands.py
@@ -301,16 +301,19 @@ class MachCommands(CommandBase):
                 "--sysroot", env['ANDROID_SYSROOT'],
                 "-I" + support_include])
             env['CXXFLAGS'] = ' '.join([
                 "--sysroot", env['ANDROID_SYSROOT'],
                 "-I" + support_include,
                 "-I" + cxx_include,
                 "-I" + cxxabi_include])
             env["NDK_ANDROID_VERSION"] = android_platform.replace("android-", "")
+            env['CPPFLAGS'] = ' '.join(["--sysroot", env['ANDROID_SYSROOT']])
+            env["CMAKE_ANDROID_ARCH_ABI"] = self.config["android"]["lib"]
+            env["CMAKE_TOOLCHAIN_FILE"] = path.join(self.android_support_dir(), "toolchain.cmake")
 
         cargo_binary = "cargo" + BIN_SUFFIX
 
         status = call(
             [cargo_binary, "build"] + opts,
             env=env, cwd=self.servo_crate(), verbose=verbose)
         elapsed = time() - build_start
 
new file mode 100644
--- /dev/null
+++ b/servo/support/android/toolchain.cmake
@@ -0,0 +1,4 @@
+set(CMAKE_SYSTEM_NAME Android)
+set(CMAKE_ANDROID_NDK $ENV{ANDROID_NDK})
+set(CMAKE_ANDROID_API $ENV{NDK_ANDROID_VERSION})
+set(CMAKE_ANDROID_ARCH_ABI $ENV{CMAKE_ANDROID_ARCH_ABI})