-
Notifications
You must be signed in to change notification settings - Fork 567
[WIP] Run FixLegacyResourceDesigner before trimming #11084
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sbomer
wants to merge
16
commits into
main
Choose a base branch
from
dev/sbomer/fix-legacy-before-trim
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
70f7f30
[illink] Move FixLegacyResourceDesignerStep to post-trim pipeline
sbomer 77de75d
[targets] Fix NativeAOT designer assembly trimming
sbomer e9edefd
Merge remote-tracking branch 'origin/main' into fix-resource-designer
sbomer f0059fd
Fix merge conflict: remove FixAbstractMethodsStep from ILLink csproj
sbomer 64d4ed1
Root designer assembly to prevent ILLink from trimming resource prope…
sbomer 924649e
Use TrimmerRootDescriptor instead of TrimmerRootAssembly for designer…
sbomer 8be3817
Update SkiaSharp test to expect XA8000 instead of IL8000 for release …
sbomer f12d747
Merge remote-tracking branch 'origin/main' into fix-resource-designer
sbomer 83a8f64
Fix incremental build: use WriteOnlyWhenDifferent for linker descriptor
sbomer 6e870ef
Add TODO to simplify TrimmerRootDescriptor once dotnet/runtime#126518…
sbomer 4c4c091
Move FixLegacyResourceDesignerStep to run before ILLink trimming
sbomer 5e3ba1f
Fix SkiaSharp NativeAOT test to expect XA8000 build failure
sbomer 432b1b2
Filter framework/main assemblies in PreTrimmingFixLegacyDesigner for …
sbomer 548ba35
Merge branch 'main' into dev/sbomer/fix-legacy-before-trim
sbomer 7b72611
Filter pre/post trimming assemblies by PostprocessAssembly metadata
sbomer 0dbbbee
Open assemblies read-only in PreTrimmingFixLegacyDesigner
sbomer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
71 changes: 71 additions & 0 deletions
71
src/Xamarin.Android.Build.Tasks/Tasks/PreTrimmingFixLegacyDesigner.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| #nullable enable | ||
|
|
||
| using System.IO; | ||
| using Java.Interop.Tools.Cecil; | ||
| using Microsoft.Android.Build.Tasks; | ||
| using Microsoft.Build.Framework; | ||
| using Mono.Cecil; | ||
| using MonoDroid.Tuner; | ||
|
|
||
| namespace Xamarin.Android.Tasks; | ||
|
|
||
| /// <summary> | ||
| /// Runs <see cref="FixLegacyResourceDesignerStep"/> on assemblies that are about to be | ||
| /// trimmed by ILLink. This rewrites library assemblies so their resource field accesses | ||
| /// (ldsfld) become calls to the designer assembly's property getters. | ||
| /// | ||
| /// Running this *before* ILLink means the trimmer sees the rewritten IL and can freely | ||
| /// trim unused designer types/fields. This avoids the need to root the entire designer | ||
| /// assembly during trimming (which causes an APK size regression). | ||
| /// </summary> | ||
| public class PreTrimmingFixLegacyDesigner : AndroidTask | ||
| { | ||
| public override string TaskPrefix => "PTD"; | ||
|
|
||
| [Required] | ||
| public ITaskItem [] Assemblies { get; set; } = []; | ||
|
|
||
| [Required] | ||
| public string TargetName { get; set; } = ""; | ||
|
|
||
| public bool Deterministic { get; set; } | ||
|
|
||
| public override bool RunTask () | ||
| { | ||
| using var resolver = new DirectoryAssemblyResolver ( | ||
| this.CreateTaskLogger (), loadDebugSymbols: true); | ||
|
|
||
| foreach (var assembly in Assemblies) { | ||
| var dir = Path.GetFullPath (Path.GetDirectoryName (assembly.ItemSpec) ?? ""); | ||
| if (!resolver.SearchDirectories.Contains (dir)) { | ||
| resolver.SearchDirectories.Add (dir); | ||
| } | ||
| } | ||
|
|
||
| var linkContext = new MSBuildLinkContext (resolver, Log); | ||
| var fixLegacyStep = new FixLegacyResourceDesignerStep (); | ||
| fixLegacyStep.Initialize (linkContext); | ||
|
|
||
| foreach (var item in Assemblies) { | ||
| // Match the filtering in FixLegacyResourceDesignerStep.ProcessAssembly: | ||
| // skip the main assembly and framework/BCL assemblies. | ||
| if (Path.GetFileNameWithoutExtension (item.ItemSpec) == TargetName) { | ||
| continue; | ||
| } | ||
| if (MonoAndroidHelper.IsFrameworkAssembly (item)) { | ||
| continue; | ||
| } | ||
|
|
||
| var assembly = resolver.GetAssembly (item.ItemSpec); | ||
| if (fixLegacyStep.ProcessAssemblyDesigner (assembly)) { | ||
| Log.LogDebugMessage ($" Writing modified assembly: {item.ItemSpec}"); | ||
| assembly.Write (item.ItemSpec, new WriterParameters { | ||
| WriteSymbols = assembly.MainModule.HasSymbols, | ||
| DeterministicMvid = Deterministic, | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| return !Log.HasLoggedErrors; | ||
| } | ||
| } |
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.