8000 [nativeaot] Next steps for the NAOT runtime by grendello · Pull Request #10476 · dotnet/android · GitHub
[go: up one dir, main page]

Skip to content

Conversation

grendello
Copy link
Contributor
@grendello grendello commented Sep 11, 2025

Context: # 8000 10461

A follow up to #10461 which adds some more compatibility with the "standard"
MonoVM and CoreCLR runtime hosts, namely:

  • Support for setting environment variables via the environment file
    (<AndroidEnvironment> MSBuild item)
  • Support for setting local (that is, application level, not system
    level) system properties

In addition to the above, it makes NativeAOT use static libc++ instead of the
shared one, which not only shrinks the package size (libc++_shared.so is
around 9mb), but it also makes startup slightly faster.

@grendello grendello force-pushed the dev/grendel/naot-next-steps branch 4 times, most recently from c830a14 to 2d7ffcb Compare September 17, 2025 12:06
@grendello grendello marked this pull request as ready for review September 17, 2025 12:12
@grendello grendello requested a review from Copilot September 17, 2025 12:52
Copy link
@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements compatibility improvements for the NativeAOT runtime to align it more closely with MonoVM and CoreCLR runtime hosts. It adds support for setting environment variables via <AndroidEnvironment> MSBuild items and local system properties, while also optimizing package size and startup performance by switching from shared to static libc++.

Key changes include:

  • Unified environment variable and system property handling across runtime hosts
  • Infrastructure for NativeAOT to process environment files and system properties
  • Static linking of libc++ instead of shared library to reduce package size (~9MB) and improve startup

Reviewed Changes

Copilot reviewed 16 out of 17 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/native/nativeaot/runtime-base/android-system.cc Updates system property lookup to use shared HostEnvironment implementation
src/native/nativeaot/include/host/host-environment-naot.hh Adds NativeAOT-specific environment structure declarations and extern symbols
src/native/nativeaot/include/host/host-environment.hh Removes old NativeAOT-only environment class (file deleted)
src/native/nativeaot/host/host.cc Updates include to use new NativeAOT-specific header
src/native/nativeaot/host/host-environment.cc Refactors environment initialization to use templated approach for both variables and properties
src/native/clr/xamarin-app-stub/application_dso_stub.cc Updates system properties structure and adds JNI library flags to DSO cache entries
src/native/clr/runtime-base/android-system.cc Refactors to use shared HostEnvironment methods for setting variables and properties
src/native/clr/include/xamarin-app.hh Changes system properties from string array to AppEnvironmentVariable structure
src/native/clr/include/host/host-environment.hh Adds new shared HostEnvironment class with templated setter methods
src/native/clr/include/host/host-environment-clr.hh Minimal header to include CLR-specific environment dependencies
src/Xamarin.Android.Build.Tasks/Utilities/NativeAotEnvironmentNativeAssemblyGenerator.cs Adds system property generation using same structure as environment variables
src/Xamarin.Android.Build.Tasks/Utilities/ApplicationConfigNativeAssemblyGeneratorCLR.cs Refactors CLR system property generation to use unified structure
src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.NativeAOT.targets Switches from shared libc++ to static linking and removes conflicting libraries
samples/NativeAOT/run.sh Uncomments debug logging for testing
samples/NativeAOT/environment.txt Adds test system property
samples/NativeAOT/NativeAOT.csproj Includes environment.txt as AndroidEnvironment item

@grendello
Copy link
Contributor Author

/azp run

Copy link
Azure Pipelines successfully started running 1 pipeline(s).

@filipnavara
Copy link
Member
filipnavara commented Sep 17, 2025

Tested on our app and it still launches. The size decrease is ~2Mb (for single RID; compressed size).

Before: com.emclient.mailclient-Signed.apk 71998960
After: com.emclient.mailclient-Signed.apk 69803431

(-9MB for the uncompressed libc++_shared.so, +540Kb for uncompressed size in the statically linked C++ library inside main .so)

@grendello grendello merged commit 4a09dd4 into main Sep 18, 2025
59 checks passed
@grendello grendello deleted the dev/grendel/naot-next-steps branch September 18, 2025 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0