Skip to content
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

[Xamarin.Android.Build.Tasks] introduce $(_AndroidRuntime) property #9686

Merged
merged 3 commits into from
Jan 21, 2025

Conversation

jonathanpeppers
Copy link
Member

Context: #9572 (comment)
Context: https://github.com/xamarin/xamarin-macios/blob/2009c571aa8a975ab0e0b1785e5484dbd64d6f9b/dotnet/targets/Xamarin.Shared.Sdk.targets#L1004-L1006

To align with xamarin/xamarin-macios, the following public MSBuild properties can be used to select a runtime for iOS, macOS, etc.:

  • $(UseMonoRuntime)=true: MonoVM
  • $(UseMonoRuntime)=false: CoreCLR
  • $(PublishAot)=true: NativeAOT
  • Defaults if blank, select MonoVM

Introduce a private $(_AndroidRuntime) property we can use throughout our build to know which runtime is being targetted.

This way, if a new property is designed in the future, we can keep using $(_AndroidRuntime) and simply update the defaults.

Context: #9572 (comment)
Context: https://github.com/xamarin/xamarin-macios/blob/2009c571aa8a975ab0e0b1785e5484dbd64d6f9b/dotnet/targets/Xamarin.Shared.Sdk.targets#L1004-L1006

To align with xamarin/xamarin-macios, the following public MSBuild
properties can be used to select a runtime for iOS, macOS, etc.:

* `$(UseMonoRuntime)=true`: MonoVM
* `$(UseMonoRuntime)=false`: CoreCLR
* `$(PublishAot)=true`: NativeAOT
* Defaults if blank, select MonoVM

Introduce a private `$(_AndroidRuntime)` property we can use
throughout our build to know which runtime is being targetted.

This way, if a new property is designed in the future, we can keep
using `$(_AndroidRuntime)` and simply update the defaults.
@jonathanpeppers jonathanpeppers marked this pull request as ready for review January 15, 2025 19:36
grendello added a commit that referenced this pull request Jan 16, 2025
@grendello
Copy link
Contributor

It seems that, at least right now, we cannot use UseMonoRuntime because it causes build problems because of this code.

Setting UseMonoRuntime=true when building an Android app results in:

XAPerfTest.csproj : error NU1101: Unable to find package Microsoft.NETCore.App.Runtime.linux-bionic-x86. No packages exist with this id in source(s): darc-pub-dotnet-emsdk-91b783e, darc-pub-dotnet-runtime-ef07c4f, dotnet-eng, dotnet-public, dotnet-tools, dotnet10, dotnet10-transport, dotnet9, dotnet9-transport, xamarin.android util
XAPerfTest.csproj : error NU1101: Unable to find package Microsoft.NETCore.App.Runtime.linux-bionic-arm. No packages exist with this id in source(s): darc-pub-dotnet-emsdk-91b783e, darc-pub-dotnet-runtime-ef07c4f, dotnet-eng, dotnet-public, dotnet-tools, dotnet10, dotnet10-transport, dotnet9, dotnet9-transport, xamarin.android util

@jonathanpeppers
Copy link
Member Author

It seems that, at least right now, we cannot use UseMonoRuntime because it causes build problems because of this code.

Setting UseMonoRuntime=true when building an Android app results in:

XAPerfTest.csproj : error NU1101: Unable to find package Microsoft.NETCore.App.Runtime.linux-bionic-x86. No packages exist with this id in source(s): darc-pub-dotnet-emsdk-91b783e, darc-pub-dotnet-runtime-ef07c4f, dotnet-eng, dotnet-public, dotnet-tools, dotnet10, dotnet10-transport, dotnet9, dotnet9-transport, xamarin.android util
XAPerfTest.csproj : error NU1101: Unable to find package Microsoft.NETCore.App.Runtime.linux-bionic-arm. No packages exist with this id in source(s): darc-pub-dotnet-emsdk-91b783e, darc-pub-dotnet-runtime-ef07c4f, dotnet-eng, dotnet-public, dotnet-tools, dotnet10, dotnet10-transport, dotnet9, dotnet9-transport, xamarin.android util

UseMonoRuntime=true is the default for all Android projects today, and nothing will work without it. I suspect the failure above is related to something else.

@@ -1947,7 +1947,7 @@ because xbuild doesn't support framework reference assemblies.

<!-- Shrink Mono.Android.dll by removing attribute only needed for GenerateJavaStubs -->
<RemoveRegisterAttribute
Condition="'$(AndroidLinkMode)' != 'None' and '$(AndroidIncludeDebugSymbols)' != 'true' and '$(AndroidStripILAfterAOT)' != 'true' and '$(_AndroidNativeAot)' != 'true' "
Condition="'$(AndroidLinkMode)' != 'None' and '$(AndroidIncludeDebugSymbols)' != 'true' and '$(AndroidStripILAfterAOT)' != 'true' and '$(_AndroidRuntime)' != 'NativeAOT' "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why wouldn't we run <RemoveRegisterAttribute/> on NativeAOT?

Copy link
Member Author

@jonathanpeppers jonathanpeppers Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, it runs after the trimmer.

Under NativeAOT, after the trimmer, it's down to a single .so file, so nothing to do?

We will revisit this, but I was hoping to just move <RemoveRegisterAttribute/> inside a trimmer step.

Comment on lines +27 to +31
<UseMonoRuntime Condition=" '$(PublishAot)' == 'true' and '$(UseMonoRuntime)' == '' ">false</UseMonoRuntime>
<UseMonoRuntime Condition=" '$(UseMonoRuntime)' == '' ">true</UseMonoRuntime>
<_AndroidRuntime Condition=" '$(PublishAot)' == 'true' and '$(UseMonoRuntime)' != 'true' ">NativeAOT</_AndroidRuntime>
<_AndroidRuntime Condition=" '$(PublishAot)' != 'true' and '$(UseMonoRuntime)' != 'true' ">CoreCLR</_AndroidRuntime>
<_AndroidRuntime Condition=" '$(_AndroidRuntime)' == '' ">MonoVM</_AndroidRuntime>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite understand the desired semantics; when would $(UseMonoRuntime) be set to false? When would CoreCLR be used? Or is it that CoreCLR support is still in-progress via #9572, and thus it currently isn't possible for $(_AndroidRuntime) to be CoreCLR, and #9572 will change that? Or is the expectation that in the future, to use CoreCLR then devs must explicitly set $(UseMonoRuntime)=false in their .csproj?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now, the best option we have to align with xamarin/xamarin-macios is that you would set UseMonoRuntime=false in your .csproj file.

@jonpryor jonpryor merged commit 8aca6e6 into main Jan 21, 2025
58 of 60 checks passed
@jonpryor jonpryor deleted the dev/peppers/runtime/msbuild/property branch January 21, 2025 17:18
grendello added a commit that referenced this pull request Jan 21, 2025
* main:
  [Xamarin.Android.Build.Tasks] introduce `$(_AndroidRuntime)` property (#9686)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants