diff --git a/zorg/buildbot/builders/sanitizers/buildbot_android.sh b/zorg/buildbot/builders/sanitizers/buildbot_android.sh --- a/zorg/buildbot/builders/sanitizers/buildbot_android.sh +++ b/zorg/buildbot/builders/sanitizers/buildbot_android.sh @@ -25,7 +25,7 @@ clobber -download_android_tools r16 +download_android_tools r21 # Stage 1 diff --git a/zorg/buildbot/builders/sanitizers/buildbot_android_functions.sh b/zorg/buildbot/builders/sanitizers/buildbot_android_functions.sh --- a/zorg/buildbot/builders/sanitizers/buildbot_android_functions.sh +++ b/zorg/buildbot/builders/sanitizers/buildbot_android_functions.sh @@ -46,13 +46,41 @@ ninja -C llvm_build64 || echo @@@STEP_FAILURE@@@ } +function check_android_api { + if [ -z ${ANDROID_API+x} ]; then + # If ANDROID_API was not specified, then use the one from the device. + ANDROID_API=$(adb shell getprop ro.build.version.sdk) + fi + + # Re-adjust it since the current NDK supports API levels in the range [21,29]. + if [[ $ANDROID_API -gt 29 || $ANDROID_API -lt 21 ]]; then + echo "API level $ANDROID_API is not supported." + ANDROID_API=29 + fi + + echo "Building for Android API level $ANDROID_API" +} + function build_android_ndk { local NDK_DIR=android_ndk local _arch=$1 local _ndk_arch=$2 + + check_android_api if [[ ! -d $NDK_DIR/standalone-$_arch ]] ; then echo @@@BUILD_STEP building Android NDK for $_arch@@@ - $NDK_DIR/build/tools/make_standalone_toolchain.py --api 24 --force --arch $_ndk_arch --stl=libc++ --install-dir $NDK_DIR/standalone-$_arch + $NDK_DIR/build/tools/make_standalone_toolchain.py --api $ANDROID_API --force --arch $_ndk_arch --stl=libc++ --install-dir $NDK_DIR/standalone-$_arch + + # Move the [shared] objects and libraries back to expected sysroot layout. + # Or it won't be able to find -lc++ + local _source=$ROOT/$NDK_DIR/standalone-$_arch/sysroot/usr/lib/$_arch-linux-android + local _target=$ROOT/$NDK_DIR/standalone-$_arch/sysroot/usr/lib + mv $_source/*.so $_target/. + mv $_source/*.a $_target/. + + mv $_source/$ANDROID_API/*.so $_target/. + mv $_source/$ANDROID_API/*.o $_target/. + mv $_source/$ANDROID_API/*.a $_target/. fi } @@ -64,8 +92,10 @@ local ANDROID_LIBRARY_OUTPUT_DIR=$(ls -d $ROOT/llvm_build64/lib/clang/* | tail -1) local ANDROID_EXEC_OUTPUT_DIR=$ROOT/llvm_build64/bin local ANDROID_FLAGS="--target=$_triple --sysroot=$ANDROID_TOOLCHAIN/sysroot -B$ANDROID_TOOLCHAIN" - local ANDROID_CXX_FLAGS="$ANDROID_FLAGS -stdlib=libstdc++" + local ANDROID_CXX_FLAGS="$ANDROID_FLAGS -stdlib=libc++ -I/$ANDROID_TOOLCHAIN/sysroot/usr/include/c++/v1" + local CLANG_PATH=$ROOT/llvm_build64/bin/clang + local CLANGXX_PATH=$ROOT/llvm_build64/bin/clang++ # Always clobber android build tree. # It has a hidden dependency on clang (through CXX) which is not known to # the build system. @@ -76,8 +106,8 @@ (cd llvm_build_android_$_arch && cmake \ -DLLVM_ENABLE_WERROR=OFF \ - -DCMAKE_C_COMPILER=$ROOT/llvm_build64/bin/clang \ - -DCMAKE_CXX_COMPILER=$ROOT/llvm_build64/bin/clang++ \ + -DCMAKE_C_COMPILER=$CLANG_PATH \ + -DCMAKE_CXX_COMPILER=$CLANGXX_PATH \ -DCMAKE_ASM_FLAGS="$ANDROID_FLAGS" \ -DCMAKE_C_FLAGS="$ANDROID_FLAGS" \ -DCMAKE_CXX_FLAGS="$ANDROID_CXX_FLAGS" \ @@ -91,8 +121,8 @@ local COMPILER_RT_OPTIONS="$(readlink -f $LLVM/../compiler-rt)" (cd compiler_rt_build_android_$_arch && cmake \ - -DCMAKE_C_COMPILER=$ROOT/llvm_build64/bin/clang \ - -DCMAKE_CXX_COMPILER=$ROOT/llvm_build64/bin/clang++ \ + -DCMAKE_C_COMPILER=$CLANG_PATH \ + -DCMAKE_CXX_COMPILER=$CLANGXX_PATH \ -DLLVM_CONFIG_PATH=$ROOT/llvm_build64/bin/llvm-config \ -DCOMPILER_RT_BUILD_BUILTINS=OFF \ -DCOMPILER_RT_INCLUDE_TESTS=ON \