Skip to content

AOT support #50

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

Open
tonyqus opened this issue Jul 9, 2024 · 5 comments
Open

AOT support #50

tonyqus opened this issue Jul 9, 2024 · 5 comments

Comments

@tonyqus
Copy link

tonyqus commented Jul 9, 2024

Hi, I'm the guy who maintains NPOI. Enums.NET is really nice. Thank you for the nice work.

I'd like to check if you have plan to support AOT because someone suggests me to get rid of Enums.NET in order to support AOT. But I don't like his idea. I think it's better to check with you first.

@TylerBrinkley
Copy link
Owner

Sorry I've never used Enums.NET from an AOT app. Can you explain what things are broken in Enums.NET in an AOT environment? Is there some reflection I'm doing that's not supported?

@TylerBrinkley
Copy link
Owner

It looks like I tried addressing AOT support for Unity in #23 but never received feedback if it fixed it.

@tonyqus
Copy link
Author

tonyqus commented Jul 10, 2024

I'm not an expert of AOT. But as I understand, if you use anything about reflection, then it's not AOT compatible.

Please check this issue: nissl-lab/npoi#1156

It's not so urgent as I don't believe AOT can get popular in a short time. But you can check if it's possible to make Enums.NET AOT compatible.

@TylerBrinkley
Copy link
Owner

@karakasa Would you be able to enlighten me on what changes or attributes I should add to add AOT support? Thanks.

@mikernet
Copy link

mikernet commented Oct 22, 2024

The basic steps are as follows:

  1. Mark the project as AOT compatible for net6+ targets: https://github.com/Singulink/Singulink.Enums/blob/cb3845ea1d2bf4f2d090c44dd77a13668ef7def1/Source/Directory.Build.props#L16-L19
  2. Add -windows targets if you also want to ensure that your library won't have any problems with AOT windows apps. The <CsWinRTAotWarningLevel> element from above ensures that you won't get any runtime marshalling exceptions when using types from your library with WinRT.
  3. Build and observe that you will get a bunch of trim and/or AOT warnings. Iteratively fix all of them until there are no more warnings when you build.

Most of step 3 will likely involve annotating generic type parameters, such as: https://github.com/Singulink/Singulink.Enums/blob/cb3845ea1d2bf4f2d090c44dd77a13668ef7def1/Source/Singulink.Enums/EnumExtensions.cs#L24, but you can get more info on what may be required here:
https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/prepare-libraries-for-trimming?pivots=dotnet-8-0

@tonyqus Shameless plug for the lib linked above, just released v2 with AOT support if you want something similar to enums.net that is AOT compatible right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants