-
Notifications
You must be signed in to change notification settings - Fork 533
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
[NativeAOT] MSBuild-related logic to get projects to build #9583
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
...in.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.NativeAOT.targets
Outdated
Show resolved
Hide resolved
This comment was marked as outdated.
This comment was marked as outdated.
Context: #9538 Context: #9583 Expanding upon #9538, there are more changes required to support multiple runtime flavors in our build. * Remove `$(MicrosoftAndroidArmPackDir)` and related properties, to rely on a new `@(AndroidAbiAndRuntimeFlavor)` item group instead. * Exclude our Mono-related native libraries from NativeAOT runtime packs. * Ensure that our runtime packs copy assemblies (`Mono.Android.dll`, etc.) to the appropriate NativeAOT-related directories. * List our `Microsoft.Android.Runtime.NativeAOT.*` packs in the `WorkloadManifest.json`, so that `**FromWorkload**` can resolve the version number for them. They can still restore via NuGet.
Context: #9538 Context: #9583 Expanding upon #9538, there are more changes required to support multiple runtime flavors in our build. * Remove `$(MicrosoftAndroidArmPackDir)` and related properties, to rely on a new `@(AndroidAbiAndRuntimeFlavor)` item group instead. * Exclude our Mono-related native libraries from NativeAOT runtime packs. * Ensure that our runtime packs copy assemblies (`Mono.Android.dll`, etc.) to the appropriate NativeAOT-related directories. * List our `Microsoft.Android.Runtime.NativeAOT.*` packs in the `WorkloadManifest.json`, so that `**FromWorkload**` can resolve the version number for them. They can still restore via NuGet.
Context: #9538 Context: #9583 Expanding upon #9538, there are more changes required to support multiple runtime flavors in our build. * Remove `$(MicrosoftAndroidArmPackDir)` and related properties, to rely on a new `@(AndroidAbiAndRuntimeFlavor)` item group instead. * Exclude our Mono-related native libraries from NativeAOT runtime packs. * Ensure that our runtime packs copy assemblies (`Mono.Android.dll`, etc.) to the appropriate NativeAOT-related directories. * List our `Microsoft.Android.Runtime.NativeAOT.*` packs in the `WorkloadManifest.json`, so that `**FromWorkload**` can resolve the version number for them. They can still restore via NuGet.
Context: #9538 Context: #9583 Expanding upon #9538, there are more changes required to support multiple runtime flavors in our build. * Remove `$(MicrosoftAndroidArmPackDir)` and related properties, to rely on a new `@(AndroidAbiAndRuntimeFlavor)` item group instead. * Exclude our Mono-related native libraries from NativeAOT runtime packs. * Ensure that our runtime packs copy assemblies (`Mono.Android.dll`, etc.) to the appropriate NativeAOT-related directories. * List our `Microsoft.Android.Runtime.NativeAOT.*` packs in the `WorkloadManifest.json`, so that `**FromWorkload**` can resolve the version number for them. They can still restore via NuGet.
508ba8e
to
546c241
Compare
This is an initial step to get the NativeAOT build working the same as iOS does. At a high level, the changes are: * Run `ILLink` with our existing trimmer/linker pipeline. * Temporarily change our RID to `linux-bionic-arm64`. * Pass the output to `ILC`, the NativeAOT compiler. * Turn the RID back to `android-arm64`. A list of MSBuild/workload changes required so far: * `$(UseMonoRuntime)` is false when `$(PublishAot)` is true * Set `$(_IsPublishing)` as NativeAOT expects `dotnet publish` to be the only way NativeAOT is used. Setting this in our targets allows the proper `*.NativeAOT.*` packs to restore inside of a `dotnet build`. * `$(SelfContained)=true`, seems to be required for the `linux-bionic-arm64` runtime packs to restore. All Android apps are self-contained, so this might be fine. * Create a new `Microsoft.Android.Sdk.NativeAOT.targets` file that uses `$(_AndroidNdkDirectory)` to set various properties for NativeAOT's build (ILC). * `HACK:` set `$(_targetOS)` to `linux` to make the NativeAOT build attempt to run. `--targetos:android` results in a build error that says Android is not supported. * Disable `$(RunAOTCompilation)`, Mono's AOT compiler and the `<RemoveRegisterAttribute/>` MSBuild task. * Disable `$(AndroidEnableMarshalMethods)` to be re-enabled in a future PR. A list of blockers or things that don't work yet: * NativeAOT apps won't launch yet (future changes for that) * The NativeAOT cross compiler doesn't run on Windows: Microsoft.NETCore.Native.Publish.targets(61,5): Cross-OS native compilation is not supported. Microsoft.NETCore.Native.Unix.targets(296,5): error : Platform linker ('C:\Android\android-sdk\ndk\26.3.11579264\toolchains/llvm/prebuilt/windows-x86_64/bin/aarch64-linux-android21-clang++' or 'gcc') not found in PATH. Ensure you have all the required prerequisites documented at https://aka.ms/nativeaot-prerequisites. * You can only target `-r android-arm64` as there are no other `linux-bionic-*` runtime packs yet. * `-p:PublishAotUsingRuntimePack=true` is currently required, but I will investigate if we should just set this by default.
546c241
to
a35f711
Compare
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.
Copilot reviewed 1 out of 6 changed files in this pull request and generated no suggestions.
Files not reviewed (5)
- src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.AssemblyResolution.targets: Language not supported
- src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets: Language not supported
- src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.NativeAOT.targets: Language not supported
- src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.targets: Language not supported
- src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets: Language not supported
Comments skipped due to low confidence (2)
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest2.cs:109
- [nitpick] The method name 'NativeAOT' is not descriptive. Consider renaming it to 'BuildNativeAOTApplication' or something similar to better reflect its purpose.
public void NativeAOT ()
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest2.cs:113
- [nitpick] The comment could be clearer. Consider rephrasing to: 'Ensure all required prerequisites are documented at https://aka.ms/nativeaot-prerequisites.'
// Ensure you have all the required prerequisites documented at https://aka.ms/nativeaot-prerequisites.
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.
looks reasonable
This is an initial step to get the NativeAOT build working the same as
iOS does. At a high level, the changes are:
Run
ILLink
with our existing trimmer/linker pipeline.Temporarily change our RID to
linux-bionic-arm64
.Pass the output to
ILC
, the NativeAOT compiler.Turn the RID back to
android-arm64
.A list of MSBuild/workload changes required so far:
$(UseMonoRuntime)
is false when$(PublishAot)
is trueSet
$(_IsPublishing)
as NativeAOT expectsdotnet publish
to bethe only way NativeAOT is used. Setting this in our targets allows
the proper
*.NativeAOT.*
packs to restore inside of adotnet build
.$(SelfContained)=true
, seems to be required for thelinux-bionic-arm64
runtime packs to restore. All Android apps areself-contained, so this might be fine.
Create a new
Microsoft.Android.Sdk.NativeAOT.targets
file thatuses
$(_AndroidNdkDirectory)
to set various properties forNativeAOT's build (ILC).
HACK:
set$(_targetOS)
tolinux
to make the NativeAOT buildattempt to run.
--targetos:android
results in a build error thatsays Android is not supported.
Disable
$(RunAOTCompilation)
, Mono's AOT compiler and the<RemoveRegisterAttribute/>
MSBuild task.Disable
$(AndroidEnableMarshalMethods)
to be re-enabled in afuture PR.
A list of blockers or things that don't work yet:
NativeAOT apps won't launch yet (future changes for that)
The NativeAOT cross compiler doesn't run on Windows:
You can only target
-r android-arm64
as there are no otherlinux-bionic-*
runtime packs yet.-p:PublishAotUsingRuntimePack=true
is currently required, but Iwill investigate if we should just set this by default.