Skip to content

[One .NET] fix AOT builds with different settings - #6556

Merged
jonpryor merged 1 commit into
dotnet:mainfrom
jonathanpeppers:dotnet-aot-issues
Dec 10, 2021
Merged

jonpryor merged 1 commit into
dotnet:mainfrom
jonathanpeppers:dotnet-aot-issues

Conversation

@jonathanpeppers

Copy link
Copy Markdown
Member

Building a .NET 6 Release app with UseInterpreter=true and
RunAOTCompilation=true would fail with:

Microsoft.Android.Sdk.Aot.targets(71,5): Unknown Mode value: Interpreter. 'Mode' must be one of: Normal,JustInterp,Full,FullInterp,Hybrid,LLVMOnly,LLVMOnlyInterp

Reviewing the code:

https://github.com/dotnet/runtime/blob/60edc0bdafce1849fec19e3ec4f766074de50fc3/src/tasks/AotCompilerTask/MonoAOTCompiler.cs#L1064-L1073

There does not appear to be a mode of Normal + Interp. So let's
just make AOT take precendence over $(UseInterpreter). On Android
$(UseInterpreter) is a Debug-mode setting for Hot Reload.

Building a .NET 6 Debug app RunAOTCompilation=true would fail with:

Microsoft.Android.Sdk.Aot.targets(49,5): error MSB4044: The "GetAotAssemblies" task was not given a value for the required parameter "AndroidApiLevel".

This is because the linker was skipped, particularly this target:

<Target Name="_PrepareLinking"
    Condition=" '$(PublishTrimmed)' == 'true' "
    AfterTargets="ComputeResolvedFilesToPublishList"
    DependsOnTargets="GetReferenceAssemblyPaths;_CreatePropertiesCache">

_CreatePropertiesCache doesn't run, and so we have some empty
properties in this case. We can simply add _CreatePropertiesCache to
the _AndroidAot MSBuild target's DependsOnTargets to solve this
issue.

@jonathanpeppers

Copy link
Copy Markdown
Member Author

I added:

warning XA0119: Using the interpreter and AOT at the same time is not recommended. Use the interpreter for hot reload support in Debug configurations and AOT for Release configurations.

Building a .NET 6 `Release` app with `UseInterpreter=true` and
`RunAOTCompilation=true` would fail with:

    Microsoft.Android.Sdk.Aot.targets(71,5): Unknown Mode value: Interpreter. 'Mode' must be one of: Normal,JustInterp,Full,FullInterp,Hybrid,LLVMOnly,LLVMOnlyInterp

Reviewing the code:

https://github.com/dotnet/runtime/blob/60edc0bdafce1849fec19e3ec4f766074de50fc3/src/tasks/AotCompilerTask/MonoAOTCompiler.cs#L1064-L1073

There does not appear to be a mode of `Normal` + `Interp`. So let's
just make AOT take precendence over `$(UseInterpreter)`. On Android
`$(UseInterpreter)` is a Debug-mode setting for Hot Reload.

Building a .NET 6 `Debug` app `RunAOTCompilation=true` would fail with:

    Microsoft.Android.Sdk.Aot.targets(49,5): error MSB4044: The "GetAotAssemblies" task was not given a value for the required parameter "AndroidApiLevel".

This is because the linker was skipped, particularly this target:

    <Target Name="_PrepareLinking"
        Condition=" '$(PublishTrimmed)' == 'true' "
        AfterTargets="ComputeResolvedFilesToPublishList"
        DependsOnTargets="GetReferenceAssemblyPaths;_CreatePropertiesCache">

`_CreatePropertiesCache` doesn't run, and so we have some empty
properties in this case. We can simply add `_CreatePropertiesCache` to
the `_AndroidAot` MSBuild target's `DependsOnTargets` to solve this
issue.
@jonpryor

jonpryor commented Dec 10, 2021 •

Copy link
Copy Markdown
Contributor
Building a .NET 6 `Release` app with `UseInterpreter=true` and
`RunAOTCompilation=true` would fail with:

	Microsoft.Android.Sdk.Aot.targets(71,5): Unknown Mode value: Interpreter. 'Mode' must be one of: Normal,JustInterp,Full,FullInterp,Hybrid,LLVMOnly,LLVMOnlyInterp

Reviewing [Mono's AOT code][0]:

	public enum MonoAotMode
	{
	    Normal,
	    JustInterp,
	    Full,
	    FullInterp,
	    Hybrid,
	    LLVMOnly,
	    LLVMOnlyInterp
	}

There does not appear to be a mode for `Normal` + `Interp`.  So let's
instead have AOT take precedence over `$(UseInterpreter)`.
On Android, `$(UseInterpreter)` is a Debug-mode setting for
[Hot Reload][1]; the *expectation* is that AOT won't be enabled in
Debug config builds as Debug builds should be "fast" while AOT builds
are *slow*, so if AOT is explicitly enabled, *presumably* the
developer doesn't want the Interpreter.

To inform developers of this change, we now emit an XA0119 warning
when both `$(UseInterpreter)`=true and `$(RunAOTCompilation)`=true:

	dotnet build -p:UseInterpreter=true -p:RunAOTCompilation=true
	…
	warning XA0119: Disabling the interpreter;
	  using the interpreter and AOT at the same time is not supported.
	  Use the interpreter for hot reload support in Debug configurations and
	  AOT for Release configurations.

While testing this new priority order, we found that building a
.NET 6 `Debug` config app with `$(RunAOTCompilation)`=true would
fail with:

	Microsoft.Android.Sdk.Aot.targets(49,5): error MSB4044:
	The "GetAotAssemblies" task was not given a value for the required parameter "AndroidApiLevel".

This is because the linker was skipped, particularly this target:

	<Target Name="_PrepareLinking"
	    Condition=" '$(PublishTrimmed)' == 'true' "
	    AfterTargets="ComputeResolvedFilesToPublishList"
	    DependsOnTargets="GetReferenceAssemblyPaths;_CreatePropertiesCache">

The `_CreatePropertiesCache` target didn't run, and so we have some
empty properties in this case.

We can simply add `_CreatePropertiesCache` to the `_AndroidAot` MSBuild
target's `DependsOnTargets` to solve this issue.

[0]: https://github.com/dotnet/runtime/blob/60edc0bdafce1849fec19e3ec4f766074de50fc3/src/tasks/AotCompilerTask/MonoAOTCompiler.cs#L1064-L1073
[1]: https://docs.microsoft.com/visualstudio/debugger/hot-reload

@jonpryor
jonpryor merged commit 513f613 into dotnet:main Dec 10, 2021
@jonathanpeppers
jonathanpeppers deleted the dotnet-aot-issues branch December 10, 2021 15:31
@github-actions github-actions Bot locked and limited conversation to collaborators Jan 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants