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

Add support for NativeAOT on macOS #18524

Closed
wants to merge 14 commits into from

Conversation

filipnavara
Copy link
Contributor

No description provided.

@akoeplinger
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@dalexsoto
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@filipnavara
Copy link
Contributor Author

filipnavara commented Jul 1, 2023

I wonder what the dotnettests failure is. If you can repost the logs publicly it would be great.

Also, it seems that _LinkMode may get a wrong default value which causes quite unexpected errors (dotnet/runtime#88287). It needs some additional investigation.

UPD: #18530

@mandel-macaque
Copy link
Member

I wonder what the dotnettests failure is. If you can repost the logs publicly it would be great.

Also, it seems that _LinkMode may get a wrong default value which causes quite unexpected errors (dotnet/runtime#88287). It needs some additional investigation.

UPD: #18530

The tests are failing with the following error:

DotNet tests (Failed)
Failure: Execution failed with exit code 1 
Project file: /Users/builder/azdo/_work/2/s/xamarin-macios/tests/dotnet/UnitTests/DotNetUnitTests.csproj 
Platform: Configuration: Debug 
Build duration: 00:00:14.8218009 
Time Elapsed: DotNet tests - (waiting time : 00:00:00.0000011 , running time : 02:11:06.1980065) 
[TrxLog](file:///Users/mandel/Downloads/HtmlReport-simulator_dotnettests-1/tests/DotNet-tests/506/results-20230630_201259.trx)
Xamarin.Tests.TemplateTest.CreateAndBuildItemTemplates(MacOSX,CSharp): Contains magic word
Expected: String containing "5629d1db-a947-4384-8755-956e0f30c9db"
But was: <string.Empty>

Xamarin.Tests.TemplateTest.CreateAndBuildProjectTemplate(maccatalyst-visualbasic): Contains magic word
Expected: String containing "80c97376-bbb6-4764-a1fc-83eb152583b4"
But was: <string.Empty>

Xamarin.Tests.TemplateTest.CreateAndBuildItemTemplates(MacCatalyst,CSharp): Contains magic word
Expected: String containing "baaaf182-f2a3-4ffd-ab5c-24c949ae9fcb"
But was: <string.Empty>

Xamarin.Tests.TemplateTest.CreateAndBuildProjectTemplate(macos-csharp): Contains magic word
Expected: String containing "845db586-297e-4dd5-bccf-7b1fba2d0392"
But was: <string.Empty>

Xamarin.Tests.TemplateTest.CreateAndBuildProjectTemplate(maccatalyst-csharp): Contains magic word
Expected: String containing "8a74e085-bce4-440e-ba14-79ed8ba952a6"
But was: <string.Empty>

Xamarin.Tests.IncrementalBuildTest.NativeLink(iOS,"ios-arm64"): The target '_AOTCompile' was not executed: the target was found 1 time(s) in the binlog, but they were all skipped (B)
Xamarin.Tests.TemplateTest.CreateAndBuildProjectTemplate(macos-visualbasic): Contains magic word
Expected: String containing "c93a685e-8ca7-4854-94d1-2f46121033a4"
But was: <string.Empty>

Logs can be found here: https://gist.github.com/mandel-macaque/93cc94e2258904f9abc9c9b7b3ddbc06

Copy link
Member

@mandel-macaque mandel-macaque left a comment

Choose a reason for hiding this comment

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

We should get to the bottom of the failing tests, but code looks good.

@filipnavara
Copy link
Contributor Author

We should get to the bottom of the failing tests, but code looks good.

Thanks! I will check these tests locally... (likely not until next week, I am at remote location with spotty internet connection)

@dalexsoto
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne
Copy link
Member

The monotouch-test failures are unrelated, but the dotnettests ones aren't.

The macOS/mac catalyst template tests are failing:

Xamarin.Tests.TemplateTest.CreateAndBuildProjectTemplate(macos-visualbasic): Contains magic word
Expected: String containing "37888137-2a68-44a5-927c-ebe7a9ae9c45"
But was: <string.Empty>

Xamarin.Tests.TemplateTest.CreateAndBuildProjectTemplate(maccatalyst-csharp): Contains magic word
Expected: String containing "d9b87b1a-9a5c-4f6b-bfb1-7fb1fd4966a0"
But was: <string.Empty>

Xamarin.Tests.TemplateTest.CreateAndBuildProjectTemplate(maccatalyst-visualbasic): Contains magic word
Expected: String containing "031fe3d3-1ccb-46cb-a638-6c245a4f6953"
But was: <string.Empty>

Xamarin.Tests.TemplateTest.CreateAndBuildItemTemplates(MacOSX,CSharp): Contains magic word
Expected: String containing "fa2b769a-6364-41e0-a6d2-df5a08d434d3"
But was: <string.Empty>

Xamarin.Tests.TemplateTest.CreateAndBuildProjectTemplate(macos-csharp): Contains magic word
Expected: String containing "d08c2325-cd6b-4f82-9ea4-4235ba36147f"
But was: <string.Empty>

Xamarin.Tests.TemplateTest.CreateAndBuildItemTemplates(MacCatalyst,CSharp): Contains magic word
Expected: String containing "39970c1a-fa3a-403d-b6be-adaacc4c0668"
But was: <string.Empty>

I investigated a bit:

  1. In the template tests, we create a new project from a template, and then inject code in the Main method to return immediately (so that when running the built app it actually exits).
  2. When it fails, the linker removes the newly added code... so the new app launches, but never exits. IL diff for before and after linking: https://gist.github.com/rolfbjarne/383f0feaa2b291ddf420cdb7083edb52#file-ab-diff

This is rather puzzling, I wouldn't have expected any of the changes here to have such an effect.

@filipnavara
Copy link
Contributor Author

Thanks for digging into the dotnettests tests. I am still puzzled by it but I think I finally managed to run some of these tests locally, so I can investigate.

@rolfbjarne
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [PR Build] Tests on macOS M1 - Mac Ventura (13.0) passed 💻

All tests on macOS M1 - Mac Ventura (13.0) passed.

Pipeline on Agent
Hash: [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build] Windows Integration Tests passed 💻

All Windows Integration Tests passed.

Pipeline on Agent
Hash: c7742fc1c4b0dabcc6f9b15b7891d6e08b1e7927 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [PR Build] Tests on macOS M1 - Mac Big Sur (11.5) passed 💻

All tests on macOS M1 - Mac Big Sur (11.5) passed.

Pipeline on Agent
Hash: [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

📚 [PR Build] Artifacts 📚

Packages generated

View packages

Pipeline on Agent
Hash: [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ API diff for current PR / commit

Legacy Xamarin (No breaking changes)
  • iOS (no change detected)
  • tvOS (no change detected)
  • watchOS (no change detected)
  • macOS (no change detected)
NET (empty diffs)
  • iOS: (empty diff detected)
  • tvOS: (empty diff detected)
  • MacCatalyst: (empty diff detected)
  • macOS: (empty diff detected)

✅ API diff vs stable

Legacy Xamarin (No breaking changes)
.NET (No breaking changes)
Legacy Xamarin (stable) vs .NET

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: c7742fc1c4b0dabcc6f9b15b7891d6e08b1e7927 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

🚀 [CI Build] Test results 🚀

Test results

✅ All tests passed on VSTS: simulator tests.

🎉 All 233 tests passed 🎉

Tests counts

✅ bcl: All 69 tests passed. Html Report (VSDrops) Download
✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests: All 1 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 7 tests passed. Html Report (VSDrops) Download
✅ framework: All 8 tests passed. Html Report (VSDrops) Download
✅ generator: All 2 tests passed. Html Report (VSDrops) Download
✅ interdependent_binding_projects: All 7 tests passed. Html Report (VSDrops) Download
✅ install_source: All 1 tests passed. Html Report (VSDrops) Download
✅ introspection: All 8 tests passed. Html Report (VSDrops) Download
✅ linker: All 65 tests passed. Html Report (VSDrops) Download
✅ mac_binding_project: All 1 tests passed. Html Report (VSDrops) Download
✅ mmp: All 2 tests passed. Html Report (VSDrops) Download
✅ mononative: All 6 tests passed. Html Report (VSDrops) Download
✅ monotouch: All 39 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ mtouch: All 1 tests passed. Html Report (VSDrops) Download
✅ xammac: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 8 tests passed. Html Report (VSDrops) Download
✅ xtro: All 2 tests passed. Html Report (VSDrops) Download

Pipeline on Agent
Hash: c7742fc1c4b0dabcc6f9b15b7891d6e08b1e7927 [PR build]

Copy link
Member

@dalexsoto dalexsoto left a comment

Choose a reason for hiding this comment

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

❤️

@rolfbjarne
Copy link
Member

I believe some of these changes aren't necessary anymore now that I've added support for the [Preserve] attribute (so test suites can be fully linked for NativeAOT), so I've created a different PR (#18765) to test this hypothesis. I'll analyze the results next Tuesday.

@ivanpovazan
Copy link
Contributor

ivanpovazan commented Aug 22, 2023

Should we also try to cleanup this code within this PR?

#if !NET || !__MACOS__
[MethodImplAttribute (MethodImplOptions.InternalCall)]
extern static void RegisterToggleRef (NSObject obj, IntPtr handle, bool isCustomType);
#endif // !NET || !__MACOS__
[DllImport ("__Internal")]
static extern void xamarin_release_managed_ref (IntPtr handle, [MarshalAs (UnmanagedType.I1)] bool user_type);
static void RegisterToggleReference (NSObject obj, IntPtr handle, bool isCustomType)
{
#if NET && __MACOS__
Runtime.RegisterToggleReferenceCoreCLR (obj, handle, isCustomType);
#elif NET
if (Runtime.IsCoreCLR) {
Runtime.RegisterToggleReferenceCoreCLR (obj, handle, isCustomType);
} else {
RegisterToggleRef (obj, handle, isCustomType);
}
#else
RegisterToggleRef (obj, handle, isCustomType);
#endif
}

to something like:

#if !NET
 		[MethodImplAttribute (MethodImplOptions.InternalCall)] 
 		extern static void RegisterToggleRef (NSObject obj, IntPtr handle, bool isCustomType); 
#endif // !NET
// ...
                static void RegisterToggleReference (NSObject obj, IntPtr handle, bool isCustomType) 
 		{ 
 #if NET
 			Runtime.RegisterToggleReferenceCoreCLR (obj, handle, isCustomType); 
 #else 
 			RegisterToggleRef (obj, handle, isCustomType); 
 #endif 
 		} 

@filipnavara
Copy link
Contributor Author

@ivanpovazan That's not equivalent. We still use MonoVM on .NET 8 ;)

@ivanpovazan
Copy link
Contributor

ivanpovazan commented Aug 22, 2023

My mistake, I misinterpreted what NET preprocessor directive does.

Why I was mentioning this part of the code is that we get:
ILC: Method '[Microsoft.iOS]Foundation.NSObject.RegisterToggleRef(NSObject,native int,bool)' will always throw because: Invalid IL or CLR metadata in 'Void Foundation.NSObject.RegisterToggleRef(Foundation.NSObject, IntPtr, Boolean)'
from ILC (although when building an iOS app). So was thinking if simplifying that ifdef condition would fix this.

@filipnavara
Copy link
Contributor Author

Yeah, I would love to fix that warning but it's not that trivial. Definitely worth a separate PR.

@rolfbjarne
Copy link
Member

Superseded by #18765.

@rolfbjarne rolfbjarne closed this Aug 25, 2023
@rolfbjarne rolfbjarne added the community Community contribution ❤ label Aug 28, 2023
rolfbjarne pushed a commit that referenced this pull request Sep 6, 2023
This PR implements a workaround for the following build warning:

```
ILC: Method '[Microsoft.iOS]Foundation.NSObject.RegisterToggleRef(NSObject,native int,bool)' will always throw because:
Invalid IL or CLR metadata in 'Void Foundation.NSObject.RegisterToggleRef(Foundation.NSObject, IntPtr, Boolean)'
```

Ref #18524
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Community contribution ❤
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants