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

Support NativeAOT as a runtime variant for iOS platforms #17339

Closed
20 tasks done
Tracked by #80905
ivanpovazan opened this issue Jan 23, 2023 · 4 comments
Closed
20 tasks done
Tracked by #80905

Support NativeAOT as a runtime variant for iOS platforms #17339

ivanpovazan opened this issue Jan 23, 2023 · 4 comments
Assignees
Labels
dotnet An issue or pull request related to .NET (6) feature A feature to be implemented
Milestone

Comments

@ivanpovazan
Copy link
Contributor

ivanpovazan commented Jan 23, 2023

Description

To enable Supporting NativeAOT on iOS platforms as an experimental feature in .NET8 it is required to adjust Xamarin runtime, build system and SDK accordingly.

Tasks

The following list of tasks give a top-level overview of work that is required to enable this feature:

.NET 8

.NET 9

UPDATE: .NET9 tasks are moved to the top-level tracking issue:


PS The list of tasks is not complete. Feel free to extend it, change it and add more context.

@ivanpovazan
Copy link
Contributor Author

  • Introduce new managed-to-native bridge for NativeAOT runtime

The bridge will be responsible for properly initialising the NativeAOT runtime, invoking any managed code initialisation e.g.:

unsafe static void Initialize (InitializationOptions* options)
, and finally invoking the managed Main method.

See this comment for more information: dotnet/runtime#77957 (comment)

@jkotas
Copy link

jkotas commented Jan 24, 2023

Introduce new managed-to-native bridge for NativeAOT runtime

Why is this bridge better than just injecting static constructor into the app with default bootstrapper? Injecting static constructor into the app looks more composable.

rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Jan 25, 2023
@ivanpovazan
Copy link
Contributor Author

ivanpovazan commented Jan 26, 2023

Why is this bridge better than just injecting static constructor into the app with default bootstrapper? Injecting static constructor into the app looks more composable.

Thanks for the suggestion, but at the moment there seem to be some limitations around it. If you are referring to the default bootstrapper provided by NativeAOT, it currently cannot be used from a native hosting app, when the managed executable is compiled as a static library, as the ILCompiler will not expose its managed Main method entry point (reported here: dotnet/runtime#81097).

@rolfbjarne also gave an explanation on why it is required Xamarin to act as a native hosting application here: dotnet/runtime#77957 (comment)

Finally, the requirement for:

Introduce new managed-to-native bridge for NativeAOT runtime

is written in more general terms, as mono and coreCLR runtimes have their dedicated bridges, so supporting NativeAOT would use the same logic without changing current implementation much.

Afaik, injecting static constructor does not allow the method to have parameters, so if we would want to use it for initializing Xamarin's ObjCRuntime, we would have to change the code to PInvoke into the native to get the required parameters. It is not my call and I could be wrong, but this sounds like more work (especially making sure that the change does not break what is already supported).

@marek-safar marek-safar changed the title Support NativeAOT as a third runtime variant with Xamarin for iOS platforms Support NativeAOT as a runtime variant for iOS platforms Jan 27, 2023
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Apr 28, 2023
filipnavara pushed a commit to filipnavara/xamarin-macios that referenced this issue May 7, 2023
filipnavara pushed a commit to filipnavara/xamarin-macios that referenced this issue May 9, 2023
filipnavara pushed a commit to filipnavara/xamarin-macios that referenced this issue May 12, 2023
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue May 19, 2023
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue May 26, 2023
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue May 26, 2023
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Jun 1, 2023
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Jun 2, 2023
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Jun 5, 2023
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Jun 6, 2023
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Jun 6, 2023
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Jun 7, 2023
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Jun 9, 2023
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Jun 9, 2023
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Jun 12, 2023
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Jun 13, 2023
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Jun 14, 2023
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Jun 15, 2023
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Jun 19, 2023
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Jun 20, 2023
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Jun 20, 2023
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Jun 22, 2023
rolfbjarne added a commit that referenced this issue Jun 22, 2023
Add support for using NativeAOT on all our platforms.

This contains numerous changes in a lot of places to add support for
NativeAOT:

* build logic
* runtime
* managed code
* tests 

And it all pretty much consists of special-casing NativeAOT everywhere
we need to.

Note: NativeAOT doesn't work on macOS yet, because a dotnet/runtime fix
is required, and thus the corresponding test variations for
monotouch-test have been commented out.

This PR is best reviewed commit-by-commit.

This contributes towards #17339.
@ivanpovazan
Copy link
Contributor Author

Closing this issue as all subtasks have been completed for the .NET8 timeframe.
The remaining 2 issues for .NET9 milestone are moved to the top-level tracking issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dotnet An issue or pull request related to .NET (6) feature A feature to be implemented
Projects
None yet
Development

No branches or pull requests

3 participants