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

Beginnings of native Android build #110471

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
90c22cb
Beginnings of native Android build
grendello Dec 6, 2024
6f1b917
Don't package what's not needed on Android
grendello Dec 6, 2024
c25fbd9
TARGET_LINUX == TARGET_ANDROID for crosscomp.h
grendello Dec 6, 2024
bfcbb3e
Beginnings of native Android build
grendello Dec 6, 2024
97f2555
Don't package what's not needed on Android
grendello Dec 6, 2024
3d9da10
TARGET_LINUX == TARGET_ANDROID for crosscomp.h
grendello Dec 6, 2024
9e173df
Merge remote-tracking branch 'grendel/dev/grendel/android-build-with-…
steveisok Dec 6, 2024
bb9f323
Fix cmake endif / make sure RuntimeFlavor is CoreCLR
steveisok Dec 6, 2024
b0f3d55
Use dummyprovider instead of lttngprovider / disable FEATURE_PERFTRAC…
steveisok Dec 9, 2024
f9eb950
Put a GEN_SHARED_LIB check around install_with_stripped_symbols in Sy…
steveisok Dec 11, 2024
a69fcfd
Bump min API level to 29 (proper TLS support) and link the right syst…
steveisok Dec 11, 2024
54fbb50
Fix host/target confusion in R2R tool publish / Add Android target to…
steveisok Dec 13, 2024
061badd
Beginnings of native Android build
grendello Dec 6, 2024
343547d
Don't package what's not needed on Android
grendello Dec 6, 2024
d9d653a
TARGET_LINUX == TARGET_ANDROID for crosscomp.h
grendello Dec 6, 2024
be4941b
Fix cmake endif / make sure RuntimeFlavor is CoreCLR
steveisok Dec 6, 2024
db133cb
Use dummyprovider instead of lttngprovider / disable FEATURE_PERFTRAC…
steveisok Dec 9, 2024
6473af2
Put a GEN_SHARED_LIB check around install_with_stripped_symbols in Sy…
steveisok Dec 11, 2024
4d9f500
Bump min API level to 29 (proper TLS support) and link the right syst…
steveisok Dec 11, 2024
d5e0292
Fix host/target confusion in R2R tool publish / Add Android target to…
steveisok Dec 13, 2024
54d5725
Enable doublemapping via memfd_create and few fixes
janvorli Dec 18, 2024
7d78dec
Enable cross-build for macos
ivanpovazan Dec 18, 2024
7026cc8
First version of HelloAndroid
ivanpovazan Dec 18, 2024
9823a55
Cleanup
ivanpovazan Jan 10, 2025
7797943
Merge remote-tracking branch 'grendel/dev/grendel/android-build-with-…
steveisok Jan 10, 2025
2e4c737
Revert changes to R2R that alias Android to linux and put it in a few…
steveisok Jan 10, 2025
2516884
Merge remote-tracking branch 'upstream/main' into dev/grendel/android…
steveisok Jan 10, 2025
074a955
Merge branch 'main' into dev/grendel/android-build-with-ndk
grendello Jan 13, 2025
240ad01
Oops, too much
grendello Jan 13, 2025
34cdc56
Undo host awareness in crossgen_publish as building it is about the t…
steveisok Jan 14, 2025
c171ce3
Fix setting target platform in tryrun.cmake
ivanpovazan Jan 15, 2025
a515ed8
Make sure android runtime pack is generated and crossgen_inbuild uses…
steveisok Jan 15, 2025
3831805
Merge remote-tracking branch 'grendel/dev/grendel/android-build-with-…
steveisok Jan 15, 2025
9779aeb
Condition min api level for coreclr and not.
steveisok Jan 15, 2025
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
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
- src/tasks/MobileBuildTasks/Apple/AppleProject.cs
- https://github.com/dotnet/sdk repo > src/Installer/redist-installer/targets/GeneratePKG.targets
-->
<AndroidApiLevelMin>21</AndroidApiLevelMin>
<AndroidApiLevelMin>29</AndroidApiLevelMin>
Copy link
Member

Choose a reason for hiding this comment

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

this needs to be conditioned on CoreCLR so we don't change the Mono build. same in eng/native/build-commons.sh

Copy link
Member

Choose a reason for hiding this comment

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

