Move FixLegacyResourceDesignerStep to post-trim pipeline#11059
Move FixLegacyResourceDesignerStep to post-trim pipeline#11059
Conversation
Migrate FixLegacyResourceDesignerStep out of the ILLink trimmer process and into PostTrimmingPipeline, continuing the work in #10842 to remove custom ILLink steps. The step now runs after ILLink via a thin wrapper (PostTrimmingFixLegacyResourceDesignerStep) that calls ProcessAssemblyDesigner() directly, matching the former ILLink behavior. - Remove all #if ILLINK conditionals from FixLegacyResourceDesignerStep, LinkDesignerBase, and BaseStep - Remove FixLegacyResourceDesignerStep and LinkDesignerBase from the ILLink project (no longer compiled as a trimmer step) - Add UseDesignerAssembly property to PostTrimmingPipeline task - Wire AndroidUseDesignerAssembly through targets to PostTrimmingPipeline - Remove _TrimmerCustomSteps entry for FixLegacyResourceDesignerStep
There was a problem hiding this comment.
Pull request overview
Moves FixLegacyResourceDesignerStep out of the ILLink custom-step mechanism and into the PostTrimmingPipeline MSBuild task so the legacy designer fix runs after ILLink, aligning with the ongoing effort to eliminate _TrimmerCustomSteps-based customization.
Changes:
- Adds a
UseDesignerAssemblyswitch toPostTrimmingPipelineand runs the legacy resource-designer fix via a thin post-trim wrapper. - Removes
FixLegacyResourceDesignerStep/LinkDesignerBasefrom theMicrosoft.Android.Sdk.ILLinkproject and deletes the corresponding_TrimmerCustomStepsregistration. - Removes
#if ILLINKconditional paths from the step/base classes now that they no longer compile into the ILLink step assembly.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj | Ensures linker-related sources used by PostTrimmingPipeline include LinkDesignerBase. |
| src/Xamarin.Android.Build.Tasks/Tasks/PostTrimmingPipeline.cs | Adds UseDesignerAssembly and invokes the legacy designer fix post-ILLink via PostTrimmingFixLegacyResourceDesignerStep. |
| src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.TypeMap.LlvmIr.targets | Removes _TrimmerCustomSteps registration for the legacy designer fix and wires AndroidUseDesignerAssembly into PostTrimmingPipeline. |
| src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/LinkDesignerBase.cs | Removes ILLink-specific conditional logging paths. |
| src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/FixLegacyResourceDesignerStep.cs | Makes the step unconditionally implement the post-trim pipeline interface and removes ILLink-only conditionals. |
| src/Xamarin.Android.Build.Tasks/Linker/External/Linker.Steps/BaseStep.cs | Removes ILLink-specific conditional error logging path. |
| src/Microsoft.Android.Sdk.ILLink/Microsoft.Android.Sdk.ILLink.csproj | Stops compiling FixLegacyResourceDesignerStep and LinkDesignerBase into the ILLink step assembly. |
|
Somehow a lot of tests get an error like: Maybe the assembly resolver is missing some search directories? And that is what made it work before this change? |
In NativeAOT builds, _AddResourceDesignerToPublishFiles ran after _ComputeManagedAssemblyToLink, so the designer assembly was not in ManagedAssemblyToLink. ILLink skipped the designer assembly entirely and did not rewrite its netstandard references. Fix by adding _AddResourceDesignerToPublishFiles to _PrepareLinking's DependsOnTargets, so the designer is passed to ILLink.
# Conflicts: # src/Microsoft.Android.Sdk.ILLink/Microsoft.Android.Sdk.ILLink.csproj
FixAbstractMethodsStep was moved from ILLink to the post-trim pipeline on main (7ae24aa). The merge conflict resolution incorrectly kept the Compile include, but the file now uses types not available in the ILLink project (IAssemblyModifierPipelineStep, StepContext, Properties.Resources).
…rties FixLegacyResourceDesignerStep now runs in PostTrimmingPipeline (after ILLink) instead of as an ILLink custom step. Previously, the step ran before MarkStep and rewrote library assemblies to reference designer properties, which caused MarkStep to preserve them. Now that the rewriting happens after ILLink, we must root the designer assembly so all resource properties survive trimming. Add TrimmerRootAssembly for the designer in _AddResourceDesignerToPublishFiles. This keeps IsTrimmable=true (action=link) so ILLink still rewrites the netstandard assembly reference, but roots all types so nothing is trimmed. An alternative approach would be to run FixLegacyResourceDesignerStep before ILLink instead of after. That would allow ILLink to trim unused resource properties from the designer (since the rewritten references would already be in place for MarkStep), but it would also process resource references in assemblies that ILLink may later remove entirely.
… assembly TrimmerRootAssembly (-a flag) makes the designer an entry point, which causes ILLink to retain netstandard.dll as a dependency, leaking it into the APK (+19KB). TrimmerRootDescriptor (-x flag) preserves all designer types/members without making it an entry point, avoiding the regression.
…builds FixLegacyResourceDesignerStep now runs in PostTrimmingPipeline (MSBuild task) instead of inside ILLink, so the error code is always XA8000 regardless of build configuration.
WriteLinesToFile was regenerating the TrimmerRootDescriptor XML on every build, changing its timestamp and causing ILLink to re-run on incremental builds. Adding WriteOnlyWhenDifferent preserves the timestamp when the content hasn't changed.
FixLegacyResourceDesignerStep now runs in PostTrimmingPipeline for all runtimes including NativeAOT, so the missing @styleable/SKCanvasView resources correctly produce XA8000 errors. Remove the NativeAOT exclusion from the addResource=False path.
FixLegacyResourceDesignerStep now runs post-ILLink with preserve=all, keeping all designer properties instead of only those referenced by libraries. This increases the designer assembly from ~19KB to ~135KB in the XForms MonoVM test app (1% of total APK size). Other baselines updated for SDK changes from the main branch merge.
bc8256f to
1eec909
Compare
The problem was that the post-trim I worked around this by passing the designer assembly through ILLink (as a root) to let it fix up the references. The downside of running this step after ILLink is that the shared designer assembly no longer gets trimmed, leading to a size increase. In #11084 I'm trying to move the step to run before ILLink, but that requires some larger changes to the build logic, so if we are ok with the size increase, I think we should take it for now. @jonathanpeppers |
Migrate FixLegacyResourceDesignerStep out of the ILLink trimmer process and into PostTrimmingPipeline, continuing the work in #10842 to remove custom ILLink steps. The step now runs after ILLink via a thin wrapper (PostTrimmingFixLegacyResourceDesignerStep) that calls ProcessAssemblyDesigner() directly, matching the former ILLink behavior.