-
Notifications
You must be signed in to change notification settings - Fork 533
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes: #6052 Helpful reading: * https://github.com/dotnet/runtime/blob/15dec9a2aa5a4236d6ba70de2e9c146867b9d2e0/src/tasks/AotCompilerTask/MonoAOTCompiler.cs * https://github.com/dotnet/runtime/blob/15dec9a2aa5a4236d6ba70de2e9c146867b9d2e0/src/mono/netcore/nuget/Microsoft.NET.Runtime.MonoAOTCompiler.Task/README.md To make this work, I moved the existing `<Aot/>` MSBuild task calls to a new `_AndroidAot` MSBuild target in `Xamarin.Android.Legacy.targets`. In the .NET 6 targets, there is a *different* `_AndroidAot` MSBuild target that runs the new `<MonoAOTCompiler/>` MSBuild task. The `_AndroidAot` target runs once per `$(RuntimeIdentifier)`, after the linker completes. Native libraries are added to the `@(ResolvedFileToPublish)` item group to be included in the final `.apk`. To follow [convention with Blazor WASM][0], the `$(RunAOTCompilation)` MSBuild property enables AOT. To help with backwards compatibility with "legacy" Xamarin.Android, I kept the `$(AotAssemblies)` MSBuild property intact. Unfortunately, we have to manually import things to support `$(AotAssemblies)`: <ImportGroup Condition=" '$(MonoAOTCompilerTasksAssemblyPath)' == '' and '$(AotAssemblies)' == 'true' "> <Import Project="Sdk.props" Sdk="Microsoft.NET.Runtime.MonoAOTCompiler.Task" /> <Import Project="Sdk.props" Sdk="Microsoft.NETCore.App.Runtime.AOT.Cross.android-x86" /> <Import Project="Sdk.props" Sdk="Microsoft.NETCore.App.Runtime.AOT.Cross.android-x64" /> <Import Project="Sdk.props" Sdk="Microsoft.NETCore.App.Runtime.AOT.Cross.android-arm" /> <Import Project="Sdk.props" Sdk="Microsoft.NETCore.App.Runtime.AOT.Cross.android-arm64" /> </ImportGroup> as the [default Mono workload does not support `$(AotAssemblies)`][1]. I think this is reasonable for now. ~~ Limitations ~~ Profiled AOT is not implemented yet: * #6053 `$(EnableLLVM)` fails when locating `opt`: * dotnet/runtime#56386 `$(AndroidClientHandler)` usage causes runtime crash: * dotnet/runtime#56315 Use of folder names like `Build AndÜmläüts` fails: * dotnet/runtime#56163 ~~ Results ~~ All tests: 1. Were running on a [Google Pixel 5][2], and 2. Enabled two architectures, arm64 and x86, and 3. **JIT time** was average of 10 runs with `-c Release`, with the `Activity: Displayed` time, and 4. **AOT time** was average of 10 runs with `-c Release -p:RunAOTCompilation=true` with the `Activity: Displayed` time. 5. Δ values are (AOT / JIT)*100. | Test | JIT time | AOT time | Δ time | JIT apk size | AOT apk size | Δ size | | ------------------- | ------------: | ------------: | ------: | ------------: | ------------: | -----: | | [HelloAndroid][3] | 00:00:00.308 | 00:00:00.209 | 68% | 8,367,969 | 12,082,123 | 144.4% | | [HelloMaui][4] | 00:00:01.117 | 00:00:00.568 | 51% | 16,272,964 | 42,869,016 | 263.4% | [0]: https://devblogs.microsoft.com/aspnet/asp-net-core-updates-in-net-6-preview-4/#blazor-webassembly-ahead-of-time-aot-compilation [1]: https://github.com/dotnet/runtime/blob/69711860262e44458bbe276393ea3eb9f7a2192a/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.Manifest/WorkloadManifest.targets.in#L20-L25 [2]: https://store.google.com/us/product/pixel_5_specs?hl=en-US [3]: https://github.com/dotnet/maui-samples/tree/714460431541f40570e91225e8ba4bc1fe08025f/HelloAndroid [4]: https://github.com/dotnet/maui-samples/tree/714460431541f40570e91225e8ba4bc1fe08025f/HelloMaui
- Loading branch information
1 parent
7e1558c
commit c929289
Showing
19 changed files
with
543 additions
and
263 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
87 changes: 87 additions & 0 deletions
87
...marin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.Aot.targets
This file contains 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,87 @@ | ||
<!-- | ||
*********************************************************************************************** | ||
Microsoft.Android.Sdk.Aot.targets | ||
.NET 6 AOT support. You can find "legacy" Xamarin.Android AOT support | ||
in Xamarin.Android.Legacy.targets. | ||
For <MonoAOTCompiler/> usage, see: | ||
* https://github.com/dotnet/runtime/blob/15dec9a2aa5a4236d6ba70de2e9c146867b9d2e0/src/tasks/AotCompilerTask/MonoAOTCompiler.cs | ||
* https://github.com/dotnet/runtime/blob/15dec9a2aa5a4236d6ba70de2e9c146867b9d2e0/src/mono/netcore/nuget/Microsoft.NET.Runtime.MonoAOTCompiler.Task/README.md | ||
These targets are running within the _ComputeFilesToPublishForRuntimeIdentifiers target. | ||
They run in a context of an inner build with a single $(RuntimeIdentifier). | ||
*********************************************************************************************** | ||
--> | ||
<Project> | ||
|
||
<!-- | ||
NOTE: currently, the only way to allow $(AotAssemblies) in | ||
.csproj files is to import these in the Android workload | ||
when $(MonoAOTCompilerTasksAssemblyPath) is blank: | ||
https://github.com/dotnet/runtime/blob/69711860262e44458bbe276393ea3eb9f7a2192a/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.Manifest/WorkloadManifest.targets.in#L20-L25 | ||
--> | ||
<ImportGroup Condition=" '$(MonoAOTCompilerTasksAssemblyPath)' == '' and '$(AotAssemblies)' == 'true' "> | ||
<Import Project="Sdk.props" Sdk="Microsoft.NET.Runtime.MonoAOTCompiler.Task" /> | ||
<Import Project="Sdk.props" Sdk="Microsoft.NETCore.App.Runtime.AOT.Cross.android-x86" /> | ||
<Import Project="Sdk.props" Sdk="Microsoft.NETCore.App.Runtime.AOT.Cross.android-x64" /> | ||
<Import Project="Sdk.props" Sdk="Microsoft.NETCore.App.Runtime.AOT.Cross.android-arm" /> | ||
<Import Project="Sdk.props" Sdk="Microsoft.NETCore.App.Runtime.AOT.Cross.android-arm64" /> | ||
</ImportGroup> | ||
|
||
<UsingTask TaskName="Xamarin.Android.Tasks.GetAotArguments" AssemblyFile="$(_XamarinAndroidBuildTasksAssembly)" /> | ||
|
||
<Target Name="_AndroidAotInputs"> | ||
<ItemGroup> | ||
<_AndroidAotInputs Include="@(ResolvedFileToPublish)" Condition=" '%(Extension)' == '.dll' " /> | ||
</ItemGroup> | ||
</Target> | ||
|
||
<Target Name="_AndroidAot" | ||
Condition=" '$(AotAssemblies)' == 'true' and '$(RuntimeIdentifier)' != '' " | ||
DependsOnTargets="_AndroidAotInputs" | ||
Inputs="@(_AndroidAotInputs)" | ||
Outputs="$(_AndroidStampDirectory)_AndroidAot.stamp"> | ||
<GetAotArguments | ||
AndroidAotMode="$(AndroidAotMode)" | ||
AndroidNdkDirectory="$(_AndroidNdkDirectory)" | ||
AndroidBinUtilsDirectory="$(AndroidBinUtilsDirectory)" | ||
AndroidApiLevel="$(_AndroidApiLevel)" | ||
MinimumSupportedApiLevel="$(AndroidMinimumSupportedApiLevel)" | ||
AndroidSequencePointsMode="$(_SequencePointsMode)" | ||
AotAdditionalArguments="$(AndroidAotAdditionalArguments)" | ||
AotOutputDirectory="$(_AndroidAotBinDirectory)" | ||
RuntimeIdentifier="$(RuntimeIdentifier)" | ||
EnableLLVM="$(EnableLLVM)" | ||
Profiles="@(_AotProfiles)"> | ||
<Output PropertyName="_AotArguments" TaskParameter="Arguments" /> | ||
<Output PropertyName="_LLVMPath" TaskParameter="LLVMPath" /> | ||
</GetAotArguments> | ||
<ItemGroup> | ||
<_MonoAOTAssemblies Include="@(_AndroidAotInputs->'%(FullPath)')" AotArguments="$(_AotArguments)" /> | ||
</ItemGroup> | ||
<MakeDir Directories="$(IntermediateOutputPath)aot\" /> | ||
<MonoAOTCompiler | ||
Assemblies="@(_MonoAOTAssemblies)" | ||
CompilerBinaryPath="@(MonoAotCrossCompiler->WithMetadataValue('RuntimeIdentifier', '$(RuntimeIdentifier)'))" | ||
DisableParallelAot="$(_DisableParallelAot)" | ||
LibraryFormat="So" | ||
Mode="$(AndroidAotMode)" | ||
OutputDir="$(IntermediateOutputPath)aot\" | ||
OutputType="Library" | ||
UseAotDataFile="false" | ||
UseLLVM="$(EnableLLVM)" | ||
LLVMPath="$(_LLVMPath)"> | ||
<Output TaskParameter="CompiledAssemblies" ItemName="_AotCompiledAssemblies" /> | ||
<Output TaskParameter="FileWrites" ItemName="FileWrites" /> | ||
</MonoAOTCompiler> | ||
<Touch Files="$(_AndroidStampDirectory)_AndroidAot.stamp" AlwaysCreate="true" /> | ||
<ItemGroup> | ||
<ResolvedFileToPublish | ||
Include="@(_AotCompiledAssemblies->'%(LibraryFile)')" | ||
ArchiveFileName="libaot-$([System.IO.Path]::GetFileNameWithoutExtension('%(_AotCompiledAssemblies.LibraryFile)')).so" | ||
/> | ||
</ItemGroup> | ||
</Target> | ||
</Project> |
This file contains 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 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
Oops, something went wrong.