ice-builder-visualstudio icon indicating copy to clipboard operation
ice-builder-visualstudio copied to clipboard

C# Source Generator instead of MSBuild task juggling

Open Gulum opened this issue 1 year ago • 3 comments

How likely is it that the .ice Source file generation for C# will be migrated to C# Source Generators instead of MSBuild task juggling? Are there any plans?

Gulum avatar Jul 10 '24 07:07 Gulum

Hi Gulum,

There is no plan for this, the MSBuild task just runs the slice2cs compiler which is a C++ binary. Can you elaborate on your use case and why you would prefer to have this in a source generator?

Cheers, Jose

pepone avatar Jul 10 '24 08:07 pepone

In our company we would like to generate slice files based on c# classes with the help of C# Source Generators. Those generators run as a part of the compiler. The Slice2CS generator runs upfront of the CSC compiler not allowing us to use outputs from the Source Generator. This forces us to also use MSBuild based generators to ensure correct generation order. E.g. Generate .ice files -> Generate C# files (Slice2CS) -> Run C# Compiler.

From my point of view the Source Generators lacks features to allow such a flow anyway.

  • Ensure generator execution order (Ours need to be run before yours). (https://github.com/dotnet/roslyn/issues/57239)
  • Allow Source Generator to output non Source Files to the compiler. We would need to output the ICE files to be used as input to your Source Generator. (https://github.com/dotnet/roslyn/issues/57608)

Both features are already on the Backlog of C#. So i might return to this request :). At the moment my question was out of curiosity if something like this is planned. Not a concrete request. However the mentioned lacking feature would not keep ICE from using Source Generators.

Thanks

Gulum avatar Jul 10 '24 08:07 Gulum

This forces us to also use MSBuild based generators to ensure correct generation order. E.g. Generate .ice files -> Generate C# files (Slice2CS) -> Run C# Compiler.

One thing you can try is to run slice2cs from your generator, it shouldn't be too difficult using the Process class.

For [IceRPC] our latest RPC product, we are planning to allow using Slice without Slice files, see https://github.com/icerpc/icerpc-csharp/issues/4011

We are already using Source generators for Services https://docs.icerpc.dev/slice2/language-guide/interface#c#-mapping

And we are planning to move code generation entirely to C# https://github.com/icerpc/icerpc-csharp/issues/3978

pepone avatar Jul 10 '24 09:07 pepone