diff --git a/Directory.Build.props b/Directory.Build.props index f30877332027d..727eec689b092 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 + 29 12.2 12.2 12.0 @@ -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/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/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/eng/native/build-commons.sh b/eng/native/build-commons.sh index 2cf33442a9325..5e6f1ba008c80 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=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 @@ -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/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/.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..31732745e49de 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(NOT CLR_CMAKE_TARGET_ANDROID) add_subdirectory(gcinfo) add_subdirectory(jit) add_subdirectory(vm) 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 - 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/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 12e655d9fdedb..d71c4c7723bd5 100644 --- a/src/coreclr/runtime.proj +++ b/src/coreclr/runtime.proj @@ -78,16 +78,24 @@ <_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" /> <_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/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 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 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() 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) 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)