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

Initial NET5/ILLink support #4669

Merged
merged 34 commits into from
Jun 4, 2020
Merged

Initial NET5/ILLink support #4669

merged 34 commits into from
Jun 4, 2020

Conversation

radekdoulik
Copy link
Member

@radekdoulik radekdoulik commented May 11, 2020

Implements #4707

With .NET5 we are switching from XA linker implemented as msbuild task to ILLink tool with custom steps provided in an assembly.

The new assembly with our custom steps is named Microsoft.Android.Sdk.ILLink and the source code is located in src/Microsoft.Android.Sdk.ILLink. It is used during build by ILLink tool.

The initial support is already able to link and run simple XA and XA/XF samples.

Future work

Notes

  • the Profile API is not available in the linker public API. we work around it by adding src/Microsoft.Android.Sdk.ILLink/Profile.cs with missing pieces.
  • TypeDefinition.GetMethods extension method from Mono.Tuner.MethodBodyRocks is not public. It is very simple so we are inlining it.
  • the ILLink is now enabled in Release configuration defaults.
  • tests were updated to reference more packages, to not miss second level dependencies.

Initial results:

apkdiff output summary for HelloAndroid sample, comparing Debug and Release apk's

  -       7,300 Davik executables -2.34% (of 311,436)
  -  14,733,944 Assemblies -31.85% (of 46,265,064)
  -   2,492,452 Shared libraries -11.43% (of 21,803,164)
  -  15,528,456 Package size difference -28.70% (of 54,114,462)

Context:

Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

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

It looks like some of the tests on CI are hitting:

Unrecognized command-line option: '--custom-data' 

Do you know what .NET 5 version we need for this to work?

We can bump this number: https://github.com/xamarin/xamarin-android/blob/3f438e46d7b166a3a3ef54c9ffafb5f426760468/build-tools/automation/azure-pipelines.yaml#L53

We could maybe try 5.0.100-preview.5.20264.3, which is latest master here: https://github.com/dotnet/installer#build-status

@radekdoulik
Copy link
Member Author

Do you know what .NET 5 version we need for this to work?

Locally I am using 5.0.100-preview.5.20229.12. I will try to bump it to lastest.

Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

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

We might have to wait until this lands: #4692

This fixes the change from netcoreapp5.0 -> net5.0.

@radekdoulik
Copy link
Member Author

Indeed. dotnet tests are now failing with related error:

error XARSD7004: System.ArgumentException: `C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\5.0.0-preview.6.20264.1\ref\netcoreapp5.0` must be a directory! (Parameter 'frameworkDirectories')

@jonathanpeppers
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jonpryor
Copy link
Member

DotNetBuild("android.21-arm",True) on Windows fails:

The assembly 'C:\A\vs2019xam00000L-1\_work\2\s\packages\microsoft.android.sdk\10.0.100-ci.pr.gh4669.53\targets\..\tools\Xamarin.Android.Linker.dll' specified for '--custom-step' option could not be found (TaskId:185)
18:23:35.119   1:7>C:\Program Files\dotnet\sdk\5.0.100-preview.6.20265.2\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(83,5): error MSB6006: "dotnet.exe" exited with code 1. [C:\A\vs2019xam00000L-1\_work\2\s\bin\TestRelease\temp\DotNetBuildandroid.21-armTrue\UnnamedProject.csproj]
                   Done executing task "ILLink" -- FAILED. (TaskId:185)

jonathanpeppers and others added 17 commits May 20, 2020 13:23
Based on the new `Microsoft.NET.ILLink` NuGet package, this is a start
to what it would look like to use it for Xamarin.Android.
And use it in place of Mono.Tuner one, where needed for net5
Do not run `LinkAssemblies` task on NET5

Temporarily disable `_RemoveRegisterAttribute` target. It is crashing,
presumably because the assemblies are in different location.
The step so far only installs `FixAbstractMethodsStep`.

Parts of the code come from xamarin-macios repo. We might share these
and move them to linker. Or enable more linker API to avoid getting
the pipeline steps with reflection.
And re-enable `_RemoveRegisterAttribute` target, as the assemblies now
end up in the right place
To avoid few #if's and make the code better readable
To avoid using Xamarin.Android.Linker namespace and introducing another
`#if`'s
We don't need them anymore as we have the new extension method in that
namespace
We still need `using Mono.Tuner;` for non NET5 version.
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.ILLink" Version="5.0.0-preview.3.20227.3" />
<ProjectReference Include="..\..\external\Java.Interop\src\Java.Interop.Export\Java.Interop.Export.csproj" />
Copy link
Member

Choose a reason for hiding this comment

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

I do not understand why we would have a @(ProjectReference) to Java.Interop.Export.dll. I don't see any mentions of types located within that assembly within this PR, e.g. neither JniSignature nor MarshalMemberBuilder make an appearance.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is to have MarshalMemberBuilder.GetMarshalMethodName for TryGetMarshalMethod method.

Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xamarin.Android.Tools.AndroidSdk", "external\xamarin-android-tools\src\Xamarin.Android.Tools.AndroidSdk\Xamarin.Android.Tools.AndroidSdk.csproj", "{E34BCFA0-CAA4-412C-AA1C-75DB8D67D157}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xamarin.Android.Tools.AndroidSdk", "external\xamarin-android-tools\src\Xamarin.Android.Tools.AndroidSdk\Xamarin.Android.Tools.AndroidSdk.csproj", "{E34BCFA0-CAA4-412C-AA1C-75DB8D67D157}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xamarin.Android.Linker", "src\Xamarin.Android.Linker\Xamarin.Android.Linker.csproj", "{2A237E71-1FA3-409B-B13E-F6294932A5A9}"
Copy link
Member

Choose a reason for hiding this comment

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

I half wonder if this should be Microsoft.Android.Linker. :-/

Copy link
Contributor

Choose a reason for hiding this comment

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

Or even better Microsoft.Android.Sdk.ILLink ;-)

Copy link
Member

Choose a reason for hiding this comment

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

How many assemblies do we want running around? That's a rather fine-grained name…

@@ -165,7 +166,7 @@ bool CheckInvokerType (TypeDefinition type, string name)

void PreserveInterfaceMethods (TypeDefinition type, TypeDefinition invoker)
{
foreach (var m in type.GetMethods ()) {
foreach (var m in type.Methods.Where (m => !m.IsConstructor)) {
Copy link
Member

Choose a reason for hiding this comment

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

Any specific reason for this change? The PR description is anemic.

Copy link
Member Author

Choose a reason for hiding this comment

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

This one comes from Mono.Tuner.MethodBodyRocks class, which is not part of illink public API and was simple enough to inline.

@radekdoulik radekdoulik merged commit f68f32a into master Jun 4, 2020
@radekdoulik radekdoulik deleted the net5-linker branch June 4, 2020 12:03
@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.

6 participants