From 90c22cb90bf3198381d4e41a50d4459d4b4e678e Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Fri, 6 Dec 2024 13:55:45 +0100 Subject: [PATCH 01/11] Beginnings of native Android build --- Directory.Build.props | 2 +- eng/native/build-commons.sh | 4 +++- src/coreclr/minipal/Unix/doublemapping.cpp | 3 +++ src/coreclr/runtime.proj | 5 +++-- src/native/external/libunwind_extras/CMakeLists.txt | 9 +++++++++ 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index f30877332027d..dcac66ca23720 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -68,7 +68,7 @@ - src/tasks/MobileBuildTasks/Apple/AppleProject.cs - https://github.com/dotnet/sdk repo > src/Installer/redist-installer/targets/GeneratePKG.targets --> - 21 + 28 12.2 12.2 12.0 diff --git a/eng/native/build-commons.sh b/eng/native/build-commons.sh index 2cf33442a9325..f3195336bbaea 100755 --- a/eng/native/build-commons.sh +++ b/eng/native/build-commons.sh @@ -79,6 +79,8 @@ build_native() fi if [[ "$targetOS" == android || "$targetOS" == linux-bionic ]]; then + # Keep in sync with $(AndroidApiLevelMin) in Directory.Build.props in the repository rooot + local ANDROID_API_LEVEL=28 if [[ -z "$ANDROID_NDK_ROOT" ]]; then echo "Error: You need to set the ANDROID_NDK_ROOT environment variable pointing to the Android NDK root." exit 1 @@ -87,7 +89,7 @@ build_native() cmakeArgs="-C $__RepoRootDir/eng/native/tryrun.cmake $cmakeArgs" # keep ANDROID_PLATFORM in sync with SetOSTargetMinVersions in the root Directory.Build.props - cmakeArgs="-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_ROOT/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=android-21 $cmakeArgs" + cmakeArgs="-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_ROOT/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=android-${ANDROID_API_LEVEL} -DANDROID_NATIVE_API_LEVEL=${ANDROID_API_LEVEL} $cmakeArgs" # Don't try to set CC/CXX in init-compiler.sh - it's handled in android.toolchain.cmake already __Compiler="default" diff --git a/src/coreclr/minipal/Unix/doublemapping.cpp b/src/coreclr/minipal/Unix/doublemapping.cpp index ba43e72a0c673..261d3a2cf9499 100644 --- a/src/coreclr/minipal/Unix/doublemapping.cpp +++ b/src/coreclr/minipal/Unix/doublemapping.cpp @@ -54,6 +54,8 @@ bool VMToOSInterface::CreateDoubleMemoryMapper(void** pHandle, size_t *pMaxExecu int fd = -1; #endif +#ifndef TARGET_ANDROID + // Bionic doesn't have shm_{open,unlink} // POSIX fallback if (fd == -1) { @@ -64,6 +66,7 @@ bool VMToOSInterface::CreateDoubleMemoryMapper(void** pHandle, size_t *pMaxExecu fd = shm_open(name, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW, 0600); shm_unlink(name); } +#endif // !TARGET_ANDROID if (fd == -1) { diff --git a/src/coreclr/runtime.proj b/src/coreclr/runtime.proj index 12e655d9fdedb..a2e704b5152ab 100644 --- a/src/coreclr/runtime.proj +++ b/src/coreclr/runtime.proj @@ -78,9 +78,10 @@ <_CoreClrBuildArg Include="-DCMAKE_TOOLCHAIN_FILE=$(ANDROID_NDK_ROOT)/build/cmake/android.toolchain.cmake"/> <_CoreClrBuildArg Include="-DANDROID_NDK=$(ANDROID_NDK_ROOT)"/> - <_CoreClrBuildArg Include="-DANDROID_STL=none"/> - <_CoreClrBuildArg Include="-DANDROID_CPP_FEATURES="no-rtti no-exceptions""/> + <_CoreClrBuildArg Include="-DANDROID_STL=c++_static"/> + <_CoreClrBuildArg Include="-DANDROID_CPP_FEATURES="no-rtti exceptions""/> <_CoreClrBuildArg Include="-DANDROID_PLATFORM=android-$(AndroidApiLevelMin)"/> + <_CoreClrBuildArg Include="-DANDROID_NATIVE_API_LEVEL=$(AndroidApiLevelMin)"/> <_CoreClrBuildArg Condition="'$(Platform)' == 'arm64'" Include="-DANDROID_ABI=arm64-v8a" /> <_CoreClrBuildArg Condition="'$(Platform)' == 'arm'" Include="-DANDROID_ABI=armeabi-v7a" /> <_CoreClrBuildArg Condition="'$(Platform)' == 'x86'" Include="-DANDROID_ABI=x86" /> diff --git a/src/native/external/libunwind_extras/CMakeLists.txt b/src/native/external/libunwind_extras/CMakeLists.txt index 2bfd2194c969e..f63bbf705a072 100644 --- a/src/native/external/libunwind_extras/CMakeLists.txt +++ b/src/native/external/libunwind_extras/CMakeLists.txt @@ -11,6 +11,8 @@ add_definitions(-DPACKAGE_STRING="") add_definitions(-DPACKAGE_BUGREPORT="") add_definitions(-DHAVE_DL_ITERATE_PHDR=1) + + if(CLR_CMAKE_HOST_UNIX) if (CLR_CMAKE_HOST_ARCH_AMD64) set(arch x86_64) @@ -165,12 +167,19 @@ if(CLR_CMAKE_HOST_WIN32) set_source_files_properties(${LIBUNWIND_SOURCES} PROPERTIES COMPILE_FLAGS /TC) # compile all files as C endif(CLR_CMAKE_HOST_WIN32) +if(CLR_CMAKE_TARGET_ANDROID) + # Instead of patching libunwind, don't treat the handful of warnings it has as errors + add_compile_options(-Wno-error) +endif() + if(CLR_CMAKE_HOST_UNIX) if(CLR_CMAKE_HOST_OSX) add_library(libunwind_dac OBJECT ${LIBUNWIND_SOURCES}) else() add_library(libunwind OBJECT ${LIBUNWIND_SOURCES}) endif(CLR_CMAKE_HOST_OSX) + + else(CLR_CMAKE_HOST_UNIX) set_source_files_properties(${CLR_DIR}/pal/src/exception/remote-unwind.cpp PROPERTIES COMPILE_FLAGS /TP INCLUDE_DIRECTORIES ${CLR_DIR}/inc) From 6f1b917a32535413bb138a27fdc56c2573dffb16 Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Fri, 6 Dec 2024 15:46:27 +0100 Subject: [PATCH 02/11] Don't package what's not needed on Android --- src/coreclr/.nuget/coreclr-packages.proj | 4 ++-- src/coreclr/CMakeLists.txt | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/coreclr/.nuget/coreclr-packages.proj b/src/coreclr/.nuget/coreclr-packages.proj index f7c43af0e783c..03deff0b8dc5d 100644 --- a/src/coreclr/.nuget/coreclr-packages.proj +++ b/src/coreclr/.nuget/coreclr-packages.proj @@ -9,11 +9,11 @@ - + - + diff --git a/src/coreclr/CMakeLists.txt b/src/coreclr/CMakeLists.txt index 107859ec58dc5..8a6b50fd3030a 100644 --- a/src/coreclr/CMakeLists.txt +++ b/src/coreclr/CMakeLists.txt @@ -250,8 +250,10 @@ if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_H add_subdirectory(utilcode) add_subdirectory(inc) - add_subdirectory(ilasm) - add_subdirectory(ildasm) + if (NOT CLR_CMAKE_TARGET_ANDROID) + add_subdirectory(ilasm) + add_subdirectory(ildasm) + endif(CLR_CMAKE_TARGET_ANDROID) add_subdirectory(gcinfo) add_subdirectory(jit) add_subdirectory(vm) From c25fbd915a8676d661aea619570acf78a4417e7c Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Fri, 6 Dec 2024 16:00:40 +0100 Subject: [PATCH 03/11] TARGET_LINUX == TARGET_ANDROID for crosscomp.h --- src/coreclr/inc/crosscomp.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/coreclr/inc/crosscomp.h b/src/coreclr/inc/crosscomp.h index 50867accca1ac..051ab99f4b09b 100644 --- a/src/coreclr/inc/crosscomp.h +++ b/src/coreclr/inc/crosscomp.h @@ -696,15 +696,15 @@ typedef struct _T_KNONVOLATILE_CONTEXT_POINTERS { #define DAC_CS_NATIVE_DATA_SIZE 24 #elif defined(TARGET_FREEBSD) && defined(TARGET_ARM64) #define DAC_CS_NATIVE_DATA_SIZE 24 -#elif defined(TARGET_LINUX) && defined(TARGET_ARM) +#elif (defined(TARGET_LINUX) || defined(TARGET_ANDROID)) && defined(TARGET_ARM) #define DAC_CS_NATIVE_DATA_SIZE 80 -#elif defined(TARGET_LINUX) && defined(TARGET_ARM64) +#elif (defined(TARGET_LINUX) || defined(TARGET_ANDROID)) && defined(TARGET_ARM64) #define DAC_CS_NATIVE_DATA_SIZE 104 #elif defined(TARGET_LINUX) && defined(TARGET_LOONGARCH64) #define DAC_CS_NATIVE_DATA_SIZE 96 -#elif defined(TARGET_LINUX) && defined(TARGET_X86) +#elif (defined(TARGET_LINUX) || defined(TARGET_ANDROID)) && defined(TARGET_X86) #define DAC_CS_NATIVE_DATA_SIZE 76 -#elif defined(TARGET_LINUX) && defined(TARGET_AMD64) +#elif (defined(TARGET_LINUX) || defined(TARGET_ANDROID)) && defined(TARGET_AMD64) #define DAC_CS_NATIVE_DATA_SIZE 96 #elif defined(TARGET_LINUX) && defined(TARGET_S390X) #define DAC_CS_NATIVE_DATA_SIZE 96 @@ -748,4 +748,3 @@ struct T_CRITICAL_SECTION { #else #define T_CRITICAL_SECTION CRITICAL_SECTION #endif - From bfcbb3ef0bda2ad278ff901d4c911094657a4e98 Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Fri, 6 Dec 2024 13:55:45 +0100 Subject: [PATCH 04/11] Beginnings of native Android build --- Directory.Build.props | 2 +- eng/native/build-commons.sh | 4 +++- src/coreclr/minipal/Unix/doublemapping.cpp | 3 +++ src/coreclr/runtime.proj | 5 +++-- src/native/external/libunwind_extras/CMakeLists.txt | 9 +++++++++ 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index f30877332027d..dcac66ca23720 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -68,7 +68,7 @@ - src/tasks/MobileBuildTasks/Apple/AppleProject.cs - https://github.com/dotnet/sdk repo > src/Installer/redist-installer/targets/GeneratePKG.targets --> - 21 + 28 12.2 12.2 12.0 diff --git a/eng/native/build-commons.sh b/eng/native/build-commons.sh index 2cf33442a9325..f3195336bbaea 100755 --- a/eng/native/build-commons.sh +++ b/eng/native/build-commons.sh @@ -79,6 +79,8 @@ build_native() fi if [[ "$targetOS" == android || "$targetOS" == linux-bionic ]]; then + # Keep in sync with $(AndroidApiLevelMin) in Directory.Build.props in the repository rooot + local ANDROID_API_LEVEL=28 if [[ -z "$ANDROID_NDK_ROOT" ]]; then echo "Error: You need to set the ANDROID_NDK_ROOT environment variable pointing to the Android NDK root." exit 1 @@ -87,7 +89,7 @@ build_native() cmakeArgs="-C $__RepoRootDir/eng/native/tryrun.cmake $cmakeArgs" # keep ANDROID_PLATFORM in sync with SetOSTargetMinVersions in the root Directory.Build.props - cmakeArgs="-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_ROOT/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=android-21 $cmakeArgs" + cmakeArgs="-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_ROOT/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=android-${ANDROID_API_LEVEL} -DANDROID_NATIVE_API_LEVEL=${ANDROID_API_LEVEL} $cmakeArgs" # Don't try to set CC/CXX in init-compiler.sh - it's handled in android.toolchain.cmake already __Compiler="default" diff --git a/src/coreclr/minipal/Unix/doublemapping.cpp b/src/coreclr/minipal/Unix/doublemapping.cpp index ba43e72a0c673..261d3a2cf9499 100644 --- a/src/coreclr/minipal/Unix/doublemapping.cpp +++ b/src/coreclr/minipal/Unix/doublemapping.cpp @@ -54,6 +54,8 @@ bool VMToOSInterface::CreateDoubleMemoryMapper(void** pHandle, size_t *pMaxExecu int fd = -1; #endif +#ifndef TARGET_ANDROID + // Bionic doesn't have shm_{open,unlink} // POSIX fallback if (fd == -1) { @@ -64,6 +66,7 @@ bool VMToOSInterface::CreateDoubleMemoryMapper(void** pHandle, size_t *pMaxExecu fd = shm_open(name, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW, 0600); shm_unlink(name); } +#endif // !TARGET_ANDROID if (fd == -1) { diff --git a/src/coreclr/runtime.proj b/src/coreclr/runtime.proj index 12e655d9fdedb..a2e704b5152ab 100644 --- a/src/coreclr/runtime.proj +++ b/src/coreclr/runtime.proj @@ -78,9 +78,10 @@ <_CoreClrBuildArg Include="-DCMAKE_TOOLCHAIN_FILE=$(ANDROID_NDK_ROOT)/build/cmake/android.toolchain.cmake"/> <_CoreClrBuildArg Include="-DANDROID_NDK=$(ANDROID_NDK_ROOT)"/> - <_CoreClrBuildArg Include="-DANDROID_STL=none"/> - <_CoreClrBuildArg Include="-DANDROID_CPP_FEATURES="no-rtti no-exceptions""/> + <_CoreClrBuildArg Include="-DANDROID_STL=c++_static"/> + <_CoreClrBuildArg Include="-DANDROID_CPP_FEATURES="no-rtti exceptions""/> <_CoreClrBuildArg Include="-DANDROID_PLATFORM=android-$(AndroidApiLevelMin)"/> + <_CoreClrBuildArg Include="-DANDROID_NATIVE_API_LEVEL=$(AndroidApiLevelMin)"/> <_CoreClrBuildArg Condition="'$(Platform)' == 'arm64'" Include="-DANDROID_ABI=arm64-v8a" /> <_CoreClrBuildArg Condition="'$(Platform)' == 'arm'" Include="-DANDROID_ABI=armeabi-v7a" /> <_CoreClrBuildArg Condition="'$(Platform)' == 'x86'" Include="-DANDROID_ABI=x86" /> diff --git a/src/native/external/libunwind_extras/CMakeLists.txt b/src/native/external/libunwind_extras/CMakeLists.txt index 2bfd2194c969e..f63bbf705a072 100644 --- a/src/native/external/libunwind_extras/CMakeLists.txt +++ b/src/native/external/libunwind_extras/CMakeLists.txt @@ -11,6 +11,8 @@ add_definitions(-DPACKAGE_STRING="") add_definitions(-DPACKAGE_BUGREPORT="") add_definitions(-DHAVE_DL_ITERATE_PHDR=1) + + if(CLR_CMAKE_HOST_UNIX) if (CLR_CMAKE_HOST_ARCH_AMD64) set(arch x86_64) @@ -165,12 +167,19 @@ if(CLR_CMAKE_HOST_WIN32) set_source_files_properties(${LIBUNWIND_SOURCES} PROPERTIES COMPILE_FLAGS /TC) # compile all files as C endif(CLR_CMAKE_HOST_WIN32) +if(CLR_CMAKE_TARGET_ANDROID) + # Instead of patching libunwind, don't treat the handful of warnings it has as errors + add_compile_options(-Wno-error) +endif() + if(CLR_CMAKE_HOST_UNIX) if(CLR_CMAKE_HOST_OSX) add_library(libunwind_dac OBJECT ${LIBUNWIND_SOURCES}) else() add_library(libunwind OBJECT ${LIBUNWIND_SOURCES}) endif(CLR_CMAKE_HOST_OSX) + + else(CLR_CMAKE_HOST_UNIX) set_source_files_properties(${CLR_DIR}/pal/src/exception/remote-unwind.cpp PROPERTIES COMPILE_FLAGS /TP INCLUDE_DIRECTORIES ${CLR_DIR}/inc) From 97f2555ba653856259313d273dc6d544e2e8905e Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Fri, 6 Dec 2024 15:46:27 +0100 Subject: [PATCH 05/11] Don't package what's not needed on Android --- src/coreclr/.nuget/coreclr-packages.proj | 4 ++-- src/coreclr/CMakeLists.txt | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/coreclr/.nuget/coreclr-packages.proj b/src/coreclr/.nuget/coreclr-packages.proj index f7c43af0e783c..03deff0b8dc5d 100644 --- a/src/coreclr/.nuget/coreclr-packages.proj +++ b/src/coreclr/.nuget/coreclr-packages.proj @@ -9,11 +9,11 @@ - + - + diff --git a/src/coreclr/CMakeLists.txt b/src/coreclr/CMakeLists.txt index 107859ec58dc5..8a6b50fd3030a 100644 --- a/src/coreclr/CMakeLists.txt +++ b/src/coreclr/CMakeLists.txt @@ -250,8 +250,10 @@ if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_H add_subdirectory(utilcode) add_subdirectory(inc) - add_subdirectory(ilasm) - add_subdirectory(ildasm) + if (NOT CLR_CMAKE_TARGET_ANDROID) + add_subdirectory(ilasm) + add_subdirectory(ildasm) + endif(CLR_CMAKE_TARGET_ANDROID) add_subdirectory(gcinfo) add_subdirectory(jit) add_subdirectory(vm) From 3d9da104630ff25ad7a17076f59bb6f1cbed2d58 Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Fri, 6 Dec 2024 16:00:40 +0100 Subject: [PATCH 06/11] TARGET_LINUX == TARGET_ANDROID for crosscomp.h --- src/coreclr/inc/crosscomp.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/coreclr/inc/crosscomp.h b/src/coreclr/inc/crosscomp.h index 50867accca1ac..051ab99f4b09b 100644 --- a/src/coreclr/inc/crosscomp.h +++ b/src/coreclr/inc/crosscomp.h @@ -696,15 +696,15 @@ typedef struct _T_KNONVOLATILE_CONTEXT_POINTERS { #define DAC_CS_NATIVE_DATA_SIZE 24 #elif defined(TARGET_FREEBSD) && defined(TARGET_ARM64) #define DAC_CS_NATIVE_DATA_SIZE 24 -#elif defined(TARGET_LINUX) && defined(TARGET_ARM) +#elif (defined(TARGET_LINUX) || defined(TARGET_ANDROID)) && defined(TARGET_ARM) #define DAC_CS_NATIVE_DATA_SIZE 80 -#elif defined(TARGET_LINUX) && defined(TARGET_ARM64) +#elif (defined(TARGET_LINUX) || defined(TARGET_ANDROID)) && defined(TARGET_ARM64) #define DAC_CS_NATIVE_DATA_SIZE 104 #elif defined(TARGET_LINUX) && defined(TARGET_LOONGARCH64) #define DAC_CS_NATIVE_DATA_SIZE 96 -#elif defined(TARGET_LINUX) && defined(TARGET_X86) +#elif (defined(TARGET_LINUX) || defined(TARGET_ANDROID)) && defined(TARGET_X86) #define DAC_CS_NATIVE_DATA_SIZE 76 -#elif defined(TARGET_LINUX) && defined(TARGET_AMD64) +#elif (defined(TARGET_LINUX) || defined(TARGET_ANDROID)) && defined(TARGET_AMD64) #define DAC_CS_NATIVE_DATA_SIZE 96 #elif defined(TARGET_LINUX) && defined(TARGET_S390X) #define DAC_CS_NATIVE_DATA_SIZE 96 @@ -748,4 +748,3 @@ struct T_CRITICAL_SECTION { #else #define T_CRITICAL_SECTION CRITICAL_SECTION #endif - From bb9f323c8ad8873e6b3397df1675f02ec512ad4a Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Fri, 6 Dec 2024 15:53:59 -0500 Subject: [PATCH 07/11] Fix cmake endif / make sure RuntimeFlavor is CoreCLR --- eng/Subsets.props | 7 +++++++ src/coreclr/CMakeLists.txt | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/eng/Subsets.props b/eng/Subsets.props index a50fd3e80025e..208492335e191 100644 --- a/eng/Subsets.props +++ b/eng/Subsets.props @@ -56,9 +56,16 @@ <_subset Condition="'$(Subset)' == ''">+$(DefaultSubsets)+ + + + CoreCLR + CoreCLR + + Mono CoreCLR + CoreCLR Mono $(PrimaryRuntimeFlavor) diff --git a/src/coreclr/CMakeLists.txt b/src/coreclr/CMakeLists.txt index 8a6b50fd3030a..31732745e49de 100644 --- a/src/coreclr/CMakeLists.txt +++ b/src/coreclr/CMakeLists.txt @@ -253,7 +253,7 @@ if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_H if (NOT CLR_CMAKE_TARGET_ANDROID) add_subdirectory(ilasm) add_subdirectory(ildasm) - endif(CLR_CMAKE_TARGET_ANDROID) + endif(NOT CLR_CMAKE_TARGET_ANDROID) add_subdirectory(gcinfo) add_subdirectory(jit) add_subdirectory(vm) From b0f3d55636558a37cd4345cf4c982a4453eea1a2 Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Mon, 9 Dec 2024 10:41:31 -0500 Subject: [PATCH 08/11] Use dummyprovider instead of lttngprovider / disable FEATURE_PERFTRACING_PAL_TCP --- src/coreclr/pal/src/configure.cmake | 3 ++- src/coreclr/pal/src/eventprovider/CMakeLists.txt | 3 ++- src/coreclr/runtime.proj | 11 +++++++++-- src/native/eventpipe/CMakeLists.txt | 4 +++- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/coreclr/pal/src/configure.cmake b/src/coreclr/pal/src/configure.cmake index 8dd44c550ba5d..2b4e23e656191 100644 --- a/src/coreclr/pal/src/configure.cmake +++ b/src/coreclr/pal/src/configure.cmake @@ -936,7 +936,8 @@ elseif(CLR_CMAKE_TARGET_HAIKU) set(DEADLOCK_WHEN_THREAD_IS_SUSPENDED_WHILE_BLOCKED_ON_MUTEX 0) set(HAVE_SCHED_OTHER_ASSIGNABLE 1) else() # Anything else is Linux - if(NOT HAVE_LTTNG_TRACEPOINT_H AND FEATURE_EVENT_TRACE) + # LTTNG is not available on Android, so don't error out + if(NOT HAVE_LTTNG_TRACEPOINT_H AND NOT CLR_CMAKE_TARGET_ANDROID AND FEATURE_EVENT_TRACE) unset(HAVE_LTTNG_TRACEPOINT_H CACHE) message(FATAL_ERROR "Cannot find liblttng-ust-dev. Try installing liblttng-ust-dev (or the appropriate packages for your platform)") endif() diff --git a/src/coreclr/pal/src/eventprovider/CMakeLists.txt b/src/coreclr/pal/src/eventprovider/CMakeLists.txt index 143206b5c34f5..540072e406551 100644 --- a/src/coreclr/pal/src/eventprovider/CMakeLists.txt +++ b/src/coreclr/pal/src/eventprovider/CMakeLists.txt @@ -1,6 +1,7 @@ set(EVENT_MANIFEST ${VM_DIR}/ClrEtwAll.man) -if(CLR_CMAKE_HOST_LINUX) +# TODO: LTTNG is not supported on Android. We need a solution. +if(CLR_CMAKE_HOST_LINUX AND NOT CLR_CMAKE_TARGET_ANDROID) add_subdirectory(lttngprovider) else() add_subdirectory(dummyprovider) diff --git a/src/coreclr/runtime.proj b/src/coreclr/runtime.proj index a2e704b5152ab..d71c4c7723bd5 100644 --- a/src/coreclr/runtime.proj +++ b/src/coreclr/runtime.proj @@ -87,8 +87,15 @@ <_CoreClrBuildArg Condition="'$(Platform)' == 'x86'" Include="-DANDROID_ABI=x86" /> <_CoreClrBuildArg Condition="'$(Platform)' == 'x64'" Include="-DANDROID_ABI=x86_64" /> - - <_CoreClrBuildArg Include="-cmakeargs -DFEATURE_EVENT_TRACE=0"/> + + + <_CoreClrBuildArg Include="-cmakeargs -DRUNTIME_CORECLR=1" /> diff --git a/src/native/eventpipe/CMakeLists.txt b/src/native/eventpipe/CMakeLists.txt index 311293ca5f45c..6fccb2f26d5c2 100644 --- a/src/native/eventpipe/CMakeLists.txt +++ b/src/native/eventpipe/CMakeLists.txt @@ -12,7 +12,9 @@ check_symbol_exists( HAVE_ACCEPT4) # Use TCP for EventPipe on mobile platforms -if (CLR_CMAKE_HOST_IOS OR CLR_CMAKE_HOST_TVOS OR CLR_CMAKE_HOST_ANDROID) +# +# TODO: Resolve TCP/IP EventPipe support on CoreCLR Android +if (CLR_CMAKE_HOST_IOS OR CLR_CMAKE_HOST_TVOS OR (CLR_CMAKE_HOST_ANDROID AND NOT RUNTIME_CORECLR)) set(FEATURE_PERFTRACING_PAL_TCP 1) set(FEATURE_PERFTRACING_DISABLE_DEFAULT_LISTEN_PORT 1) endif() From f9eb950a151ea69e95c7f7b562438f66dd570e37 Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Wed, 11 Dec 2024 15:15:41 -0500 Subject: [PATCH 09/11] Put a GEN_SHARED_LIB check around install_with_stripped_symbols in System.Security.Cryptography.Native.Android. It will incorrectly try to install in the coreclr build --- eng/build.sh | 2 +- .../CMakeLists.txt | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/eng/build.sh b/eng/build.sh index fe0e880252818..2338e7846412b 100755 --- a/eng/build.sh +++ b/eng/build.sh @@ -141,7 +141,7 @@ initDistroRid() local isCrossBuild="$3" # Only pass ROOTFS_DIR if __DoCrossArchBuild is specified and the current platform is not an Apple platform (that doesn't use rootfs) - if [[ $isCrossBuild == 1 && "$targetOs" != "osx" && "$targetOs" != "ios" && "$targetOs" != "iossimulator" && "$targetOs" != "tvos" && "$targetOs" != "tvossimulator" && "$targetOs" != "maccatalyst" ]]; then + if [[ $isCrossBuild == 1 && "$targetOs" != "osx" && "$targetOs" != "android" && "$targetOs" != "ios" && "$targetOs" != "iossimulator" && "$targetOs" != "tvos" && "$targetOs" != "tvossimulator" && "$targetOs" != "maccatalyst" ]]; then passedRootfsDir=${ROOTFS_DIR} fi initDistroRidGlobal "${targetOs}" "${targetArch}" "${passedRootfsDir}" diff --git a/src/native/libs/System.Security.Cryptography.Native.Android/CMakeLists.txt b/src/native/libs/System.Security.Cryptography.Native.Android/CMakeLists.txt index f87db8a8c75b6..033378d2ee00a 100644 --- a/src/native/libs/System.Security.Cryptography.Native.Android/CMakeLists.txt +++ b/src/native/libs/System.Security.Cryptography.Native.Android/CMakeLists.txt @@ -52,5 +52,8 @@ target_link_libraries(System.Security.Cryptography.Native.Android set_target_properties(System.Security.Cryptography.Native.Android PROPERTIES OUTPUT_NAME "System.Security.Cryptography.Native.Android") set_target_properties(System.Security.Cryptography.Native.Android-Static PROPERTIES OUTPUT_NAME "System.Security.Cryptography.Native.Android") -install_with_stripped_symbols (System.Security.Cryptography.Native.Android PROGRAMS .) -install (TARGETS System.Security.Cryptography.Native.Android-Static DESTINATION .) +if (GEN_SHARED_LIB) + install_with_stripped_symbols (System.Security.Cryptography.Native.Android PROGRAMS .) +endif() + +install (TARGETS System.Security.Cryptography.Native.Android-Static DESTINATION ${STATIC_LIB_DESTINATION} COMPONENT libs) From a69fcfd9f8a7c498c38cd65110602e2c9fcc4f0d Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Wed, 11 Dec 2024 16:53:54 -0500 Subject: [PATCH 10/11] Bump min API level to 29 (proper TLS support) and link the right system.native library for the singlefilehost --- Directory.Build.props | 2 +- eng/native/build-commons.sh | 2 +- .../corehost/apphost/static/CMakeLists.txt | 22 ++++++++++++++++--- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index dcac66ca23720..f347b925a5d7a 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -68,7 +68,7 @@ - src/tasks/MobileBuildTasks/Apple/AppleProject.cs - https://github.com/dotnet/sdk repo > src/Installer/redist-installer/targets/GeneratePKG.targets --> - 28 + 29 12.2 12.2 12.0 diff --git a/eng/native/build-commons.sh b/eng/native/build-commons.sh index f3195336bbaea..5e6f1ba008c80 100755 --- a/eng/native/build-commons.sh +++ b/eng/native/build-commons.sh @@ -80,7 +80,7 @@ build_native() if [[ "$targetOS" == android || "$targetOS" == linux-bionic ]]; then # Keep in sync with $(AndroidApiLevelMin) in Directory.Build.props in the repository rooot - local ANDROID_API_LEVEL=28 + local ANDROID_API_LEVEL=29 if [[ -z "$ANDROID_NDK_ROOT" ]]; then echo "Error: You need to set the ANDROID_NDK_ROOT environment variable pointing to the Android NDK root." exit 1 diff --git a/src/native/corehost/apphost/static/CMakeLists.txt b/src/native/corehost/apphost/static/CMakeLists.txt index 25c1d55e7360c..c8df014e50e8c 100644 --- a/src/native/corehost/apphost/static/CMakeLists.txt +++ b/src/native/corehost/apphost/static/CMakeLists.txt @@ -46,7 +46,12 @@ set(HEADERS ../../fxr_resolver.h ) -add_compile_definitions(NATIVE_LIBS_EMBEDDED) +# TODO: Android uses a separate System.Security.Cryptography lib that does not have +# the exported functions the singlefilehost expects. +# Figure out how that's going to work and turn this back on. +if (NOT CLR_CMAKE_TARGET_ANDROID) + add_compile_definitions(NATIVE_LIBS_EMBEDDED) +endif() include(../../fxr/files.cmake) include(../../hostpolicy/files.cmake) @@ -169,10 +174,21 @@ else() System.Globalization.Native-Static System.IO.Compression.Native-Static - System.Net.Security.Native-Static System.Native-Static - System.Security.Cryptography.Native.OpenSsl-Static + ) + + if(NOT CLR_CMAKE_TARGET_ANDROID) + list(APPEND NATIVE_LIBS + System.Net.Security.Native-Static + System.Security.Cryptography.Native.OpenSsl-Static + ) + else() + list(APPEND NATIVE_LIBS + System.Security.Cryptography.Native.Android-Static + ) + endif() + list(APPEND NATIVE_LIBS coreclrpal_dac corguids dbgutil From 54fbb509c5e8c728a829bbb15face41215825724 Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Thu, 12 Dec 2024 22:19:56 -0500 Subject: [PATCH 11/11] Fix host/target confusion in R2R tool publish / Add Android target to R2R that acts like linux --- Directory.Build.props | 2 +- eng/native/naming.props | 27 +++++++++++++++++++ .../tools/Common/CommandLineHelpers.cs | 3 ++- .../Common/TypeSystem/Common/TargetDetails.cs | 3 ++- .../ObjectWriter/TargetExtensions.cs | 1 + .../tools/aot/crossgen2/crossgen2.props | 11 ++++++-- .../aot/crossgen2/crossgen2_publish.csproj | 4 ++- 7 files changed, 45 insertions(+), 6 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index f347b925a5d7a..727eec689b092 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -231,7 +231,7 @@ <_packageOS>$(_portableOS) - <_packageOS Condition="'$(CrossBuild)' == 'true' and '$(_portableOS)' != 'linux-musl' and '$(_portableOS)' != 'linux-bionic'">$(_hostOS) + <_packageOS Condition="'$(CrossBuild)' == 'true' and '$(_portableOS)' != 'linux-musl' and '$(_portableOS)' != 'linux-bionic' and '$(_portableOS)' != 'android'">$(_hostOS) $(PackageOS)-$(TargetArchitecture) diff --git a/eng/native/naming.props b/eng/native/naming.props index b50c0c131cda5..d1e1b3c552009 100644 --- a/eng/native/naming.props +++ b/eng/native/naming.props @@ -2,9 +2,36 @@ lib .exe + $(HostOS) + + + + .dll + .lib + .pdb + + + + + lib + .dylib + .a + .dwarf + + + + + lib + .so + .a + .dbg + + + + diff --git a/src/coreclr/tools/Common/CommandLineHelpers.cs b/src/coreclr/tools/Common/CommandLineHelpers.cs index 26d59f72d02b3..4c937c7f109b2 100644 --- a/src/coreclr/tools/Common/CommandLineHelpers.cs +++ b/src/coreclr/tools/Common/CommandLineHelpers.cs @@ -60,7 +60,7 @@ public static TargetOS GetTargetOS(string token) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) return TargetOS.Windows; - else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.Create("ANDROID"))) return TargetOS.Linux; else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) return TargetOS.OSX; @@ -81,6 +81,7 @@ public static TargetOS GetTargetOS(string token) "ios" => TargetOS.iOS, "tvossimulator" => TargetOS.tvOSSimulator, "tvos" => TargetOS.tvOS, + "android" => TargetOS.Android, _ => throw new CommandLineException($"Target OS '{token}' is not supported") }; } diff --git a/src/coreclr/tools/Common/TypeSystem/Common/TargetDetails.cs b/src/coreclr/tools/Common/TypeSystem/Common/TargetDetails.cs index bb7929b88affe..a0bee20e6b0ff 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/TargetDetails.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/TargetDetails.cs @@ -23,7 +23,8 @@ public enum TargetOS FreeBSD, NetBSD, SunOS, - WebAssembly + WebAssembly, + Android } public enum TargetAbi diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/ObjectWriter/TargetExtensions.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/ObjectWriter/TargetExtensions.cs index 59a0567d790f2..bb5e27c1a5771 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/ObjectWriter/TargetExtensions.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/ObjectWriter/TargetExtensions.cs @@ -109,6 +109,7 @@ public static MachineOSOverride MachineOSOverrideFromTarget(this TargetDetails t return MachineOSOverride.Windows; case TargetOS.Linux: + case TargetOS.Android: return MachineOSOverride.Linux; case TargetOS.OSX: diff --git a/src/coreclr/tools/aot/crossgen2/crossgen2.props b/src/coreclr/tools/aot/crossgen2/crossgen2.props index 0c2555a477fff..f084bf8778d80 100644 --- a/src/coreclr/tools/aot/crossgen2/crossgen2.props +++ b/src/coreclr/tools/aot/crossgen2/crossgen2.props @@ -41,12 +41,19 @@ + + <_LibPrefix Condition="'$(_IsCrossHostPublish)' == 'true'">$(LibPrefix) + <_LibPrefix Condition="'$(_IsCrossHostPublish)' != 'true'">$(HostLibPrefix) + <_LibSuffix Condition="'$(_IsCrossHostPublish)' == 'true'">$(LibSuffix) + <_LibSuffix Condition="'$(_IsCrossHostPublish)' != 'true'">$(HostLibSuffix) + + $(TargetArchitecture) $(CrossHostArch) arm - $(LibPrefix)jitinterface_$(TargetArchitectureForSharedLibraries)$(LibSuffix) + $(_LibPrefix)jitinterface_$(TargetArchitectureForSharedLibraries)$(_LibSuffix) @@ -56,7 +63,7 @@ Link="%(FileName)%(Extension)" /> - <_IsPublishing>true - $(PackageRID) + $(NETCoreSdkPortableRuntimeIdentifier) + $(PackageRID) $(RuntimeBinDir)crossgen2-published/ true true false true + <_IsCrossHostPublish>true