From cc08b0776dbf52c174be6acb6fbe2e6a3f6471f5 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Tue, 19 Sep 2023 12:31:27 +0200 Subject: [PATCH] [dotnet] Work around an expectation mismatch between ILLink and library projects. Fixes #19037. ILLink doesn't handle library projects the way we need: the library is automatically treated as a root assembly, with the entry point as the root. This doesn't work, because library projects don't have an entry point. In earlier versions of .NET (and Xamarin), we'd solved this by a custom linker step that would manually root everything that needed to be rooted, but that doesn't work anymore because we hit this sanity check in ILLink: > ILLink : error IL1034: Root assembly 'MyExtension, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have entry point. Technically this happens because the library project is configured as a root assembly, where the entry point is the root point (and in that regards the sanity check is rather sane). The best solution would be if we could just treat the library assembly as any other assembly, and manually root it in our custom linker steps - but the custom linker step we have for this kind of rooting will only iterate over types in assemblies that are already marked somehow, and that's not necessarily the case for app extension projects - the end result is that the entire app extension assembly is linked away. A close runner-up as the second best solution is to provide the API that needs to be rooted as an xml file to the linker. This works, but we currently don't have the infrastructure in the code to generate this xml file before running the linker (it would be a rather major undertaking). This work is tentatively scheduled for .NET 9 (https://github.com/xamarin/xamarin-macios/issues/17693). So I went for the third option: set RootMode="Library" for the library assembly. I'm not sure exactly what that means ILLink will mark, but as long as _anything_ is marked, our custom linker step will run. This seems like an acceptable workaround until we can implement the previous solution. Fixes https://github.com/xamarin/xamarin-macios/issues/19037. --- dotnet/targets/Xamarin.Shared.Sdk.targets | 9 +++++++++ tests/dotnet/UnitTests/ProjectTest.cs | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/dotnet/targets/Xamarin.Shared.Sdk.targets b/dotnet/targets/Xamarin.Shared.Sdk.targets index 2fbe4850aabe..4e8cf77cc143 100644 --- a/dotnet/targets/Xamarin.Shared.Sdk.targets +++ b/dotnet/targets/Xamarin.Shared.Sdk.targets @@ -1164,6 +1164,15 @@ + + + + + + + +