ByronMayne / SourceGenerator.Foundations

A Source Generator for Source Generators. Gives out of the box support for transistent dependencies and logging right in Visual Studio
MIT License
26 stars 0 forks source link

Issue with library using banned symbols Environment and Assembly.Load #13

Closed kkukshtel closed 4 months ago

kkukshtel commented 5 months ago

This library seems like just the thing that would finally fix all my source generator deps woes. However when trying to use it, I'm seeing errors about banned symbols — specifically, the use of Enviornment and Assembly.Load.

I know a banned symbol is more of a.... suggestion, but I'm wondering if there are ways around this to either make the code not use this, or to suppress the error (RS1035).

ByronMayne commented 5 months ago

Hey,

It's a suggestion because it's very easy to get it wrong, and maybe even I could do it better.

I use them because one of the main feature is loading dependencies on external packages which source generators can't do themselves. So that involves using those Assembly api. I can add the compiler suppression warnings in the code. I had them at one time but have been moving things around as I work with this library.

Enviornment is just used to check if it's running within Visual Studio so you get the better debugging experience.

I can add the compiler suppression to both places these are used.

kkukshtel commented 5 months ago

Yeah I'm totally fine taking on the risk as well so maybe just compiler suppression in the lib would help, otherwise it blocks compilation on build.

kkukshtel commented 5 months ago

@ByronMayne I updated the package and the symbol errors went away but something is failing in the package itself:

/Users/kyle/.nuget/packages/sourcegenerator.foundations/1.5.3/build/SourceGenerator.Foundations.targets(27,5): 
error MSB3073: 
The command "/Users/kyle/.nuget/packages/sourcegenerator.foundations/1.5.3/build/SourceGenerator.Foundations.Injector.exe SGF.Reflection.AssemblyResolver Initialize /Users/kyle/Workspace/Dinghy/Depot.SourceGenerator/bin/Debug/netstandard2.0/Depot.SourceGenerator.dll" 
exited with code 126. [/Users/kyle/Workspace/Dinghy/Depot.SourceGenerator/Depot.SourceGenerator.csproj]

I'm running on a Mac M1 so maybe it's that the injector/this package only work on Windows as it's trying to invoke a .exe?

ByronMayne commented 5 months ago

Yup that is dependent on windows currently however it's something that I am currently working on removing. It was there because the constant fight with assembly resolution. I allowed for explicit definition of the module initialization order.

The problem is you if you use a type that is defined in a referenced assembly as a static member, the type will be attempted to resolved before the static constructor is invoked and at that point the assembly resolver is not hooked up, leading to your generator failing.

For the new changes I instead of your class being an IncrementalGenerator and being invoked by the compiler, I create a wrapper around your instance. This way I can make sure everything is initialized before your is called

kkukshtel commented 4 months ago

Does closing this mean the Windows dep is gone?

ByronMayne commented 4 months ago

It does not use the Exe anymore so in theory it should work, but I can't guarantee it as I don't own a mac.