[NativeAOT] Add trimmable type map build tests and decouple ILC from ILLink#11183
Open
[NativeAOT] Add trimmable type map build tests and decouple ILC from ILLink#11183
Conversation
…pe map Parameterize Build_WithTrimmableTypeMap_Succeeds and Build_WithTrimmableTypeMap_IncrementalBuild to run with both CoreCLR and NativeAOT runtimes. NativeAOT uses Release configuration (required). CoreCLR + Release is skipped pending upstream fixes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds build-test coverage for the trimmable typemap when using NativeAOT, and updates the NativeAOT MSBuild pipeline so ILC inputs are no longer hard-wired to ILLink output—allowing NativeAOT + trimmable builds to proceed without running ILLink.
Changes:
- Parameterize
TrimmableTypeMapBuildTeststo run for both CoreCLR and NativeAOT (with appropriate skips/ignores). - Update
Microsoft.Android.Sdk.NativeAOT.targetsso trimmable typemap builds skip ILLink and let the SDK’s standard NativeAOT input computation drive ILC references. - Adjust NativeCompile scheduling/dependencies to avoid ILLink/llvm-ir typemap-specific targets in the trimmable path.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/TrimmableTypeMapBuildTests.cs | Expands trimmable typemap build tests to cover both CoreCLR and NativeAOT configurations. |
| src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.NativeAOT.targets | Conditions ILLink integration and ILC input wiring so trimmable typemap NativeAOT builds don’t depend on ILLink output. |
3f37eef to
f5b66c8
Compare
Redesign _AndroidComputeIlcCompileInputs to populate IlcCompileInput and IlcReference from @(ResolvedFileToPublish) instead of hardcoding the $(IntermediateLinkDir) path. This matches the SDK contract in Microsoft.NETCore.Native.Publish.targets and works regardless of whether ILLink ran. When _AndroidTypeMapImplementation is 'trimmable': - Remove PrepareForILLink and ILLink from IlcCompileDependsOn - Skip _PrepareLinking dependency in _AndroidBeforeIlcCompile - Skip ILLink-specific settings (RunILLink, SuppressTrimAnalysisWarnings) - Skip _PreTrimmingFixLegacyDesignerUpdateItems in _AndroidRunNativeCompile Fixes #11182 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
_OriginalSuppressTrimAnalysisWarnings is only set in the ILLink-specific PropertyGroup (non-trimmable path). Without this condition, the restore in _AndroidComputeIlcCompileInputs would clobber SuppressTrimAnalysisWarnings with an empty value in the trimmable path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
f5b66c8 to
2b79e92
Compare
The ILC input wiring change results in a 470 KB size reduction in the native binary (10.2%) because the SDK's _ComputeIlcCompileInputs provides a cleaner set of references for ILC trimming. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Member
There was a problem hiding this comment.
I think we reduced the warnings on this one?
BuildHasNoWarnings(True,True,False,"apk",NativeAOT)
build.log should have exactly 120 MSBuild warnings for NativeAOT.
Expected: True
But was: False
Log has 92 Warning(s).
Honestly, I don't know if we care about the exact number, maybe the assert can just assert < 92 now? (so, it doesn't grow worse)
Removing the blanket TrimMode=All rooting for ILC inputs means ILC trims more unused code and produces fewer AOT analysis warnings (120 -> 92). Use Assert.LessOrEqual so the test does not break if warnings decrease further. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The trimmable path skips _PrepareLinking (ILLink-specific), but _PrepareLinking indirectly triggered _CreatePropertiesCache which resolves AndroidBinUtilsDirectory via _ResolveSdks. Without this, CompileNativeAssembly fails in the inner per-RID build. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
NativeAOT + trimmable builds fail at Java compilation because JavaInteropRuntime.java and NativeAotEnvironmentVars.java are not generated by the trimmable typemap path. Tracked in #11210. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This reverts commit b5eee26.
This reverts commit 71665b0.
The ILLink path needs TrimmerRootAssembly TrimMode=All for all ILLink-trimmed assemblies so ILC doesn't trim further. Without it, ILC removes JNI callback types that are invoked from Java at runtime, causing MemberAccessException crashes. The trimmable path doesn't need this because it doesn't run ILLink and ILC handles all trimming directly. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add build test coverage for NativeAOT with the trimmable type map, and decouple the ILC input wiring from ILLink so that NativeAOT builds work without running ILLink.
Test changes (
TrimmableTypeMapBuildTests.cs)Parameterize
Build_WithTrimmableTypeMap_SucceedsandBuild_WithTrimmableTypeMap_IncrementalBuildto run with both CoreCLR and NativeAOT runtimes:[Values] bool isRelease— NativeAOT requires Release, CoreCLR+Release skipped pending [TrimmableTypeMap] Add CoreCLRTrimmable Mono.Android.NET-Tests lane #11091[Values (AndroidRuntime.CoreCLR, AndroidRuntime.NativeAOT)] AndroidRuntime runtimeBuild pipeline changes (
Microsoft.Android.Sdk.NativeAOT.targets)When
_AndroidTypeMapImplementation=trimmable, skip ILLink and let ILC compile directly:IlcCompileDependsOn: conditionally removePrepareForILLinkandILLinkfor trimmable path_AndroidBeforeIlcCompile: skip_PrepareLinkingdependency and ILLink-specific settings (RunILLink,SuppressTrimAnalysisWarnings,_ExtraTrimmerArgs) for trimmable path_AndroidComputeIlcCompileInputs: remove the manualIlcCompileInput/IlcReferenceoverride that read from$(IntermediateLinkDir)linked/. Let the SDK's_ComputeIlcCompileInputs(fromMicrosoft.NETCore.Native.Publish.targets) populateIlcReferencefrom@(ResolvedFileToPublish)using the standardPostprocessAssemblymetadata contract. For the ILLink path, replace trimmedPrivateSdkAssembliesinIlcReferencewith untrimmed originals from the NativeAOT SDK pack (ILC needs them for--initassemblyruntime infrastructure)._AndroidRunNativeCompile: skip_PreTrimmingFixLegacyDesignerUpdateItemsdependency for trimmable pathContext
This content was created with assistance from AI.