Visitar URL original
Add MESSAGEPACK_FORCE_AOT preprocessor directive by brwhelan-msft · Pull Request #1701 · MessagePack-CSharp/MessagePack-CSharp · GitHub
Skip to content

Add MESSAGEPACK_FORCE_AOT preprocessor directive - #1701

Merged
AArnott merged 2 commits into
MessagePack-CSharp:masterfrom
brwhelan-msft:force-messagepack-aot
Nov 12, 2023
Merged

AArnott merged 2 commits into
MessagePack-CSharp:masterfrom
brwhelan-msft:force-messagepack-aot

Conversation

@brwhelan-msft

Copy link
Copy Markdown

Adds a MESSAGEPACK_FORCE_AOT preprocessor directive which forces the same behaviour as IL2CPP under Unity, requiring formatters to be generated ahead of time via MPC/Source Generators.

This is useful when working in the editor, since at the moment a project running in the Editor runs under Mono, so will generate IL, but then building to IL2CPP can result in failures if the formatters haven't been generated. Setting this directive will result in this failing in the editor, providing consistent results against IL2CPP builds

@AArnott

AArnott commented Nov 7, 2023

Copy link
Copy Markdown
Collaborator

Why not just set ENABLE_IL2CPP in the editor?

@AArnott AArnott added the unity label Nov 7, 2023
@brwhelan-msft

Copy link
Copy Markdown
Author

Why not just set ENABLE_IL2CPP in the editor?

I'd considered this, but had concerns about the impact it could have on other packages relying on ENABLE_IL2CPP if set globally in the Editor, so opted to target the functionality in MessagePack directly

@AArnott AArnott left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks fine to me.
@neuecc Any concerns or alternative ideas?

@AArnott
AArnott requested a review from neuecc November 8, 2023 00:49
@luis-valverde-ms

Copy link
Copy Markdown

Thank you for the changes @brwhelan-msft . For maintainability, at least where it is used often, I think it would be good to have this defined:

#if !(MESSAGEPACK_FORCE_AOT || ENABLE_IL2CPP)
#define DYNAMIC_GENERATION
#endif

And check for DYNAMIC_GENERATION instead.

@AArnott

AArnott commented Nov 8, 2023

Copy link
Copy Markdown
Collaborator

at least where it is used often

I like the suggestion, but I'd go further and say it should be used consistently at the top of any file that uses any of these Defines symbols. Otherwise it seems likely we'll regress in later code changes.

@brwhelan-msft

Copy link
Copy Markdown
Author

Great idea - I've just pushed an update which switches to defining DYNAMIC_GENERATION at the top of any files affected, and using it throughout

@AArnott AArnott left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks great. I'll wait a few more days for @nuecc to chime in before merging.

@AArnott AArnott added this to the v2.5 milestone Nov 12, 2023
@AArnott
AArnott merged commit 415c592 into MessagePack-CSharp:master Nov 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants