Make PrepareTrimConfiguration a public extension point#127253
Make PrepareTrimConfiguration a public extension point#127253sbomer wants to merge 2 commits intodotnet:mainfrom
Conversation
|
Tagging subscribers to this area: @agocke, @dotnet/illink |
Rename _PrepareTrimConfiguration to PrepareTrimConfiguration so that external SDKs (e.g. MAUI) can hook BeforeTargets="PrepareTrimConfiguration" to add RuntimeHostConfigurationOption items before they are snapshotted into _TrimmerFeatureSettings. PR dotnet#124801 extracted the RHCO → _TrimmerFeatureSettings conversion from PrepareForILLink into _PrepareTrimConfiguration, which runs as a dependency of PrepareForILLink. This caused MAUI's feature switches (added via BeforeTargets="PrepareForILLink") to arrive after the snapshot, so ILC never received --feature flags for switches like IsHybridWebViewSupported. The result was spurious IL3050 warnings on Android NativeAOT where RunILLink=true. Making the target public gives SDKs a stable, intentional hook point for adding feature switch configuration that flows to both ILLink and ILC. Fixes dotnet#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
This PR makes the trim configuration target a public MSBuild extension point so external SDKs can reliably add RuntimeHostConfigurationOption items before they’re snapshotted into _TrimmerFeatureSettings (and thus flow into both ILLink and ILC/NativeAOT). It also includes a linker marking behavior change around type-forwarders, with new tests covering the scenarios.
Changes:
- Rename
_PrepareTrimConfigurationtoPrepareTrimConfigurationand retarget dependencies to the new public name. - Update NativeAOT publish targets to depend on / order around
PrepareTrimConfiguration. - Adjust ILLink MarkStep behavior for type-forwarding scenarios and add new test cases (plus ILTrim expected-failure entries).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/tools/illink/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets | Renames target to PrepareTrimConfiguration and documents it as an extension point; updates dependent target to use new name. |
| src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets | Switches dependencies and ordering from _PrepareTrimConfiguration to PrepareTrimConfiguration. |
| src/tools/illink/src/linker/Linker.Steps/MarkStep.cs | Changes marking behavior for exported types/type references in rooted/copy scenarios. |
| src/tools/illink/test/Mono.Linker.Tests.Cases/TypeForwarding/RootedForwarderWithExportedTypesIsHandled.cs | New linker test for rooted forwarder assemblies with exported types. |
| src/tools/illink/test/Mono.Linker.Tests.Cases/TypeForwarding/UsedForwarderIsRemovedWhenReferencedByRootedAssembly.cs | New linker test ensuring forwarder removal even when the referencing assembly is rooted. |
| src/coreclr/tools/ILTrim.Tests/ILTrimExpectedFailures.txt | Adds the two new TypeForwarding tests to ILTrim’s expected-failure list. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR makes PrepareTrimConfiguration a public MSBuild extension point so external SDKs (e.g., MAUI) can reliably inject RuntimeHostConfigurationOption items before those settings are snapshotted into _TrimmerFeatureSettings and used by both ILLink and ILC (NativeAOT).
Changes:
- Renamed the internal target
_PrepareTrimConfigurationtoPrepareTrimConfigurationin ILLink targets and documented it as a public hook point. - Updated NativeAOT publish target dependencies/orderings to reference
PrepareTrimConfigurationinstead of_PrepareTrimConfiguration.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/tools/illink/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets | Exposes PrepareTrimConfiguration as a public target and wires _ComputeManagedAssemblyToLink to depend on it. |
| src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets | Updates NativeAOT pipeline targets to depend on / schedule around the newly public PrepareTrimConfiguration. |
|
Why is MAUI adding this in a target? This sounds like just asking for trouble. Is it guaranteed that this will end up in runtimeconfig.json in non-trimmed scenarios? |
Note
This PR was created with assistance from AI.
Summary
Rename
_PrepareTrimConfigurationtoPrepareTrimConfigurationso that external SDKs can hookBeforeTargets="PrepareTrimConfiguration"to addRuntimeHostConfigurationOptionitems before they are snapshotted into_TrimmerFeatureSettings.Problem
PR #124801 extracted the
RuntimeHostConfigurationOption→_TrimmerFeatureSettingsconversion fromPrepareForILLinkinto a new internal target_PrepareTrimConfiguration. This target runs as a transitive dependency ofPrepareForILLink(via_ComputeManagedAssemblyToLink), so it executes beforeBeforeTargets="PrepareForILLink"hooks fire.MAUI adds its feature switches (e.g.
IsHybridWebViewSupported) viaBeforeTargets="PrepareForILLink". After #124801, these items arrive after_PrepareTrimConfigurationhas already snapshottedRuntimeHostConfigurationOptioninto_TrimmerFeatureSettings. As a result, ILC never receives--featureflags for MAUI's switches on Android NativeAOT (whereRunILLink=true), causing spurious IL3050 warnings.Fix
Make
PrepareTrimConfigurationa public target so SDKs have a stable, intentional hook point for adding feature switch configuration that flows to both ILLink and ILC. MAUI (and other SDKs) can then useBeforeTargets="PrepareTrimConfiguration"to add theirRuntimeHostConfigurationOptionitems before the snapshot.Verified
Tested with a MAUI Android NativeAOT app:
--feature:Microsoft.Maui.RuntimeFeature.IsHybridWebViewSupported=falsemissing from ILC rsp → IL3050 emitted--featureflag present → IL3050 suppressed by FeatureGuardFixes #127017
cc @sbomer @simonrozsival