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

NativeAOT: Universal apps are not building correctly with NativeAOT #20903

Closed
ivanpovazan opened this issue Jul 15, 2024 · 2 comments
Closed
Assignees
Milestone

Comments

@ivanpovazan
Copy link
Contributor

ivanpovazan commented Jul 15, 2024

Description

It seems that we do not properly support building universal apps (RuntimeIdentifiers=osx-arm64;osx-x64 or maccatalyst-arm64;maccatalyst-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>
  1. 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
Copy link
Contributor Author

/cc: @filipnavara

@rolfbjarne rolfbjarne added this to the .NET 9 milestone Aug 1, 2024
@github-project-automation github-project-automation bot moved this to NativeAOT in .NET 9 Aug 27, 2024
@ivanpovazan ivanpovazan self-assigned this Sep 16, 2024
@ivanpovazan ivanpovazan changed the title NativeAOT: Properly support macOS universal apps NativeAOT: Universal apps are not building correctly with NativeAOT Sep 23, 2024
rolfbjarne pushed a commit that referenced this issue Sep 23, 2024
#21288)

### Description 

When building universal apps with NativeAOT, the output path for the app bundle (and zipped .ipa) is incorrect when building with NativeAOT.

For example publishing a MAUI template app with NativeAOT gives the following output (notice: `osx-arm64`):
```
Created the package: /Users/ivan/tmp/net9-rc1/MacCatRc1/bin/Release/net9.0-maccatalyst/osx-arm64/publish/MacCatRc1-1.0.pkg
```
and the following output tree:
```
bin/Release 
bin/Release/net9.0-maccatalyst 
bin/Release/net9.0-maccatalyst/maccatalyst-arm64/*
bin/Release/net9.0-maccatalyst/maccatalyst-x64/*
bin/Release/net9.0-maccatalyst/osx-arm64
bin/Release/net9.0-maccatalyst/osx-arm64/MacCatRc1.app/*
bin/Release/net9.0-maccatalyst/osx-arm64/publish/*
```

The problem comes from the fact that .NET SDK for NativeAOT builds will try to resolve `RuntimeIdentifier` when it is not specified in:
https://github.com/dotnet/sdk/blob/58eb155e30a393656dd290486143f02f958898fc/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.RuntimeIdentifierInference.targets#L95-L114

which resolves to `osx-arm64` and gets later used to setup `IntermediateOutputPath` and `OutputPath` in:
https://github.com/dotnet/sdk/blob/58eb155e30a393656dd290486143f02f958898fc/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.RuntimeIdentifierInference.targets#L343-L346
 
However, this shouldn't be done in universal builds, as the outer build does not have the runtime identifier specified and should not be altered.

### Changes

In this PR we are disabling the resolution of the `RuntimeIdentifier` when building universal apps with NativeAOT early in SDK in order to fix the output path.

I also included unit tests to verify the existence of .app bundles. 

### Follow-up

There is an additional issue with Debug builds of universal apps with NativeAOT, where merging PDBs fails, which is reported in: #20903

---
Contributes to: #20903

---------

Co-authored-by: Ivan Povazan <[email protected]>
rolfbjarne pushed a commit that referenced this issue Sep 24, 2024
### Description

Previously we were including .pdbs in NativeAOT debug bundles, which was causing issues with debug builds of universal apps (during app bundle merging). This does not seem to be required, as in debug builds NativeAOT compiler uses information from pdbs to provide more data about the managed code during native debugging (like line numbers in stack traces, etc), embedding it into the native image, and does not require presence of said files during runtime.

### Changes

- This PR excludes pdbs from NativeAOT app bundles by removing them from `ResolvedFileToPublish` item group.
- The relevant unit tests are reenabled.

---
Fixes #20903
@rolfbjarne
Copy link
Member

Fixed in #21291.

@github-project-automation github-project-automation bot moved this from NativeAOT to Done in .NET 9 Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

2 participants