Skip to content

Commit

Permalink
Auto merge of #18031 - jhlin:android-build-on-macos, r=mbrubeck
Browse files Browse the repository at this point in the history
Fix Android build errors on macOS.

- 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. -->

<!-- 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/18031)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Sep 15, 2017
2 parents fb00fc2 + fbdb209 commit a3b85cb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions python/servo/build_commands.py
Expand Up @@ -306,6 +306,9 @@ def build(self, target=None, release=False, dev=False, jobs=None,
"-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

Expand Down
4 changes: 4 additions & 0 deletions 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})

0 comments on commit a3b85cb

Please sign in to comment.