Should this be 28? @janvorli tested it recently with 28 https://github.com/dotnet/arcade/blob/88a10ba00ed798ee289d786db9f6339acd682a99/eng/common/cross/build-android-rootfs.sh#L24. We can provide a fallback for that glob API to further lower the requirement.

Copy link
Member

Choose a reason for hiding this comment

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

I think 29 is necessary because that's the first that does not use emulated TLS.

Copy link
Member

Choose a reason for hiding this comment

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

We can add a run-time check for emulated TLS selection and still lower the requirement.

Copy link
Member

Choose a reason for hiding this comment

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

Did we add a workaround for that? When I ran things previously we only had that for NativeAOT. Assuming that's true, the build will fail.

Copy link
Member

Choose a reason for hiding this comment

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

Emulated TLS works on linux-bionic and has been for a while, so in theory it should work on older Androids, newer ones can use the real TLS. I have recently dealt with Emulated TLS on riscv64 (and later switched to real TLS but still having some issues #111317 (comment)). We can tweak things in asm code to select which path to take GETTHREAD_ETLS_1 vs. INLINE_GETTHREAD. Right now it's under the build condition FEATURE_EMULATED_TLS.

Copy link
Member

Choose a reason for hiding this comment

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

It appears that there is going to be some amount of work to get this right < API level 29. My preference would be to do any of that work in a follow up.

<iOSVersionMin>12.2</iOSVersionMin>
<tvOSVersionMin>12.2</tvOSVersionMin>
<macOSVersionMin>12.0</macOSVersionMin>
Expand Down Expand Up @@ -231,7 +231,7 @@
<PropertyGroup Label="CalculatePackageRID">
<_packageOS>$(_portableOS)</_packageOS>

<_packageOS Condition="'$(CrossBuild)' == 'true' and '$(_portableOS)' != 'linux-musl' and '$(_portableOS)' != 'linux-bionic'">$(_hostOS)</_packageOS>
<_packageOS Condition="'$(CrossBuild)' == 'true' and '$(_portableOS)' != 'linux-musl' and '$(_portableOS)' != 'linux-bionic' and '$(_portableOS)' != 'android'">$(_hostOS)</_packageOS>

<!-- source-build sets PackageOS to build with non-portable rid packages that were source-built previously. -->
<PackageRID Condition="'$(PackageOS)' != ''">$(PackageOS)-$(TargetArchitecture)</PackageRID>
Expand Down
7 changes: 7 additions & 0 deletions eng/Subsets.props
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,16 @@
<_subset Condition="'$(Subset)' == ''">+$(DefaultSubsets)+</_subset>
</PropertyGroup>

<!-- Android has a CoreCLR and Mono runtime. Default is mono. -->
<PropertyGroup Condition="'$(TargetsAndroid)' == 'true' and $(_subset.Contains('+clr.'))">
<DefaultPrimaryRuntimeFlavor>CoreCLR</DefaultPrimaryRuntimeFlavor>
<PrimaryRuntimeFlavor>CoreCLR</PrimaryRuntimeFlavor>
</PropertyGroup>

<PropertyGroup>
<RuntimeFlavor Condition="'$(TargetsMobile)' == 'true' and !$(_subset.Contains('+clr.nativeaotlibs+'))">Mono</RuntimeFlavor>
<RuntimeFlavor Condition="('$(TargetsMobile)' == 'true' or '$(TargetsLinuxBionic)' == 'true') and $(_subset.Contains('+clr.nativeaotlibs+'))">CoreCLR</RuntimeFlavor>
<RuntimeFlavor Condition="'$(TargetsAndroid)' == 'true' and $(_subset.Contains('+clr.'))">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: 1 addition & 1 deletion eng/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,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}"
Expand Down
4 changes: 3 additions & 1 deletion eng/native/build-commons.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

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

@grendello has mentioned in #110470 that even API level 28 is unfortunate and that we will want to support older API level, e.g. the originally used level 21.
So I wonder if moving to the level 29 is a good thing.

Copy link
Member

Choose a reason for hiding this comment

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

It's not good in the long term and is something we should fix. Moving it to 29 for now allows us to not have to deal with emulated TLS usage.

Copy link
Member

Choose a reason for hiding this comment

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

Unless we can fix it now, I don't think this should block progress. We can do it sometime down the road.

Choose a reason for hiding this comment

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

