xamarin / xamarin-macios

.NET for iOS, Mac Catalyst, macOS, and tvOS provide open-source bindings of the Apple SDKs for use with .NET managed languages such as C#
Other
2.43k stars 505 forks source link

NativeAOT: Properly support macOS universal apps #20903

Open ivanpovazan opened 1 month ago

ivanpovazan commented 1 month ago

Description

It seems that we do not properly support building macOS universal apps (RuntimeIdentifiers=osx-arm64;osx-x64) with NativeAOT. There are issue with both Debug and Release configuration.

Repro

  1. Create a template macOS app: dotnet new macos
  2. Edit the project file to include:
    <RuntimeIdentifiers>osx-x64;osx-arm64</RuntimeIdentifiers>
    <PublishAot>true</PublishAot>
  3. Publish the project in Debug and later in Release configuration via: dotnet publish -c <configuration>

Debug configuration

Publishing with NativeAOT in Debug configuration fails at app bundle merging and produces the following error:

/usr/local/share/dotnet/packs/Microsoft.macOS.Sdk/14.2.8078/targets/Xamarin.Shared.Sdk.targets(395,3): error : Unable to merge the file 'Contents/MonoBundle/NaotMac.pdb', it's different between the input app bundles. [/Users/ivan/tmp/getspecial/NaotMac/NaotMac.csproj]
/usr/local/share/dotnet/packs/Microsoft.macOS.Sdk/14.2.8078/targets/Xamarin.Shared.Sdk.targets(395,3): error : App bundle file #1: /Users/ivan/tmp/getspecial/NaotMac/bin/Debug/net8.0-macos/osx-x64/NaotMac.app/Contents/MonoBundle/NaotMac.pdb [/Users/ivan/tmp/getspecial/NaotMac/NaotMac.csproj]
/usr/local/share/dotnet/packs/Microsoft.macOS.Sdk/14.2.8078/targets/Xamarin.Shared.Sdk.targets(395,3): error : App bundle file #2: /Users/ivan/tmp/getspecial/NaotMac/bin/Debug/net8.0-macos/osx-arm64/NaotMac.app/Contents/MonoBundle/NaotMac.pdb [/Users/ivan/tmp/getspecial/NaotMac/NaotMac.csproj]

Release configuration

Publishing with NativeAOT succeeds in Release configuration but the universal app bundle is not present in the expected location (notice the runtime identifier in the path):

Created the package: /Users/ivan/tmp/getspecial/NaotMac/bin/Release/net8.0-macos/osx-arm64/publish/NaotMac-1.0.pkg

The expected location (when building the same app with CoreCLR ie PublishAot=false) gives the bundle at:

Created the package: /Users/ivan/tmp/getspecial/NaotMac/bin/Release/net8.0-macos/publish/NaotMac-1.0.pkg
ivanpovazan commented 1 month ago

/cc: @filipnavara