CollinAlpert / Lombok.NET

.NET adaptation for Java's Lombok using Source Generators.
MIT License
309 stars 16 forks source link

Unity Support #22

Closed igor-100 closed 1 year ago

igor-100 commented 1 year ago

Doesn't work with Unity 2021.3.1f1 (and probably with any other version). Will you consider supporting it?

CollinAlpert commented 1 year ago

What exactly does not work?

I have no experience with Unity so far, so either you can supply a PR which adds support or you can let me know what needs to be done. If it is not too much effort, I will consider maintaining it.

igor-100 commented 1 year ago

There are errors when I try to import the project. It seems that Unity's backend (Mono) version has a bit outdated .NET libraries. I'll try to fix it on my own later, I just hoped that you might know the solution.

Starting: C:\Program Files\Unity 2021.3.1f1\Editor\Data\bee_backend.exe --profile="Library/Bee/backend_profiler0.traceevents" --stdin-canary --dagfile="Library/Bee/1900b0aEDbg.dag" --continue-on-failure ScriptAssemblies
WorkingDir: ~
ExitCode: 0 Duration: 0s908ms
[725/730    0s] Csc Library/Bee/artifacts/1900b0aEDbg.dag/Assembly-CSharp.dll (+2 others)
warning CS8032: An instance of analyzer Lombok.NET.PropertyGenerators.NotifyPropertyChangedGenerator cannot be created from ~Assets\Packages\Lombok.NET.2.1.0\analyzers\dotnet\cs\Lombok.NET.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified..

...

Reloading assemblies after forced synchronous recompile.
Begin MonoManager ReloadAssembly
Symbol file LoadedFromMemory doesn't match image ~Library\PackageCache\com.unity.visualscripting@1.7.6\Editor\VisualScripting.Core\Dependencies\YamlDotNet\Unity.VisualScripting.YamlDotNet.dll
Symbol file LoadedFromMemory is not a mono symbol file
Symbol file LoadedFromMemory doesn't match image ~Library\PackageCache\com.unity.visualscripting@1.7.6\Editor\VisualScripting.Core\Dependencies\DotNetZip\Unity.VisualScripting.IonicZip.dll
Assembly 'Assets/Packages/System.Reflection.Metadata.5.0.0/lib/netstandard2.0/System.Reflection.Metadata.dll' will not be loaded due to errors:
System.Reflection.Metadata references strong named System.Collections.Immutable Assembly references: 5.0.0.0 Found in project: 6.0.0.0.
Assembly Version Validation can be disabled in Player Settings "Assembly Version Validation"
Assembly 'Assets/Packages/Microsoft.CodeAnalysis.Common.4.3.1/lib/netstandard2.0/Microsoft.CodeAnalysis.dll' will not be loaded due to errors:
Reference has errors 'System.Reflection.Metadata'.
Assembly 'Assets/Packages/Microsoft.CodeAnalysis.CSharp.4.3.1/lib/netstandard2.0/Microsoft.CodeAnalysis.CSharp.dll' will not be loaded due to errors:
Reference has errors 'Microsoft.CodeAnalysis'.
Assembly 'Assets/Packages/Microsoft.CodeAnalysis.Workspaces.Common.4.3.1/lib/netstandard2.0/Microsoft.CodeAnalysis.Workspaces.dll' will not be loaded due to errors:
Unable to resolve reference 'SQLitePCLRaw.core'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.
Unable to resolve reference 'SQLitePCLRaw.batteries_v2'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.
Assembly 'Assets/Packages/Microsoft.CodeAnalysis.CSharp.Workspaces.4.3.1/lib/netstandard2.0/Microsoft.CodeAnalysis.CSharp.Workspaces.dll' will not be loaded due to errors:
Reference has errors 'Microsoft.CodeAnalysis.Workspaces'.
Assembly 'Assets/Packages/Lombok.NET.2.1.0/lib/netstandard2.0/Lombok.NET.dll' will not be loaded due to errors:
Reference has errors 'Microsoft.CodeAnalysis.CSharp'.
Native extension for WindowsStandalone target not found
CollinAlpert commented 1 year ago

What .NET and VS version (or Rider) are you using? If it's VS, it needs to be at least v17.3.

igor-100 commented 1 year ago

I'm using NuGetForUnity https://github.com/GlitchEnzo/NuGetForUnity, it seems to depend on Unity only. It's not a VS or Rider extension.

igor-100 commented 1 year ago

And I can see that you're using C# 10.0 and a current version of Unity supports C#9.0 only

CollinAlpert commented 1 year ago

Yes, the generators generate C# 10 code. Is there no way to use C# 10 in Unity?

CollinAlpert commented 1 year ago

Have you tried the steps described in the "Installing an existing Roslyn analyzer or source generator" section of https://docs.unity3d.com/Manual/roslyn-analyzers.html?

igor-100 commented 1 year ago

Yes, the generators generate C# 10 code. Is there no way to use C# 10 in Unity?

nope, Mono doesn't support it yet

Have you tried the steps described in the "Installing an existing Roslyn analyzer or source generator" section of https://docs.unity3d.com/Manual/roslyn-analyzers.html?

I've also found it but haven't tried it yet, perhaps a little later, I'll tell you about the results here.

igor-100 commented 1 year ago

@CollinAlpert Okay I tried to follow those steps. It seems that you have newer versions of Microsoft.CodeAnalysis dependencies than it is allowed by Unity.

Unity suggests using Microsoft.CodeAnalysis.CSharp 3.8.0 in the manual. And it doesn't contain:

  1. GeneratorAttributeSyntaxContext from Microsoft.CodeAnalysis.Common v4.3.0. Unity's latest package is 3.8.0
  2. IIncrementalGenerator from Microsoft.CodeAnalysis.Common v4.0.1. Unity's latest package is 3.8.0
  3. IncrementalGeneratorInitializationContext from Microsoft.CodeAnalysis.Common v4.3.0. Unity's latest package is 3.8.0 On top of that you use FileScopedNamespaceDeclaration from C# 10. Unity uses C# 9.0

I guess the only solution here is to replace these dependencies somehow but I'm not sure if it's possible.

CollinAlpert commented 1 year ago

I see! If you want to fork this library and downgrade the dependencies, I could help you maintain it. As for IIncrementalGenerator compared to ISourceGenerator, I made the switch in the commit https://github.com/CollinAlpert/Lombok.NET/commit/ee788bb01a6e62eaa1bf5923853479b0b57a6241, so you could look at how the generators were constructed before that.

igor-100 commented 1 year ago

I don't think I'll dive into that soon enough or ever at all but thank you for your help! Perhaps someone would work on that someday later at least knowing what he has to do after we investigated the issue. Anyway, great project!

CollinAlpert commented 1 year ago

No worries, I get it :) I hope you manage to use the library at some other point.