Add NativeAOT build and runtime pack for linux-bionic (#86781)
authorMichal Strehovský <MichalStrehovsky@users.noreply.github.com>
Sat, 27 May 2023 07:38:18 +0000 (16:38 +0900)
committerGitHub <noreply@github.com>
Sat, 27 May 2023 07:38:18 +0000 (16:38 +0900)
Build and runtime pack for linux-bionic (Android without the Java part).

I tried not to regress the existing CoreCLR Android build that is based on a crossrootfs (#56622) - the if's basically deal with that. Note that it's likely broken anyway (#66562).

eng/Subsets.props
eng/native/build-commons.sh
eng/native/tryrun.cmake
eng/pipelines/runtime-official.yml
src/coreclr/CMakeLists.txt
src/coreclr/build-runtime.sh
src/coreclr/nativeaot/CMakeLists.txt
src/coreclr/runtime.proj
src/native/corehost/apphost/static/CMakeLists.txt

index 2906f49..211dc6a 100644 (file)
@@ -50,7 +50,7 @@
 
   <PropertyGroup>
     <RuntimeFlavor Condition="'$(TargetsMobile)' == 'true' and !$(_subset.Contains('+clr.nativeaotlibs+'))">Mono</RuntimeFlavor>
-    <RuntimeFlavor Condition="'$(TargetsMobile)' == 'true' and $(_subset.Contains('+clr.nativeaotlibs+'))">CoreCLR</RuntimeFlavor>
+    <RuntimeFlavor Condition="('$(TargetsMobile)' == 'true' or '$(TargetsLinuxBionic)' == 'true') and $(_subset.Contains('+clr.nativeaotlibs+'))">CoreCLR</RuntimeFlavor>
     <RuntimeFlavor Condition="'$(RuntimeFlavor)' == '' and ($(_subset.Contains('+mono+')) or $(_subset.Contains('+mono.runtime+'))) and (!$(_subset.Contains('+clr+')) and !$(_subset.Contains('+clr.runtime+')))">Mono</RuntimeFlavor>
     <RuntimeFlavor Condition="'$(RuntimeFlavor)' == ''">$(PrimaryRuntimeFlavor)</RuntimeFlavor>
   </PropertyGroup>
index 509063d..e9d696f 100755 (executable)
@@ -84,6 +84,8 @@ build_native()
             exit 1
         fi
 
+        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"
 
index 04c6d1a..97947fe 100644 (file)
@@ -1,6 +1,21 @@
 set(CROSS_ROOTFS $ENV{ROOTFS_DIR})
 set(TARGET_ARCH_NAME $ENV{TARGET_BUILD_ARCH})
 
+# Also allow building as Android without specifying `-cross`.
+if(NOT DEFINED TARGET_ARCH_NAME AND DEFINED ANDROID_PLATFORM)
+  if(ANDROID_ABI STREQUAL "arm64-v8a")
+    set(TARGET_ARCH_NAME "arm64")
+  elseif(ANDROID_ABI STREQUAL "x86_64")
+    set(TARGET_ARCH_NAME "x64")
+  elseif(ANDROID_ABI STREQUAL "armeabi-v7a")
+    set(TARGET_ARCH_NAME "arm")
+  elseif(ANDROID_ABI STREQUAL "x86")
+    set(TARGET_ARCH_NAME "x86")
+  else()
+    message(FATAL_ERROR "ANDROID_ABI ${ANDROID_ABI} not recognized!")
+  endif()
+endif()
+
 macro(set_cache_value)
   set(${ARGV0} ${ARGV1} CACHE STRING "Result from TRY_RUN" FORCE)
   set(${ARGV0}__TRYRUN_OUTPUT "dummy output" CACHE STRING "Output from TRY_RUN" FORCE)
index 2ef77a1..76cc862 100644 (file)
@@ -112,6 +112,8 @@ extends:
           - iossimulator_x64
           - iossimulator_arm64
           - ios_arm64
+          - linux_bionic_arm64
+          - linux_bionic_x64
           jobParameters:
             buildArgs: -s clr.nativeaotlibs+clr.nativeaotruntime+libs+packs -c $(_BuildConfig) /p:BuildNativeAOTRuntimePack=true
             nameSuffix: AllSubsets_NativeAOT
index 1495cb7..9720b0c 100644 (file)
@@ -97,7 +97,7 @@ endif(NOT CLR_CROSS_COMPONENTS_BUILD)
 #     - do not depend on clr's compile definitions
 #-----------------------------------------
 if(CLR_CMAKE_HOST_UNIX)
-    if(CLR_CMAKE_TARGET_ANDROID)
+    if(CLR_CMAKE_TARGET_ANDROID AND NOT DEFINED CMAKE_ANDROID_NDK)
         find_library(LZMA NAMES lzma)
         if(LZMA STREQUAL LZMA-NOTFOUND)
            message(FATAL_ERROR "Cannot find liblzma.")
index 49d2627..90179bc 100755 (executable)
@@ -106,6 +106,9 @@ source "$__ProjectRoot"/_build-commons.sh
 __LogsDir="$__RootBinDir/log/$__BuildType"
 __MsbuildDebugLogsDir="$__LogsDir/MsbuildDebugLogs"
 __ConfigTriplet="$__TargetOS.$__TargetArch.$__BuildType"
+if [[ "$__TargetOS" == "linux-bionic" ]]; then
+    __ConfigTriplet="linux.$__TargetArch.$__BuildType"
+fi
 __BinDir="$__RootBinDir/bin/coreclr/$__ConfigTriplet"
 __ArtifactsObjDir="$__RepoRootDir/artifacts/obj"
 __ArtifactsIntermediatesDir="$__ArtifactsObjDir/coreclr"
index 91fa37c..957a7ac 100644 (file)
@@ -45,6 +45,7 @@ endif()
 
 if(CLR_CMAKE_TARGET_ANDROID)
     add_definitions(-DFEATURE_EMULATED_TLS)
+    add_definitions(-DANDROID_FORCE_ICU_DATA_DIR)
 endif()
 
 add_subdirectory(Bootstrap)
index 8d5410c..496e281 100644 (file)
@@ -3,6 +3,9 @@
   <PropertyGroup>
     <NativeBuildPartitionPropertiesToRemove>ClrFullNativeBuild;ClrRuntimeSubset;ClrJitSubset;ClrPalTestsSubset;ClrAllJitsSubset;ClrILToolsSubset;ClrNativeAotSubset;ClrSpmiSubset;ClrCrossComponentsSubset;HostArchitecture;PgoInstrument;NativeOptimizationDataSupported;CMakeArgs</NativeBuildPartitionPropertiesToRemove>
     <_IcuDir Condition="'$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)' != ''">$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)/runtimes/$(TargetOS)-$(TargetArchitecture)$(_RuntimeVariant)/native</_IcuDir>
+
+    <_BuildNativeTargetOS>$(TargetOS)</_BuildNativeTargetOS>
+    <_BuildNativeTargetOS Condition="'$(TargetsLinuxBionic)' == 'true'">linux-bionic</_BuildNativeTargetOS>
   </PropertyGroup>
 
   <ItemGroup>
@@ -28,7 +31,7 @@
       <_CoreClrBuildArg Condition="'$(CrossBuild)' == 'true'" Include="-cross" />
       <_CoreClrBuildArg Condition="'$(PortableBuild)' != 'true'" Include="-portablebuild=false" />
       <_CoreClrBuildArg Condition="'$(KeepNativeSymbols)' != 'false'" Include="-keepnativesymbols" />
-      <_CoreClrBuildArg Include="-os $(TargetOS)" />
+      <_CoreClrBuildArg Include="-os $(_BuildNativeTargetOS)" />
 
       <_CoreClrBuildArg Condition="$([MSBuild]::IsOsPlatform(Windows)) and
                                    ('$(TargetArchitecture)' == 'x86' or '$(TargetArchitecture)' == 'x64') and
       <_CoreClrBuildArg Include="-cmakeargs -DCMAKE_ICU_DIR=&quot;$(_IcuDir)&quot;" />
     </ItemGroup>
 
+    <ItemGroup Condition="('$(TargetsAndroid)' == 'true' or '$(TargetsLinuxBionic)' == 'true') and '$(ANDROID_NDK_ROOT)' != ''">
+      <_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=&quot;no-rtti no-exceptions&quot;"/>
+      <_CoreClrBuildArg Include="-DANDROID_PLATFORM=android-$(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" />
+
+      <!-- No LTTNG on Android -->
+      <_CoreClrBuildArg Include="-cmakeargs -DFEATURE_EVENT_TRACE=0"/>
+    </ItemGroup>
+
     <PropertyGroup>
       <_CoreClrBuildScript Condition="$([MSBuild]::IsOsPlatform(Windows))">build-runtime.cmd</_CoreClrBuildScript>
       <_CoreClrBuildScript Condition="!$([MSBuild]::IsOsPlatform(Windows))">build-runtime.sh</_CoreClrBuildScript>
index adc5dfe..c491311 100644 (file)
@@ -157,7 +157,7 @@ else()
     include(${CLR_SRC_NATIVE_DIR}/libs/System.IO.Compression.Native/extra_libs.cmake)
     append_extra_compression_libs(NATIVE_LIBS)
 
-    if (NOT CLR_CMAKE_TARGET_TVOS) # no gssapi on tvOS, see https://developer.apple.com/documentation/gss
+    if (NOT CLR_CMAKE_TARGET_TVOS AND NOT CLR_CMAKE_HOST_ANDROID) # no gssapi on tvOS, see https://developer.apple.com/documentation/gss
         # Additional requirements for System.Net.Security.Native
         include(${CLR_SRC_NATIVE_DIR}/libs/System.Net.Security.Native/extra_libs.cmake)
         append_extra_security_libs(NATIVE_LIBS)
@@ -167,7 +167,7 @@ else()
     include(${CLR_SRC_NATIVE_DIR}/libs/System.Native/extra_libs.cmake)
     append_extra_system_libs(NATIVE_LIBS)
 
-    if(NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS)
+    if(NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND NOT CLR_CMAKE_HOST_ANDROID)
         # Additional requirements for System.Security.Cryptography.Native.OpenSsl
         include(${CLR_SRC_NATIVE_DIR}/libs/System.Security.Cryptography.Native/extra_libs.cmake)
         append_extra_cryptography_libs(NATIVE_LIBS)