-
Notifications
You must be signed in to change notification settings - Fork 537
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
[One .NET] AOT support #5539
[One .NET] AOT support #5539
Conversation
Should we be repacking the content of the Here's a rough example/outline: WorkloadManifest.json "packs": {
...
"Microsoft.NET.Runtime.MonoAOTCompiler.Task": {
"kind": "sdk",
"version": "$(MonoAOTCompilerVersion)"
},
"Microsoft.NetCore.App.Runtime.AOT.arm": {
"kind": "sdk",
"version": "$(MonoAOTCompilerVersion)",
"alias-to": {
"osx-x64": "Microsoft.NetCore.App.Runtime.AOT.osx-x64.Cross.android-arm",
"win-x64": "Microsoft.NetCore.App.Runtime.AOT.win-x64.Cross.android-arm"
}
},
"Microsoft.NetCore.App.Runtime.AOT.arm64": {
"kind": "sdk",
"version": "$(MonoAOTCompilerVersion)",
"alias-to": {
"osx-x64": "Microsoft.NetCore.App.Runtime.AOT.osx-x64.Cross.android-arm64",
"win-x64": "Microsoft.NetCore.App.Runtime.AOT.win-x64.Cross.android-arm64"
}
},
...
} WorkloadManifest.targets ...
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Runtime.MonoAOTCompiler.Task"
Condition=" '$(AotAssemblies)' == 'true' " />
<Import Project="Sdk.targets" Sdk="Microsoft.NetCore.App.Runtime.AOT.arm"
Condition=" '$(AotAssemblies)' == 'true' and '$(RuntimeIdentifier)' == 'android.21-arm' " />
... However maybe this won't work with the current version of these packages? I think for this to work these packs would need to include that In the case of <PropertyGroup>
<AotCompilerBinaryPath>$(MSBuildThisFileDirectory)..\tools\mono-aot-cross</AotCompilerBinaryPath>
</PropertyGroup> In the case of <PropertyGroup>
<MonoAOTCompilerTaskAssemblyPath>$(MSBuildThisFileDirectory)..\tools\net5.0\MonoAOTCompiler.dll</MonoAOTCompilerTaskAssemblyPath>
</PropertyGroup> However this file may not be in the right location that would allow us to import it via our The @akoeplinger what are your thoughts on this? Should we be able to consume these .nupkgs as workload packs? It looks like the |
Yes, I think we could easily make It would be helpful if the
Each pack would have a different value for |
TBH I don't have a lot of context around what the best approach is, so if you or @jonathanpeppers think we should do something differently then sure :) |
0da130a
to
e07c9b0
Compare
I reworked this to use all of the MonoAOTCompiler packages as SDK workload packs. Building app fails as before, but here is an updated log: msbuild.binlog.zip 👀
|
@jonathanpeppers it looks like that binlog is corrupt, I can't open it. Would you mind creating a new one? |
@akoeplinger did you try the latest one: #5539 (comment) I can open it with the Windows viewer at least. I think the first one was partial because the process was killed. |
@jonathanpeppers weird, for some reason downloading the .zip on macOS makes it corrupt. I can open when I download it on Windows, taking a look now :) |
e07c9b0
to
a263143
Compare
src/Xamarin.Android.Build.Tasks/Microsoft.NET.Workload.Android/WorkloadManifest.in.json
Outdated
Show resolved
Hide resolved
src/Xamarin.Android.Build.Tasks/Microsoft.NET.Workload.Android/WorkloadManifest.in.json
Outdated
Show resolved
Hide resolved
src/Xamarin.Android.Build.Tasks/Microsoft.NET.Workload.Android/WorkloadManifest.in.json
Outdated
Show resolved
Hide resolved
src/Xamarin.Android.Build.Tasks/Microsoft.NET.Workload.Android/WorkloadManifest.targets
Outdated
Show resolved
Hide resolved
AotAdditionalArguments="$(AndroidAotAdditionalArguments)" | ||
AotOutputDirectory="$(_AndroidAotBinDirectory)" | ||
RuntimeIdentifier="$(RuntimeIdentifier)" | ||
EnableLLVM="$(EnableLLVM)" |
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.
IIRC we ship LLVM only mode
/cc @akoeplinger
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.
Turning on $(EnableLLVM)
does not appear to work quite yet: dotnet/runtime#56386
We could make it the default value when it's working, if it makes sense to do so.
src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.Aot.targets
Outdated
Show resolved
Hide resolved
src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.Aot.targets
Show resolved
Hide resolved
src/Xamarin.Android.Build.Tasks/Microsoft.NET.Workload.Android/WorkloadManifest.in.json
Outdated
Show resolved
Hide resolved
01d2840
to
8be8739
Compare
8be8739
to
482210f
Compare
2c08af1
to
064301b
Compare
To test this currently, you would need: MonoAOTCompiler.zip Copy |
Some of the tests are failing, e.g. BuildBasicApplicationAndAotProfileIt, because they're invoking
|
9b0c324
to
8124229
Compare
After adding some new categories, I realized this breaks legacy due to:
Looking into it... |
a9275ad
to
0fccb69
Compare
Fixes: #6052 |
57e9c12
to
252e3b9
Compare
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 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: https://devblogs.microsoft.com/aspnet/asp-net-core-updates-in-net-6-preview-4/#blazor-webassembly-ahead-of-time-aot-compilation 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> Since, the default Mono workload does not support `$(AotAssemblies)`: https://github.com/dotnet/runtime/blob/69711860262e44458bbe276393ea3eb9f7a2192a/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.Manifest/WorkloadManifest.targets.in#L20-L25 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 were running on a Pixel 5. Using the HelloAndroid app: https://github.com/dotnet/maui-samples/tree/main/HelloAndroid Defaults to two architectures: arm64 and x86 Average of 10 runs with `-c Release` and no AOT: Activity: Displayed 00:00:00.308 Apk size: 8367969 Average of 10 runs with `-c Release -p:RunAOTCompilation=true`: Activity: Displayed 00:00:00.209 Apk size: 12082123 Using the HelloMaui app: https://github.com/dotnet/maui-samples/tree/main/HelloMaui Defaults to two architectures: arm64 and x86 Average of 10 runs with `-c Release` and no AOT: Activity: Displayed 00:00:01.117 Apk size: 16272964 Average of 10 runs with `-c Release -p:RunAOTCompilation=true`: Activity: Displayed 00:00:00.568 Apk size: 42869016
252e3b9
to
94d073a
Compare
This only has a couple runtime test failures:
Then:
https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=5024995&view=results I have a mistake where the test results file is wrong, looking into that:
|
@@ -418,17 +425,20 @@ public void HybridAOT ([Values ("armeabi-v7a;arm64-v8a", "armeabi-v7a", "arm64-v | |||
} | |||
|
|||
[Test] | |||
public void NoSymbolsArgShouldReduceAppSize ([Values (true, false)] bool enableHybridAot) | |||
[Category ("LLVM")] | |||
public void NoSymbolsArgShouldReduceAppSize ([Values ("", "Hybrid")] string androidAotMode) |
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.
Should it be "Normal"
instead of ""
?
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.
I think the test was previously leaving it blank, so I kept the behavior the same:
-- if (enableHybridAot)
-- proj.SetProperty ("AndroidAotMode", "Hybrid");
++ if (!string.IsNullOrEmpty (androidAotMode))
++ proj.SetProperty ("AndroidAotMode", androidAotMode);
* had the wrong file path for `TestResults-*.xml` * `$(ExcludeCategories)` should include `DotNetIgnore` and `InetAccess`
1a450f1
to
04bacb8
Compare
For review: Fixes: https://github.com/xamarin/xamarin-android/issues/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:
* https://github.com/xamarin/xamarin-android/issues/6053
`$(EnableLLVM)` fails when locating `opt`:
* https://github.com/dotnet/runtime/issues/56386
`$(AndroidClientHandler)` usage causes runtime crash:
* https://github.com/dotnet/runtime/issues/56315
Use of folder names like `Build AndÜmläüts` fails:
* https://github.com/dotnet/runtime/issues/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 |
Fixes: #6052 Helpful reading:
To make this work, I moved the existing In the .NET 6 targets, there is a different Native libraries are added to the To follow convention with Blazor WASM, the To help with backwards compatibility with "legacy" Xamarin.Android, I Unfortunately, we have to manually import things to support
as the default Mono workload does not support ~~ Limitations ~~ Profiled AOT is not implemented yet:
Use of folder names like ~~ Results ~~ All tests:
|
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
Fixes: #6052
Helpful reading:
To make this work, I moved the existing
<Aot/>
MSBuild task calls toa new
_AndroidAot
MSBuild target inXamarin.Android.Legacy.targets
.In the .NET 6 targets, there is a different
_AndroidAot
MSBuildtarget that runs the new
<MonoAOTCompiler/>
MSBuild task. The_AndroidAot
target runs per$(RuntimeIdentifier)
after the linkercompletes. Native libraries are added to the
@(ResolvedFileToPublish)
item group to be included in the final.apk
.To follow convention with Blazor WASM:
https://devblogs.microsoft.com/aspnet/asp-net-core-updates-in-net-6-preview-4/#blazor-webassembly-ahead-of-time-aot-compilation
The
$(RunAOTCompilation)
MSBuild property enables AOT. To help withbackwards compatibility with "legacy" Xamarin.Android, I kept the
$(AotAssemblies)
MSBuild property intact.Unfortunately, we have to manually import things to support
$(AotAssemblies)
:Since, the default Mono workload does not support
$(AotAssemblies)
:https://github.com/dotnet/runtime/blob/69711860262e44458bbe276393ea3eb9f7a2192a/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.Manifest/WorkloadManifest.targets.in#L20-L25
I think this is reasonable for now.
Limitations
#6053
$(EnableLLVM)
fails when locatingopt
:dotnet/runtime#56386
AndroidClientHandler
usage causes runtime crash:dotnet/runtime#56315
Build AndÜmläüts
fails:dotnet/runtime#56163
Results
All tests were running on a Pixel 5.
Using the HelloAndroid app:
https://github.com/dotnet/maui-samples/tree/main/HelloAndroid
Defaults to two architectures: arm64 and x86
Average of 10 runs with
-c Release
and no AOT:Apk size: 8367969
Average of 10 runs with
-c Release -p:RunAOTCompilation=true
:Apk size: 12082123
Using the HelloMaui app:
https://github.com/dotnet/maui-samples/tree/main/HelloMaui
Defaults to two architectures: arm64 and x86
Average of 10 runs with
-c Release
and no AOT:Apk size: 16272964
Average of 10 runs with
-c Release -p:RunAOTCompilation=true
:Apk size: 42869016