Entitas icon indicating copy to clipboard operation
Entitas copied to clipboard

Entitas with Roslyn Code Generation via ISourceGenerator

Open studentutu opened this issue 1 year ago • 4 comments

Hi,

I have a suggestion and would want to contribute. As in official code generation guide by Unity - https://docs.unity3d.com/Manual/roslyn-analyzers.html - we can use separate project and create dll which unity will use right in it's code compilation steps.

We already have a separate project for it - Jehny, all we need is to make sure that code gen is done by Microsoft Roslyn Source Generators, and put a label “RoslynAnalyzer” for the DLL inside the release branch (create a Unity package)

This way we don't need to use Jehny Server for constant monitoring of changes, and it will help clean up the workflow.

Here's some code that we need to use for Roslyn Source Generators

using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
using System.Text

[Generator]
public class ExampleSourceGenerator : ISourceGenerator
{
}

Hope it will be helpful.

studentutu avatar Aug 26 '22 16:08 studentutu

@studentutu thanks! Roslyn Source Generators is definitely sth I would like to research at some point! That might be useful for Entitas. Jenny however follows a different idea where the input can be anything, not just source code or assemblies. It more general purpose for any kind of code generation

sschmid avatar Aug 27 '22 16:08 sschmid

One downside is

Note: Roslyn analyzers are only compatible with the IDEs that Unity publically supports, which are Visual Studio and JetBrains Rider.

But I'll have a look

sschmid avatar Sep 14 '22 15:09 sschmid

Looks like we would need to switch to Unity when we make changes in order to recompile, which would take too long.

sschmid avatar Sep 14 '22 15:09 sschmid

Ok, building in the IDE works too 👍

sschmid avatar Sep 14 '22 15:09 sschmid

I've written a few Source Generators. My note would be to look into Incremental Source Generators if you decide to go this route. The perf of a normal ISourceGenerator isn't that great.

Unity 2022.2 supports the required newer Microsoft packages for that. They just haven't fixed their documentation yet.

rubenwe avatar Nov 01 '22 18:11 rubenwe