Define TARGET_LINUX for Android native builds and preserve Android-specific exclusions#128826
Conversation
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
|
@copilot Are there any TARGET_LINUX uses that need to be modified to exclude TARGET_ANDROID with this change? |
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
I audited the affected native files for this PR and did not find any |
There was a problem hiding this comment.
Pull request overview
This PR standardizes native build-time OS macros so Android also defines TARGET_LINUX, and then simplifies a set of native #if guards that previously treated Linux and Android as separate-but-equivalent cases.
Changes:
- Define
TARGET_LINUXfor Android native builds (CoreCLR/native CMake + Mono CMake). - Collapse redundant
defined(TARGET_LINUX) || defined(TARGET_ANDROID)checks todefined(TARGET_LINUX)in several native components. - Update related
#else/#endifcomments and negated conditions to match the new invariant.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| eng/native/configurecompiler.cmake | Ensures Android emits TARGET_LINUX (via Linux target path) while still defining TARGET_ANDROID. |
| src/mono/CMakeLists.txt | Sets TARGET_LINUX for Android in Mono’s CMake configuration. |
| src/native/libs/System.Native/pal_time.c | Uses TARGET_LINUX as the single guard for the Linux/Android boot-time clock path. |
| src/native/libs/System.Native/pal_io.c | Simplifies Linux/Android filesystem-type guarding to TARGET_LINUX. |
| src/coreclr/pal/src/misc/cgroup.cpp | Collapses Linux/Android cgroup implementation guard to TARGET_LINUX and updates guard comments. |
| src/coreclr/gc/unix/cgroup.cpp | Collapses Linux/Android GC cgroup implementation guard to TARGET_LINUX and updates guard comments. |
| src/coreclr/nativeaot/Runtime/unix/PalUnix.cpp | Simplifies Linux/Android TLS-key guarding to TARGET_LINUX (with corresponding negated guard update). |
| src/coreclr/nativeaot/Runtime/unix/cgroupcpu.cpp | Collapses Linux/Android NativeAOT cgroup CPU guard to TARGET_LINUX and updates guard comments. |
| src/coreclr/minipal/Unix/doublemapping.cpp | Uses TARGET_LINUX as the single guard for the Linux/Android memfd_create path. |
| src/coreclr/inc/crosscomp.h | Simplifies Linux/Android DAC mutex sizing guard to TARGET_LINUX. |
|
@copilot Build break FAILED: Corehost.Static/singlefilehost
|
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Fixed in f9e3214. |
|
@copilot Tests are failing on Android Please double check that there are no other ifdefs condition that need adjusting for this change. |
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
... Fixed in 2d0161a. Android was entering CoreCLR's Linux NUMA path after Validated with:
AI-generated comment posted by Copilot. |
CLR_CMAKE_TARGET_LINUX is defined on Android
I do not think that this is same relationship as Linux vs. Android. In RID graph:
|
bionic is name libc used by Android. It is sibling of glibc and musl. Android in our build system means Android apps. it implies bionic libc, crypto via Java interop, and disables use of OS features that are blocked for Android apps. |
|
/ba-g infrastructure timeout |
Android was treated as Linux in managed constants (
TargetsLinux) but not consistently in native C/C++ compile-time defines. This change aligns the native side by definingTARGET_LINUXon Android and simplifying call sites that previously special-casedTARGET_ANDROID, while preserving Android-specific exclusions where Linux-only native behavior does not apply.Build-definition alignment
eng/native/configurecompiler.cmake: Android now emits bothTARGET_ANDROIDandTARGET_LINUX.src/mono/CMakeLists.txt: Android target setup now setsTARGET_LINUX(alongside existing Android/Bionic defines).Conditional cleanup
defined(TARGET_LINUX) || defined(TARGET_ANDROID)withdefined(TARGET_LINUX)where behavior is shared.Android-specific corrections
!defined(TARGET_ANDROID)exclusion insrc/native/corehost/corehost.cppfor static createdump initialization.src/coreclr/gc/unix/numasupport.cppand related call sites insrc/coreclr/gc/unix/gcenv.unix.cpp.TARGET_LINUXdefine.