Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Convert mpc and msbuild task package to a roslyn source generator #1599

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 97 commits into from
Apr 12, 2023

Conversation

AArnott
Copy link
Collaborator

@AArnott AArnott commented Apr 12, 2023

This completely replaces mpc and the msbuild task package with a C# roslyn Source Generator.

NuGet package impact:

Package Impact
MessagePack.MSBuild.Tasks Deprecated, and no longer built. This carried the msbuild integration that ran source generation before invoking the compiler. Users should stop referencing it and switch to MessagePack.SourceGenerator
MessagePack.Generator Deprecated, and no longer built. This carried the .NET CLI tool mpc. Unity users should now consume the source generator contained in the MessagePack.SourceGenerator.Unity.zip file.
MessagePack.SourceGenerator The new roslyn source generator for msbuild/VS users.
MessagePack.SourceGenerator.Unity.zip A new zip archive (not a nuget package), containing a source generator that targets Roslyn 3 for use by unity.

Ideas for future work (after this PR)

  1. Now that source generation can be totally automatic, should it just be on by default, and should we find a way to always find the generated formatters instead of requiring the user to specify the right resolver? For example, the source generator could add a [MessagePackFormatter] attribute on each [MessagePackObject] (provided the class is declared as partial) so that the default in-library resolvers will find the source generated formatter.
  2. A massive refactoring of the TypeCollector and analyzers so we don't have so much repeated and inconsistently updated code. For example, the check that the type passed to MessagePackFormatterAttribute derives from IMessagePackFormatter<T> is only performed for one possible place where the attribute can appear instead of everywhere it may appear. Field and property searches are also repeated in many places, again with inconsistent code handling them.

Remaining tasks

  • Add tests for the Roslyn3 project.
  • Confirm that this works with Unity.
  • Confirm that incremental source generation works, including that every type in the FullModel type hierarchy has functional equality comparers.
  • Stop building a roslyn3 nuget package and instead build a .zip that will be added to github releases alongside the .unitypackage we already ship.
  • Rename the Generator package to SourceGenerator so we aren't radically changing the type of an existing package, which will likely cause more confusion than no longer updating an existing package.
  • Remove diagnostic reporting from generator and add a dependency on the analyzer package.
  • Re-enable or remove the remaining Compile Remove items in the source generator test projects.
  • Unify TypeCollector across source generator and analyzer.
  • Source generator (and analyzer) to use precise assembly versioning

Closes #1495

Y-YoL and others added 30 commits December 2, 2022 21:39
- remove project dependency
- update dependency package version
The source generator will altogether deprecate this.
It presumably should be 3.8, but it doesn't compile with 3.8 at this point.
This will help with cacheability.
AArnott and others added 7 commits April 10, 2023 08:57
* Consolidate `TypeCollector` across analyzer and source generator.
* Use `System.Text.Json` instead of `TinyJsonReader`.
* Remove all diagnostic reporting from the source generator.
* Make the source generator depend on the analyzer, so that user gets diagnostics while using source generator by way of the analyzer.
@AArnott AArnott added this to the v2.6 milestone Apr 12, 2023
@AArnott AArnott requested a review from neuecc April 12, 2023 13:56
@AArnott
Copy link
Collaborator Author

AArnott commented Apr 12, 2023

@Y-YoL let me get the unity build working, and then can you try with the source generator again? I suspect it will only work when you set the analyzer label on the System.Text.Json.dll file as you do with the other source generator DLLs.

@AArnott
Copy link
Collaborator Author

AArnott commented Apr 12, 2023

@Y-YoL do you have any idea how to resolve this warning that appears a lot in the unity build?

warning CS8632: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

@AArnott
Copy link
Collaborator Author

AArnott commented Apr 12, 2023

I guess the CS8632 warnings are a pre-existing issue. I'd still love to solve it, but it's not blocking this PR.

The only important part is "additionalCompilerArguments", but there are many differences because Unity automatically migrates
@Y-YoL
Copy link
Contributor

Y-YoL commented Apr 12, 2023

Regarding CS8632 in Unity, it is necessary to write in the configuration file.
Try #1600

@AArnott
Copy link
Collaborator Author

AArnott commented Apr 12, 2023

I have unity installed and it looks like the source generator broke somewhere along the way. Probably when I added the dependency from the source generator to the analyzer project. I'm looking into it now.

AArnott added 3 commits April 12, 2023 09:48
This is important for dependency reasons, since code fixes bring in more dependencies than analyzers, and `dotnet build` and unity don't contain the dependencies required for code fixes.
@AArnott
Copy link
Collaborator Author

AArnott commented Apr 12, 2023

I fixed the build issues in unity it seems, but the analyzer and source generator no longer work at all (no errors, no warnings, no code gen). I had them working a while back, so I guess I broke something. Any ideas, @Y-YoL?

@AArnott
Copy link
Collaborator Author

AArnott commented Apr 12, 2023

Downgrading the System.Text.Json dependency to 5.0.0 gets the analyzer and source generator to work.

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.

2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.