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

net8 regression: cannot build appextensions on iOS without workaround #19037

Closed
enclave-alistair opened this issue Sep 18, 2023 · 1 comment
Closed
Labels
bug If an issue is a bug or a pull request a bug fix regression The issue or pull request is a regression
Milestone

Comments

@enclave-alistair
Copy link

Steps to Reproduce

  1. Create an iOS app extension (set <IsAppExtension>true</IsAppExtension>).
  2. Add an owning app that loads the app extension.
  3. Build.

Expected Behavior

Build completes ok.

Actual Behavior

Receive a linker error:

ILLink : error IL1034: Root assembly 'Dotnet.Test.NetExtension, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have entry point. [/Volumes/External/git/fabric-test/src/Dotnet.Test.NetExtension/Dotnet.Test.NetExtension.csproj::TargetFramework=net8.0-ios]
/Users/alistairevans/.nuget/packages/microsoft.net.illink.tasks/8.0.0-rc.1.23419.4/build/Microsoft.NET.ILLink.targets(87,5): error NETSDK1144: Optimizing assemblies for size failed. Optimization can be disabled by setting the PublishTrimmed property to false. [/Volumes/External/git/fabric-test/src/Dotnet.Test.NetExtension/Dotnet.Test.NetExtension.csproj::TargetFramework=net8.0-ios]

I have to add the following Target to the extension project file to make it work:

<Target Name="_FixRootAssembly" AfterTargets="PrepareForILLink">
    <ItemGroup>
        <TrimmerRootAssembly Update="@(TrimmerRootAssembly)" Condition=" '%(TrimmerRootAssembly.RootMode)' == 'EntryPoint' " RootMode="Library" />
    </ItemGroup>
</Target>

This was inspired by what I think is a related issue: dotnet/linker#3165

Environment

Only building from the command-line right now (no VS on this Mac); as much version information as possible attached.

Version information
dotnet version
8.0.100-rc.1.23463.5

dotnet workload list
Installed Workload Id      Manifest Version                  Installation Source
--------------------------------------------------------------------------------
maui-maccatalyst           8.0.0-rc.1.9171/8.0.100-rc.1      SDK 8.0.100-rc.1   
maui-ios                   8.0.0-rc.1.9171/8.0.100-rc.1      SDK 8.0.100-rc.1

installed packages:

<PackageVersion Include="Microsoft.Maui.Core" Version="8.0.0-rc.1.9171" />
<PackageVersion Include="Microsoft.Maui.Controls" Version="8.0.0-rc.1.9171" />
<PackageVersion Include="Microsoft.Maui.Controls.Core" Version="8.0.0-rc.1.9171" />
<PackageVersion Include="Microsoft.Maui.Controls.Build.Tasks" Version="8.0.0-rc.1.9171" />

<PackageVersion Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.0-rc.1.9171" />
<PackageVersion Include="Microsoft.Maui.Controls.Xaml" Version="8.0.0-rc.1.9171" />
<PackageVersion Include="Microsoft.Maui.Essentials" Version="8.0.0-rc.1.9171" />
<PackageVersion Include="Microsoft.Maui.Resizetizer" Version="8.0.0-rc.1.9171" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0-rc.1.23419.4" />
<PackageVersion Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0-rc.1.23419.4" />

Build Logs

msbuild.binlog.zip

Example Project

Example project where this failure occurs is here: https://github.com/enclave-alistair/dotnet-ios-netextension/tree/without-trimming-workaround

Workaround is applied on main of that repo, the without-trimming-workaround branch fails to build.

@rolfbjarne rolfbjarne added bug If an issue is a bug or a pull request a bug fix regression The issue or pull request is a regression labels Sep 19, 2023
@rolfbjarne rolfbjarne added this to the .NET 9 milestone Sep 19, 2023
@rolfbjarne
Copy link
Member

I can reproduce this.

rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Sep 19, 2023
…ry projects. Fixes xamarin#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 (xamarin#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 xamarin#19037.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug If an issue is a bug or a pull request a bug fix regression The issue or pull request is a regression
Projects
None yet
Development

No branches or pull requests

2 participants