I could probably break this commit into more pieces.
---
This patch adds libc++ support for Android L (Android 5.0+) and up,
tested using the Android team's current compiler, a recent version of
the AOSP sysroot, and the x86[-64] Android Emulator.
CMake and Lit Configuration:
Add runtimes/cmake/android/Arch-${ARCH}.cmake files that configure CMake
to cross-compile to Android without using CMake's built-in NDK support
(which only works with an actual packaged NDK).
Add libcxx/cmake/caches/AndroidNDK.cmake that builds and tests libc++
(and libc++abi) for Android. This file configures libc++ to match what
the NDK distributes, e.g.:
- libc++_shared.so (includes libc++abi objects, there is no
libc++abi.so). libunwind is linked statically but not exported.
- libc++_static.a (does not include libc++abi) and libc++abi.a
- `std::__ndk1` namespace
- All the libraries are built with `__ANDROID_API__=21`, even when they
are linked to something targeting a higher API level.
(However, when the Android LLVM team builds these components, they do
not use these CMake cache files. Instead they use Python scripts to
configure the builds. See
https://android.googlesource.com/toolchain/llvm_android/.)
Add llvm-libc++[abi].android-ndk.cfg.in files that test the Android
NDK's libc++_shared.so. These files can target old or new Android
devices. The Android LLVM team uses these test files to test libc++ for
both arm/arm64 and x86/x86_64 architectures.
The Android testing mode works by setting %{executor} to adb_run.py,
which uses `adb push` and `adb shell` to run tests remotely. adb_run.py
always runs tests as the "shell" user even on an old emulator where "adb
unroot" doesn't work. The script has workarounds for old Android
devices. The script uses a Unix domain socket on the host
(--job-limit-socket) to restrict concurrent adb invocations. Compiling
the tests is a major part of libc++ testing run-time, so it's desirable
to exploit all the host cores without overburdening the test devices,
which can have far fewer cores.
BuildKite CI:
Add a builder to run-buildbot, `android-ndk-*`, that uses Android Clang
and an Android sysroot to build libc++, then starts an Android emulator
container to run tests.
Run the emulator and an adb server in a separate Docker container
(libcxx-ci-android-emulator), and create a separate Docker image for
each emulator OS system image. Set ADB_SERVER_SOCKET to connect to the
container's adb server. Running the only adb server inside the container
makes cleanup more reliable between test runs, e.g. the adb client
doesn't create a `~/.android` directory and the adb server can be
restarted along with the emulator using docker stop/run. (N.B. The
emulator insists on connecting to an adb server and will start one
itself if it can't connect to one.)
The suffix to the android-ndk-* job is a label that concisely specifies
an Android SDK emulator image. e.g.:
- "system-images;android-21;default;x86" ==> 21-def-x86
- "system-images;android-33;google_apis;x86_64" ==> 33-goog-x86_64
Fixes: https://github.com/llvm/llvm-project/issues/69270
Differential Revision: https://reviews.llvm.org/D139147
39 lines
1.9 KiB
CMake
39 lines
1.9 KiB
CMake
# Build libc++abi and libc++ closely resembling what is shipped in the Android
|
|
# NDK.
|
|
|
|
# The NDK names the libraries libc++_shared.so and libc++_static.a. Using the
|
|
# libc++_shared.so soname ensures that the library doesn't interact with the
|
|
# libc++.so in /system/lib[64].
|
|
set(LIBCXX_SHARED_OUTPUT_NAME c++_shared CACHE STRING "")
|
|
set(LIBCXX_STATIC_OUTPUT_NAME c++_static CACHE STRING "")
|
|
|
|
# The NDK libc++ uses a special namespace to help isolate its symbols from those
|
|
# in the platform's STL (e.g. /system/lib[64]/libc++.so, but possibly stlport on
|
|
# older versions of Android).
|
|
set(LIBCXX_ABI_VERSION 1 CACHE STRING "")
|
|
set(LIBCXX_ABI_NAMESPACE __ndk1 CACHE STRING "")
|
|
|
|
# CMake doesn't add a version suffix to an Android shared object filename,
|
|
# (because CMAKE_PLATFORM_NO_VERSIONED_SONAME is set), so it writes both a
|
|
# libc++_shared.so ELF file and a libc++_shared.so linker script to the same
|
|
# output path (the script clobbers the binary). Turn off the linker script.
|
|
set(LIBCXX_ENABLE_ABI_LINKER_SCRIPT OFF CACHE BOOL "")
|
|
|
|
set(LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY ON CACHE BOOL "")
|
|
set(LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
|
|
|
|
# Clang links libc++ by default, but it doesn't exist yet. The libc++ CMake
|
|
# files specify -nostdlib++ to avoid this problem, but CMake's default "compiler
|
|
# works" testing doesn't pass that flag, so force those tests to pass.
|
|
set(CMAKE_C_COMPILER_WORKS ON CACHE BOOL "")
|
|
set(CMAKE_CXX_COMPILER_WORKS ON CACHE BOOL "")
|
|
|
|
# Use adb to push tests to a locally-connected device (e.g. emulator) and run
|
|
# them.
|
|
set(LIBCXX_TEST_CONFIG "llvm-libc++-android-ndk.cfg.in" CACHE STRING "")
|
|
set(LIBCXXABI_TEST_CONFIG "llvm-libc++abi-android-ndk.cfg.in" CACHE STRING "")
|
|
|
|
# CMAKE_SOURCE_DIR refers to the "<monorepo>/runtimes" directory.
|
|
set(LIBCXX_EXECUTOR "${CMAKE_SOURCE_DIR}/../libcxx/utils/adb_run.py" CACHE STRING "")
|
|
set(LIBCXXABI_EXECUTOR "${LIBCXX_EXECUTOR}" CACHE STRING "")
|