Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NativeAOT build and runtime pack for linux-bionic #86781

Merged
merged 3 commits into from
May 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eng/Subsets.props
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 2 additions & 0 deletions eng/native/build-commons.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ build_native()
exit 1
fi

cmakeArgs="-C $__RepoRootDir/eng/native/tryrun.cmake $cmakeArgs"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same reason we had to add a tryrun for iDevices - cmake cannot execute these detectoids because it's a crossbuild. Normally the infra passes tryrun to crossbuild but this is not considered a crossbuild by the infra (see the first issue I linked in top post - we don't pass -cross to build.sh to build Bionic)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, what I meant was why is this not necessary for the mono-based Android build today?

I looked a bit deeper now and I think it is because we're not using any of these cmake checks in the System.Native build so we don't hit this, e.g. we explicitly skip the checks that would cause binaries to be run during configure on mobile and manually set the results:

if(CLR_CMAKE_TARGET_IOS)
# Manually set results from check_c_source_runs() since it's not possible to actually run it during CMake configure checking
unset(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP)
unset(HAVE_ALIGNED_ALLOC) # only exists on iOS 13+
unset(HAVE_CLOCK_MONOTONIC) # only exists on iOS 10+
unset(HAVE_CLOCK_REALTIME) # only exists on iOS 10+
unset(HAVE_FORK) # exists but blocked by kernel
elseif(CLR_CMAKE_TARGET_MACCATALYST)
# Manually set results from check_c_source_runs() since it's not possible to actually run it during CMake configure checking
# TODO: test to see if these all actually hold true on Mac Catalyst
unset(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP)
unset(HAVE_ALIGNED_ALLOC) # only exists on iOS 13+
unset(HAVE_CLOCK_MONOTONIC) # only exists on iOS 10+
unset(HAVE_CLOCK_REALTIME) # only exists on iOS 10+
unset(HAVE_FORK) # exists but blocked by kernel
elseif(CLR_CMAKE_TARGET_TVOS)
# Manually set results from check_c_source_runs() since it's not possible to actually run it during CMake configure checking
unset(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP)
unset(HAVE_ALIGNED_ALLOC) # only exists on iOS 13+
unset(HAVE_CLOCK_MONOTONIC) # only exists on iOS 10+
unset(HAVE_CLOCK_REALTIME) # only exists on iOS 10+
unset(HAVE_FORK) # exists but blocked by kernel
elseif(CLR_CMAKE_TARGET_ANDROID)
# Manually set results from check_c_source_runs() since it's not possible to actually run it during CMake configure checking
unset(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP)
unset(HAVE_ALIGNED_ALLOC) # only exists on newer Android
set(HAVE_CLOCK_MONOTONIC 1)
set(HAVE_CLOCK_REALTIME 1)
elseif(CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI)
set(HAVE_FORK 0)
else()
if(CLR_CMAKE_TARGET_OSX)
unset(HAVE_ALIGNED_ALLOC) # only exists on OSX 10.15+
else()

So this is fine since we'll override the values for e.g. HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP but we should probably clean this up and move all of the detection into tryrun.cmake. Would you mind filing an issue for that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed #86829.


# 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"

Expand Down
15 changes: 15 additions & 0 deletions eng/native/tryrun.cmake
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 2 additions & 0 deletions eng/pipelines/runtime-official.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/build-runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/nativeaot/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 19 additions & 1 deletion src/coreclr/runtime.proj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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
Expand Down Expand Up @@ -61,6 +64,21 @@
<_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>
Expand Down
4 changes: 2 additions & 2 deletions src/native/corehost/apphost/static/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down