From d44bd23639731ec3a902fe8699ef996805f0e825 Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Wed, 28 Apr 2021 22:48:23 +0200 Subject: [PATCH] [MonoVM] support building with Android NDK r22 (#51876) Context: https://github.com/android/ndk/issues/1427#issuecomment-759792271 Android NDK r22 changed the tree layout by moving `sysroot` from the NDK root directory to a subdirectory in the toolchains tree and also by removing per-platform library/header directories from their previous location to one under the sysroot above. MonoVM was built using the CMake's built-in Android NDK support which, alas, is not compatible with NDK r22 before CMake version 3.19. It is therefore better to use the Android CMake toolchain definition script shipped with the NDK, so that the build works regardless of CMake version installed on the system. The r22 toolchain will complain about older CMake versions: An old version of CMake is being used that cannot automatically detect compiler attributes. Compiler identification is being bypassed. Some values may be wrong or missing. Update to CMake 3.19 or newer to use CMake's built-in compiler identification. This warning can be safely ignored. --- src/mono/mono.proj | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/mono/mono.proj b/src/mono/mono.proj index 8b05c83515ae0..ff7a87a0a036a 100644 --- a/src/mono/mono.proj +++ b/src/mono/mono.proj @@ -352,13 +352,16 @@ <_MonoRunInitCompiler>false - <_MonoCMakeArgs Include="-DCMAKE_SYSTEM_NAME=Android"/> - <_MonoCMakeArgs Include="-DCMAKE_ANDROID_NDK=$(ANDROID_NDK_ROOT)"/> - <_MonoCMakeArgs Include="-DCMAKE_SYSTEM_VERSION=$(AndroidApiVersion)"/> - <_MonoCMakeArgs Condition="'$(Platform)' == 'arm64'" Include="-DCMAKE_ANDROID_ARCH_ABI=arm64-v8a" /> - <_MonoCMakeArgs Condition="'$(Platform)' == 'arm'" Include="-DCMAKE_ANDROID_ARCH_ABI=armeabi-v7a" /> - <_MonoCMakeArgs Condition="'$(Platform)' == 'x86'" Include="-DCMAKE_ANDROID_ARCH_ABI=x86" /> - <_MonoCMakeArgs Condition="'$(Platform)' == 'x64'" Include="-DCMAKE_ANDROID_ARCH_ABI=x86_64" /> + <_MonoCMakeArgs Include="-DCMAKE_TOOLCHAIN_FILE=$(ANDROID_NDK_ROOT)/build/cmake/android.toolchain.cmake"/> + <_MonoCMakeArgs Include="-DANDROID_NDK=$(ANDROID_NDK_ROOT)"/> + <_MonoCMakeArgs Include="-DANDROID_STL=none"/> + <_MonoCMakeArgs Include="-DANDROID_CPP_FEATURES="no-rtti no-exceptions""/> + <_MonoCMakeArgs Include="-DANDROID_NATIVE_API_LEVEL=$(AndroidApiVersion)"/> + <_MonoCMakeArgs Include="-DANDROID_PLATFORM=android-$(AndroidApiVersion)"/> + <_MonoCMakeArgs Condition="'$(Platform)' == 'arm64'" Include="-DANDROID_ABI=arm64-v8a" /> + <_MonoCMakeArgs Condition="'$(Platform)' == 'arm'" Include="-DANDROID_ABI=armeabi-v7a" /> + <_MonoCMakeArgs Condition="'$(Platform)' == 'x86'" Include="-DANDROID_ABI=x86" /> + <_MonoCMakeArgs Condition="'$(Platform)' == 'x64'" Include="-DANDROID_ABI=x86_64" /> <_MonoCMakeArgs Include="-DENABLE_MINIMAL=ssa,portability,logging" /> <_MonoCMakeArgs Include="-DENABLE_SIGALTSTACK=1"/> <_MonoCMakeArgs Include="-DDISABLE_CRASH_REPORTING=1"/> @@ -527,8 +530,13 @@ + linux-x86_64 + darwin-x86_64 + windows-x86_64 + true - $(ANDROID_NDK_ROOT)/sysroot + $(ANDROID_NDK_ROOT)/sysroot + $(ANDROID_NDK_ROOT)/toolchains/llvm/prebuilt/$(MonoToolchainPrebuiltOS)/sysroot aarch64-v8a-linux-android armv7-none-linux-androideabi i686-none-linux-android @@ -536,9 +544,13 @@ $(MonoObjDir)cross/offsets-$(Platform)-android.h + + <_LibClang Include="$(ANDROID_NDK_ROOT)/toolchains/llvm/prebuilt/$(MonoToolchainPrebuiltOS)/lib64/libclang.so.*"/> + + $(XcodeDir)/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib - $(ANDROID_NDK_ROOT)/toolchains/llvm/prebuilt/linux-x86_64/lib64/libclang.so.9svn + @(_LibClang) c:/dev/LLVM/bin/libclang.dll $(MonoCrossDir)