Skip to content

Add PreserveAttribute to generic formatters for Unity IL2CPP #2136

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

Merged
merged 1 commit into from
Jan 27, 2025

Conversation

neuecc
Copy link
Member

@neuecc neuecc commented Jan 23, 2025

In Unity's AOT environment, MakeGenericType often works for Full Generic Sharing.
https://unity.com/blog/engine-platform/il2cpp-full-generic-sharing-in-unity-2022-1-beta

Therefore, even with AvoidDynamicCode, we include DynamicGenericResolver in StandardResolver.
However, if the Formatter itself is stripped, it naturally won't function.
While this behavior changes depending on Unity's build settings' StrippingLevel,
we want MessagePack for C# to operate as naturally as possible even at the highest stripping level.

To achieve this, we'll make Generic Formatters preserve.
Since PreserveAttribute can be application-specific, we'll implement it as an internal type.
https://docs.unity3d.com/6000.0/Documentation/Manual/managed-code-stripping-preserving.html

Additionally, when supporting the generation of Generic-compatible Formatters,
it might be worth considering making it a public type and applying it to generated types.

#2134 is also related, Having looked into Native AOT related matters recently, I'm starting to think it's better to settle for an approach where things work - even if they might result in runtime errors in some cases - with workarounds available, rather than obsessing over 100% compatibility.

@neuecc neuecc merged commit c52c51d into master Jan 27, 2025
3 checks passed
@neuecc neuecc deleted the more-il2cpp branch January 27, 2025 07:47
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

Successfully merging this pull request may close these issues.

1 participant