-
Notifications
You must be signed in to change notification settings - Fork 552
[Xamarin.Android.Build.Tasks] implement $(AndroidStripILAfterAOT) #8172
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
815e374
[Xamarin.Android.Build.Tasks] implement $(AndroidStripIL)
jonathanpeppers 2d8bfff
Update parameter names
fanyang-mono d0db340
Disable removing attribute when AndroidStripIL is enanbled.
fanyang-mono f747395
Merge remote-tracking branch 'origin/main' into peppers/AndroidStripIL
fanyang-mono 19b2ab9
Add a test
fanyang-mono 6152320
Set default parameter values
fanyang-mono 0feee89
Add documentation of the new feature
fanyang-mono 747aabc
Simpler default for AndroidEnableProfiledAot
jonathanpeppers 0902fea
AndroidStripIL can default to empty
jonathanpeppers 6ac4b46
Update parameter name
fanyang-mono 647c8b9
Update build-properties.md
jonpryor b5dc596
Merge branch 'main' into AndroidStripIL
jonathanpeppers e4db7b8
EnableAndroidStripILAfterAOT asserts IL is stripped
jonathanpeppers 40475e2
`$(AndroidEnableProfiledAot)` test parameter
jonathanpeppers 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
using System.Text.RegularExpressions; | ||
using System.Xml.Linq; | ||
using System.Xml.XPath; | ||
using Mono.Cecil; | ||
using NUnit.Framework; | ||
using Xamarin.ProjectTools; | ||
|
||
|
@@ -1075,5 +1076,43 @@ public void SupportDesugaringStaticInterfaceMethods () | |
); | ||
} | ||
|
||
[Test] | ||
public void EnableAndroidStripILAfterAOT ([Values (false, true)] bool profiledAOT) | ||
{ | ||
var proj = new XamarinAndroidApplicationProject { | ||
ProjectName = nameof (EnableAndroidStripILAfterAOT), | ||
RootNamespace = nameof (EnableAndroidStripILAfterAOT), | ||
IsRelease = true, | ||
EnableDefaultItems = true, | ||
}; | ||
proj.SetProperty("AndroidStripILAfterAOT", "true"); | ||
proj.SetProperty("AndroidEnableProfiledAot", profiledAOT.ToString ()); | ||
// So we can use Mono.Cecil to open assemblies directly | ||
proj.SetProperty ("AndroidEnableAssemblyCompression", "false"); | ||
|
||
var builder = CreateApkBuilder (); | ||
Assert.IsTrue (builder.Build (proj), "`dotnet build` should succeed"); | ||
|
||
var apk = Path.Combine (Root, builder.ProjectDirectory, proj.OutputPath, $"{proj.PackageName}-Signed.apk"); | ||
FileAssert.Exists (apk); | ||
var helper = new ArchiveAssemblyHelper (apk); | ||
Assert.IsTrue (helper.Exists ($"assemblies/{proj.ProjectName}.dll"), $"{proj.ProjectName}.dll should exist in apk!"); | ||
using (var stream = helper.ReadEntry ($"assemblies/{proj.ProjectName}.dll")) { | ||
stream.Position = 0; | ||
using var assembly = AssemblyDefinition.ReadAssembly (stream); | ||
var type = assembly.MainModule.GetType ($"{proj.RootNamespace}.MainActivity"); | ||
var method = type.Methods.FirstOrDefault (p => p.Name == "OnCreate"); | ||
Assert.IsNotNull (method, $"{proj.RootNamespace}.MainActivity.OnCreate should exist!"); | ||
Assert.IsTrue (!method.HasBody || method.Body.Instructions.Count == 0, $"{proj.RootNamespace}.MainActivity.OnCreate should have no body!"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is probably expected, since I only zero'ed out method body and preserved method method header. |
||
} | ||
|
||
RunProjectAndAssert (proj, builder); | ||
|
||
WaitForPermissionActivity (Path.Combine (Root, builder.ProjectDirectory, "permission-logcat.log")); | ||
bool didLaunch = WaitForActivityToStart (proj.PackageName, "MainActivity", | ||
Path.Combine (Root, builder.ProjectDirectory, "logcat.log"), 30); | ||
Assert.IsTrue(didLaunch, "Activity should have started."); | ||
} | ||
|
||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
<Move/>
feels absurd to me:@(_ILStripTrimmedAssemblies)
is an output parameter, so I would normally intuit/assume that%(_ILStripTrimmedAssemblies.Identity)
is the file that was created. However, this<Move/>
implies that%(_ILStripTrimmedAssemblies.Identity)
has not in fact been created, and instead what was created is%(_ILStripTrimmedAssemblies.TrimmedAssemblyFileName)
, which must be moved to%(_ILStripTrimmedAssemblies.Identity)
.Does this make sense to anyone? Why was
<ILStrip/>
defined this way?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The goal of
ILStrip
is to trim IL code away from the assemblies which were AOT'ed. However, not all AOT'ed assemblies might be trimmable. That's why we have_ILStripTrimmedAssemblies
.ILStrip
also doesn't overwrite existing assemblies with the trimmed ones. It is designed this way, in case%(_ILStripTrimmedAssemblies.Identity)
are not the ones that you want to replace with the trimmed ones. They could be the ones which live in other directories. AndILStrip
could possibly has no knowledge of that.Here for
System.Private.CoreLib.dll
,%(_ILStripTrimmedAssemblies.Identity)
is<a_path>/System.Private.CoreLib.dll
%(_ILStripTrimmedAssemblies.TrimmedAssemblyFileName)
is<a_path>/System.Private.CoreLib_trimmed.dll
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fanyang-mono: how does
<ILStrip/>
know which method bodies it can remove? I see that the<MonoAOTCompiler/>
invocation was updated to add aMonoAOTCompiler.TrimmingEligibleMethodsOutputDirectory
property, but how does<ILStrip/>
konw about the$(IntermediateOutputPath)tokens
directory?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The output
_MonoAOTCompiledAssemblies
fromMonoAOTCompiler
has a metadataMethodTokenFile
. It stores the trimmable method token for the corresponding assembly.