In perspective, this would drop 12.8% of the devices (with API level from 21 to 29) according to https://apilevels.com/

Then again:
Level 21 is Android 5 and 6 years EOL
Level 29 is Android 10 and 2 years EOL (https://endoflife.date/android)
Level 34 or higher is necessary to publish apps to the Play Store (https://developer.android.com/google/play/requirements/target-sdk)

Copy link
Member

Choose a reason for hiding this comment

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

I think I can make the emulated TLS work without too much hassle. The question though is if we are worried about the perf implications of the emulated TLS vs the standard TLS and thus we would like to end up having support for both.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perf is important, so I think the long-term solution should be that we have two builds of the runtime (alas): one with emulated TLS for the older devices (we mustn't ignore the older Android versions, 12.8% is still a lot of devices out there), and another targeting API 29 and onwards. It will increase nuget size and the runtime build times on CI, but I think it would be the best way forward.

Copy link
Member

Choose a reason for hiding this comment

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

I'd like to avoid runtime explosion if we can help it.

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
Expand All @@ -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"
Expand Down
26 changes: 26 additions & 0 deletions eng/native/naming.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,32 @@
</PropertyGroup>

<!-- Add path globs specific to native binaries to exclude unnecessary files from packages. -->
<Choose>
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't this logic already exist?

@jkoritzinsky ?

Copy link
Member

Choose a reason for hiding this comment

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

I don't believe it exists elsewhere. I put this here because I found host / target confusion when crossgen2 was cross building android from a mac.

Copy link
Member

@jkoritzinsky jkoritzinsky Jan 15, 2025

Choose a reason for hiding this comment

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

The logic we have is for the "target" platform, not the host (and it's right below this).

<When Condition="$(HostOS.StartsWith('win'))">
<PropertyGroup>
<HostLibSuffix>.dll</HostLibSuffix>
<HostStaticLibSuffix>.lib</HostStaticLibSuffix>
<HostSymbolsSuffix>.pdb</HostSymbolsSuffix>
</PropertyGroup>
</When>
<When Condition="$(HostOS.StartsWith('osx'))">
<PropertyGroup>
<HostLibPrefix>lib</HostLibPrefix>
<HostLibSuffix>.dylib</HostLibSuffix>
<HostStaticLibSuffix>.a</HostStaticLibSuffix>
<HostSymbolsSuffix>.dwarf</HostSymbolsSuffix>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<HostLibPrefix>lib</HostLibPrefix>
<HostLibSuffix>.so</HostLibSuffix>
<HostStaticLibSuffix>.a</HostStaticLibSuffix>
<HostSymbolsSuffix>.dbg</HostSymbolsSuffix>
</PropertyGroup>
</Otherwise>
</Choose>

<Choose>
<When Condition="$(PackageRID.StartsWith('win'))">
<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion eng/native/tryrun.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ elseif(EXISTS ${CROSS_ROOTFS}/boot/system/develop/headers/config/HaikuConfig.h)
set(CLR_CMAKE_TARGET_OS haiku)
endif()

if(DARWIN)
if(DARWIN AND NOT DEFINED ANDROID_PLATFORM)
ivanpovazan marked this conversation as resolved.
Show resolved Hide resolved
if(TARGET_ARCH_NAME MATCHES "^(arm64|x64)$")
set_cache_value(HAS_POSIX_SEMAPHORES_EXITCODE 1)
set_cache_value(HAVE_BROKEN_FIFO_KEVENT_EXITCODE 1)
Expand Down
2 changes: 1 addition & 1 deletion eng/pipelines/coreclr/templates/build-perf-sample-apps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ parameters:
steps:
# Build Android sample app
- ${{ if eq(parameters.osGroup, 'android') }}:
- script: make run MONO_ARCH=arm64 DEPLOY_AND_RUN=false
- script: make run TARGET_ARCH=arm64 DEPLOY_AND_RUN=false
workingDirectory: $(Build.SourcesDirectory)/src/mono/sample/Android
displayName: Build HelloAndroid sample app
- template: /eng/pipelines/common/upload-artifact-step.yml
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/.nuget/coreclr-packages.proj
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
<ProjectReference Include="ILCompiler.Reflection.ReadyToRun.Experimental\ILCompiler.Reflection.ReadyToRun.Experimental.pkgproj" />
</ItemGroup>

<ItemGroup Condition="'$(RuntimeFlavor)' == 'CoreCLR'">
<ItemGroup Condition="'$(RuntimeFlavor)' == 'CoreCLR' and '$(TargetsAndroid)' != 'true' ">
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<ItemGroup Condition="'$(RuntimeFlavor)' == 'CoreCLR' and '$(TargetsAndroid)' != 'true' ">
<ItemGroup Condition="'$(RuntimeFlavor)' == 'CoreCLR' and '$(TargetsMobile)' != 'true' ">

<ProjectReference Include="Microsoft.NETCore.TestHost\Microsoft.NETCore.TestHost.proj" />
</ItemGroup>

<ItemGroup>
<ItemGroup Condition=" '$(TargetsAndroid)' != 'true' ">
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<ItemGroup Condition=" '$(TargetsAndroid)' != 'true' ">
<ItemGroup Condition=" '$(TargetsMobile)' != 'true' ">

<ProjectReference Include="Microsoft.NETCore.ILAsm\Microsoft.NETCore.ILAsm.proj" />
<ProjectReference Include="Microsoft.NETCore.ILDAsm\Microsoft.NETCore.ILDAsm.proj" />
</ItemGroup>
Expand Down
6 changes: 4 additions & 2 deletions src/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

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

Could we instead define a property for "build executables" instead of per-platform?
And also define one for the case above for "NativeAOT-only"?

add_subdirectory(ilasm)
add_subdirectory(ildasm)
endif(NOT CLR_CMAKE_TARGET_ANDROID)
add_subdirectory(gcinfo)
add_subdirectory(jit)
add_subdirectory(vm)
Expand Down
8 changes: 7 additions & 1 deletion src/coreclr/hosts/inc/coreclrhost.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@

#include <stdint.h>

#ifdef __cplusplus
#define CORECLR_HOSTING_API_LINKAGE extern "C"
#else
#define CORECLR_HOSTING_API_LINKAGE
#endif
Comment on lines +19 to +23
Copy link
Member

Choose a reason for hiding this comment

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


// For each hosting API, we define a function prototype and a function pointer
// The prototype is useful for implicit linking against the dynamic coreclr
// library and the pointer for explicit dynamic loading (dlopen, LoadLibrary)
#define CORECLR_HOSTING_API(function, ...) \
extern "C" int CORECLR_CALLING_CONVENTION function(__VA_ARGS__); \
CORECLR_HOSTING_API_LINKAGE int CORECLR_CALLING_CONVENTION function(__VA_ARGS__); \
typedef int (CORECLR_CALLING_CONVENTION *function##_ptr)(__VA_ARGS__)

//
Expand Down
9 changes: 4 additions & 5 deletions src/coreclr/inc/crosscomp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -748,4 +748,3 @@ struct T_CRITICAL_SECTION {
#else
#define T_CRITICAL_SECTION CRITICAL_SECTION
#endif

10 changes: 8 additions & 2 deletions src/coreclr/minipal/Unix/doublemapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#include <linux/memfd.h>
#include <sys/syscall.h> // __NR_memfd_create
#define memfd_create(...) syscall(__NR_memfd_create, __VA_ARGS__)
#elif defined(TARGET_ANDROID)
#include <sys/syscall.h> // __NR_memfd_create
#define memfd_create(...) syscall(__NR_memfd_create, __VA_ARGS__)
#endif // TARGET_LINUX && !MFD_CLOEXEC
#include "minipal.h"
#include "minipal/cpufeatures.h"
Expand Down Expand Up @@ -48,12 +51,13 @@ bool VMToOSInterface::CreateDoubleMemoryMapper(void** pHandle, size_t *pMaxExecu

#ifdef TARGET_FREEBSD
int fd = shm_open(SHM_ANON, O_RDWR | O_CREAT, S_IRWXU);
#elif defined(TARGET_LINUX)
#elif defined(TARGET_LINUX) || defined(TARGET_ANDROID)
int fd = memfd_create("doublemapper", MFD_CLOEXEC);
#else
int fd = -1;
#endif

#ifndef TARGET_ANDROID
// Bionic doesn't have shm_{open,unlink}
// POSIX fallback
if (fd == -1)
{
Expand All @@ -64,11 +68,13 @@ 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)
{
return false;
}
#endif

if (ftruncate(fd, MaxDoubleMappedSize) == -1)
{
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/pal/src/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/pal/src/eventprovider/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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.
Copy link
Member

Choose a reason for hiding this comment

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

In lieu of a TODO, please file a github issue and provide a link in the comment.

if(CLR_CMAKE_HOST_LINUX AND NOT CLR_CMAKE_TARGET_ANDROID)
Copy link
Member

Choose a reason for hiding this comment

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

This should also use the host defines.

Suggested change
if(CLR_CMAKE_HOST_LINUX AND NOT CLR_CMAKE_TARGET_ANDROID)
if(CLR_CMAKE_HOST_LINUX AND NOT CLR_CMAKE_HOST_ANDROID)

add_subdirectory(lttngprovider)
else()
add_subdirectory(dummyprovider)
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/pal/src/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2558,6 +2558,8 @@ BOOL MAPMarkSectionAsNotNeeded(LPCVOID lpAddress)
}

BOOL retval = TRUE;

#ifndef TARGET_ANDROID
CPalThread * pThread = InternalGetCurrentThread();
InternalEnterCriticalSection(pThread, &mapping_critsec);
PLIST_ENTRY pLink, pLinkNext = NULL;
Expand Down Expand Up @@ -2588,6 +2590,7 @@ BOOL MAPMarkSectionAsNotNeeded(LPCVOID lpAddress)
}

InternalLeaveCriticalSection(pThread, &mapping_critsec);
#endif // TARGET_ANDROID

TRACE_(LOADER)("MAPMarkSectionAsNotNeeded returning %d\n", retval);
return retval;
Expand Down
16 changes: 12 additions & 4 deletions src/coreclr/runtime.proj
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,24 @@
<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_STL=c++_static"/>
<_CoreClrBuildArg Include="-DANDROID_CPP_FEATURES=&quot;no-rtti exceptions&quot;"/>
Comment on lines -81 to +82
Copy link
Member

Choose a reason for hiding this comment

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

Does this affect size of native AOT runtime packs? (Build with ./build.sh -ci -arch x64 -os linux-bionic -c Release /p:DotNetBuildRuntimeNativeAOTRuntimePack=true and check the size of libRuntime.WorkstationGC.a). We'll likely have to move this part of configuration someplace else, native AOT is the most size sensitive workload we have. Native AOT doesn't need C++ runtime library and doesn't need exceptions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it will affect the size, but less than if we included the shared libc++ (which is something we cannot do anyway) and I think we just need to pay the price. NativeAOT will be but one of the supported ways to build the application, we need to keep that in mind. I don't like the fact that CoreCLR needs exceptions (Android runtime doesn't use exceptions nor RTTI), but that's what we have and we need to support it (at least for the foreseeable future).

Ideally, for NativeAOT we should be able to link the application .so at the app build time (from a set of .o or .a files), in which case this setting here won't matter at all.

Copy link
Member

Choose a reason for hiding this comment

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

My question is whether we could set this in the CMake files instead of as argument to CMake. That way pieces of this can still compile with exceptions turned off instead of globally forcing the VM policy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure we can? The variables are used by the Android toolchain definition file - I think they need to be set on the command line for this to work.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah this needs to be set at the CMake build level sadly. There's not a supported way to do it per-target. We could likely manually set flags to do it if we figure out how the toolchain file sets flags.

<_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" />

<!-- No LTTNG on Android -->
<_CoreClrBuildArg Include="-cmakeargs -DFEATURE_EVENT_TRACE=0"/>
<!--
TODO: No LTTNG on Android, it's disabled at the eventprovider level. Will need an answer.
Copy link
Member

Choose a reason for hiding this comment

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

Same as above, please file an issue and add a link to the issue here.

Disabling FEATURE_EVENT_TRACE is too wide.
-->
<!--
Unsure if something like this is actually defined. We need this to differentiate between
features that are enabled in mono android, but not in coreclr.
-->
<_CoreClrBuildArg Include="-cmakeargs -DRUNTIME_CORECLR=1" />
Comment on lines +94 to +98
Copy link
Member

Choose a reason for hiding this comment

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

Is this used anywhere?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, one spot. Is there a better existing way to do this?

if (CLR_CMAKE_HOST_IOS OR CLR_CMAKE_HOST_TVOS OR (CLR_CMAKE_HOST_ANDROID AND NOT RUNTIME_CORECLR))

Copy link
Member

Choose a reason for hiding this comment

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

Could we add a general feature flag that the Mono vs CoreCLR builds would set?

Is this expected to work for the NativeAOT build?

</ItemGroup>

<PropertyGroup>
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/tools/Common/CommandLineHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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")
};
}
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/tools/Common/TypeSystem/Common/TargetDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public enum TargetOS
FreeBSD,
NetBSD,
SunOS,
WebAssembly
WebAssembly,
Android
steveisok marked this conversation as resolved.
Show resolved Hide resolved
}

public enum TargetAbi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 9 additions & 2 deletions src/coreclr/tools/aot/crossgen2/crossgen2.props
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,19 @@
<Compile Include="..\..\Common\InstructionSetHelpers.cs" Link="InstructionSetHelpers.cs" />
</ItemGroup>

<PropertyGroup>
<_LibPrefix Condition="'$(_IsCrossHostPublish)' == 'true'">$(LibPrefix)</_LibPrefix>
<_LibPrefix Condition="'$(_IsCrossHostPublish)' != 'true'">$(HostLibPrefix)</_LibPrefix>
<_LibSuffix Condition="'$(_IsCrossHostPublish)' == 'true'">$(LibSuffix)</_LibSuffix>
<_LibSuffix Condition="'$(_IsCrossHostPublish)' != 'true'">$(HostLibSuffix)</_LibSuffix>
steveisok marked this conversation as resolved.
Show resolved Hide resolved
</PropertyGroup>

<PropertyGroup>
<TargetArchitectureForSharedLibraries Condition="'$(CrossHostArch)' == ''">$(TargetArchitecture)</TargetArchitectureForSharedLibraries>
<TargetArchitectureForSharedLibraries Condition="'$(CrossHostArch)' != ''">$(CrossHostArch)</TargetArchitectureForSharedLibraries>
<TargetArchitectureForSharedLibraries Condition="'$(TargetArchitectureForSharedLibraries)'=='armel'">arm</TargetArchitectureForSharedLibraries>

<JitInterfaceLibraryName>$(LibPrefix)jitinterface_$(TargetArchitectureForSharedLibraries)$(LibSuffix)</JitInterfaceLibraryName>
<JitInterfaceLibraryName>$(_LibPrefix)jitinterface_$(TargetArchitectureForSharedLibraries)$(_LibSuffix)</JitInterfaceLibraryName>
</PropertyGroup>

<ItemGroup>
Expand All @@ -56,7 +63,7 @@
Link="%(FileName)%(Extension)"
/>

<Content Include="$(CoreCLRArtifactsPath)/$(CrossHostArch)/$(LibPrefix)clrjit_*_$(TargetArchitectureForSharedLibraries)$(LibSuffix)"
<Content Include="$(CoreCLRArtifactsPath)/$(CrossHostArch)/$(_LibPrefix)clrjit_*_$(TargetArchitectureForSharedLibraries)$(_LibSuffix)"
CopyToOutputDirectory="PreserveNewest"
CopyToPublishDirectory="PreserveNewest"
Link="%(FileName)%(Extension)"
Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
<!-- This project is publishes a self-contained copy of crossgen2. -->
<PropertyGroup>
<_IsPublishing>true</_IsPublishing>
<RuntimeIdentifier>$(PackageRID)</RuntimeIdentifier>
<RuntimeIdentifier Condition="'$(CrossBuild)' == 'true'">$(NETCoreSdkPortableRuntimeIdentifier)</RuntimeIdentifier>
<RuntimeIdentifier Condition="'$(CrossBuild)' != 'true'">$(PackageRID)</RuntimeIdentifier>
<PublishDir>$(RuntimeBinDir)crossgen2-published/</PublishDir>
<SelfContained>true</SelfContained>
<PublishTrimmed>true</PublishTrimmed>
<TrimmerSingleWarn>false</TrimmerSingleWarn>
<AotOrSingleFile>true</AotOrSingleFile>
<_IsCrossHostPublish>true</_IsCrossHostPublish>
steveisok marked this conversation as resolved.
Show resolved Hide resolved
</PropertyGroup>

<Import Project="crossgen2.props" />
Expand Down
Loading
Loading