[NativeAOT] Hook _PrepareTrimConfiguration to fix IL3050 on Android#35071
[NativeAOT] Hook _PrepareTrimConfiguration to fix IL3050 on Android#35071
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 35071Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 35071" |
Add _PrepareTrimConfiguration to _MauiPrepareForILLink's BeforeTargets so that RuntimeHostConfigurationOption items (like IsHybridWebViewSupported) are added before the runtime's _PrepareTrimConfiguration target snapshots them into _TrimmerFeatureSettings. Without this, ILC never receives --feature flags for MAUI's feature switches on Android where RunILLink=true, causing spurious IL3050 warnings. This is a temporary workaround using the internal target name. Once dotnet/runtime ships the fix (renaming to public PrepareTrimConfiguration), this should be updated to BeforeTargets="PrepareTrimConfiguration". Workaround for dotnet/runtime#127017 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Assisted-by: Claude:claude-opus-4.6-1m
There was a problem hiding this comment.
Pull request overview
Updates MAUI’s transitive MSBuild targets so MAUI’s RuntimeHostConfigurationOption feature switches are applied early enough for Android NativeAOT trimming to pick them up, avoiding spurious IL3050 warnings.
Changes:
- Hook
_MauiPrepareForILLinkto run before the runtime’s earlier trim-configuration snapshot target (_PrepareTrimConfiguration).
| </Target> | ||
|
|
||
| <Target Name="_MauiPrepareForILLink" BeforeTargets="PrepareForILLink;_GenerateRuntimeConfigurationFilesInputCache;XamlC"> | ||
| <Target Name="_MauiPrepareForILLink" BeforeTargets="_PrepareTrimConfiguration;PrepareForILLink;_GenerateRuntimeConfigurationFilesInputCache;XamlC"> |
There was a problem hiding this comment.
Consider adding the public target name PrepareTrimConfiguration to the BeforeTargets list as well (e.g., PrepareTrimConfiguration;_PrepareTrimConfiguration;...). This keeps the workaround working both before and after the runtime target rename (and is safe because MSBuild ignores non-existent targets).
| <Target Name="_MauiPrepareForILLink" BeforeTargets="_PrepareTrimConfiguration;PrepareForILLink;_GenerateRuntimeConfigurationFilesInputCache;XamlC"> | |
| <Target Name="_MauiPrepareForILLink" BeforeTargets="PrepareTrimConfiguration;_PrepareTrimConfiguration;PrepareForILLink;_GenerateRuntimeConfigurationFilesInputCache;XamlC"> |
dede0fd to
6d0657c
Compare
jonathanpeppers
left a comment
There was a problem hiding this comment.
Looks OK, I just had one question.
| </Target> | ||
|
|
||
| <Target Name="_MauiPrepareForILLink" BeforeTargets="PrepareForILLink;_GenerateRuntimeConfigurationFilesInputCache;XamlC"> | ||
| <Target Name="_MauiPrepareForILLink" BeforeTargets="_PrepareTrimConfiguration;_GenerateRuntimeConfigurationFilesInputCache;XamlC"> |
There was a problem hiding this comment.
Are we OK to use a private target name, like _PrepareTrimConfiguration, any chance it would be renamed?
There was a problem hiding this comment.
It could be renamed or modified - this is relying on an implementation detail. See #35163.
I considered making PrepareTrimConfiguration public in dotnet/runtime#127253 but I no longer think that's a good idea.
…Android (#35094) > [!NOTE] > This PR was created with assistance from AI. Port of #35071 to the `net11.0` branch. ## Summary Add `_PrepareTrimConfiguration` to `_MauiPrepareForILLink`'s `BeforeTargets` so that `RuntimeHostConfigurationOption` items (like `IsHybridWebViewSupported`) are added before the runtime's internal target snapshots them into `_TrimmerFeatureSettings`. ## Problem dotnet/runtime PR #124801 moved the `RuntimeHostConfigurationOption` → `_TrimmerFeatureSettings` conversion from `PrepareForILLink` into an earlier internal target (`_PrepareTrimConfiguration`). MAUI's `_MauiPrepareForILLink` hooks `BeforeTargets="PrepareForILLink"`, which now fires *after* the snapshot. As a result, ILC never receives `--feature` flags for MAUI's feature switches on Android NativeAOT, causing spurious IL3050 warnings for `HybridWebViewHandler`. This is the branch (`net11.0`, SDK `11.0.100-preview.3.26203.107`) where the bug manifests — the .NET 11 SDK has `_PrepareTrimConfiguration`. ## Fix Remove `PrepareForILLink` from `BeforeTargets` (redundant — it's a transitive dependent of `_PrepareTrimConfiguration`) and add `_PrepareTrimConfiguration` instead. This ensures MAUI's `RuntimeHostConfigurationOption` items are present when the snapshot runs. **Temporary workaround** using the internal target name. The runtime fix (dotnet/runtime#127253) renames this to the public `PrepareTrimConfiguration`. Once that flows, update to `BeforeTargets="PrepareTrimConfiguration"`. Workaround for dotnet/runtime#127017 cc @sbomer @simonrozsival Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
@sbomer main is net10.0 only and will never bet net11.0 until we go GA with net11.0 and just merge the whole thing back into main do we need this PR?
The same 1-line change (
Bottom line:
|
|
Cloing this since the fix is in |
Note
This PR was created with assistance from AI.
Summary
Add
_PrepareTrimConfigurationto_MauiPrepareForILLink'sBeforeTargetsso thatRuntimeHostConfigurationOptionitems (likeIsHybridWebViewSupported) are added before the runtime's internal target snapshots them into_TrimmerFeatureSettings.Problem
dotnet/runtime PR #124801 moved the
RuntimeHostConfigurationOption→_TrimmerFeatureSettingsconversion fromPrepareForILLinkinto an earlier internal target (_PrepareTrimConfiguration). MAUI's_MauiPrepareForILLinkhooksBeforeTargets="PrepareForILLink", which now fires after the snapshot. As a result, ILC never receives--featureflags for MAUI's feature switches on Android NativeAOT, causing spurious IL3050 warnings forHybridWebViewHandler.Fix
Add
_PrepareTrimConfigurationto theBeforeTargetslist of_MauiPrepareForILLink. This ensures MAUI'sRuntimeHostConfigurationOptionitems are present when the snapshot runs.This is a temporary workaround using the internal target name. The runtime fix (dotnet/runtime#127253) renames this to the public
PrepareTrimConfiguration. Once that flows, this should be updated toBeforeTargets="PrepareTrimConfiguration;PrepareForILLink;...".Verified
Tested with a MAUI Android NativeAOT app using the
android-il3050local build:--feature:Microsoft.Maui.RuntimeFeature.IsHybridWebViewSupported=falsemissing → IL3050--featureflag present → IL3050 suppressedWorkaround for dotnet/runtime#127017
cc @sbomer @simonrozsival