SourceGenerators as a replacement for VS extensions? #50255
-
This is just question for SourceGenerators for some items that were not quite clear from the current design specs. We currently have a VS extension that is invoked in a single CUDA (*.cu, e.g. FFT.cu) file every time the user saves this files. Additionally, we run clang to extract the syntax tree from the CUDA code (from FFT.cu) and created a wrapper for the CUDA code so that it can be invoked from C#. This wrapper also loads the embedded resources (here: FFT.ptx) and does the necessary CUDA things. This wrapper is created or added to the project (here: FFT.designer.cs), marked with "compile". As above if it already there, it will be overriden. Addtionally, another file for user specific code is created (here: FFT.cs). But only once, it is not overriden when the users saves the CUDA code (FFT.cu). There reason why this cannot be done during typing is that the process takes a while (some 5-10 seconds) and therefore we have decided only to do it when saving the code. One problem is that extensions cannot be versioned and if I want to have another v ersion of the extension and need to uninstall it and install another version. So if I want to go back in source code history and in the meantime the CUDA extension has changed and need to know about this, otherwise I would create wrong ptx code. Also debugging extensions is a nightmare. So in my opinion source generator would be the optimal tool. I can add it via nuget, which versions itself automatically and I can add this solution wide via Directory.Build.props. My question is can source generator currently do this, and if not will they be able to do it in future versions? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
Today you'll run into a few problems. A source generator is capable of producing .cs files, so your wrapper could be easily produced. As you observed though we don't support generating embedded resources nor non-.cs files, so for now you wouldn't be able to do that. We're currently working on designs though for that so we absolutely expect those should be doable in future versions.
What parts of the process you describe are the slow ones? At this point we don't have a great plan for generators that take a really long time like this, but that's something further we'd have to work on. Better understanding your use case here would help us accommodate that scenario better. |
Beta Was this translation helpful? Give feedback.
Today you'll run into a few problems. A source generator is capable of producing .cs files, so your wrapper could be easily produced. As you observed though we don't support generating embedded resources nor non-.cs files, so for now you wouldn't be able to do that. We're currently working on designs though for that so we absolutely expect those should be doable in future versions.
What parts of the process you describe are the slow ones? At this point we don't have a great plan for generators that take a really long time like this, but that's something further we'd have to work on. …