Skip to content

Convert genRuntimeEventSources to a C# source generator #114810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

jkoritzinsky
Copy link
Member

Convert this script to C# to remove the only direct python usage from within our managed build.

I primarily converted this script with VSCode's Copilot's Agent mode with ChatGPT 4.1, with a few logic adjustments as necessary to match the python script's codegen.

@Copilot Copilot AI review requested due to automatic review settings April 17, 2025 23:31
@ghost ghost added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Apr 17, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR converts a Python-based code generation script into a C# source generator to remove a direct Python dependency from our managed build.

  • Converts the logic for manifest file processing and event method generation from Python to C#.
  • Adopts Roslyn incremental generator APIs, new string interpolation with raw strings, and modern collection initialization.
Files not reviewed (5)
  • eng/python.targets: Language not supported
  • src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj: Language not supported
  • src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj: Language not supported
  • src/libraries/System.Private.CoreLib/gen/System.Private.CoreLib.Generators.csproj: Language not supported
  • src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj: Language not supported

@jkoritzinsky jkoritzinsky force-pushed the gen-runtime-event-source-csharp branch from c1d8876 to 8a2bbb0 Compare April 17, 2025 23:35
@am11
Copy link
Member

am11 commented Apr 18, 2025

Nice! genLttngProvider etc. can also be converted to src/native/minipal/UnicodeDataGenerator type of a generator with output native code checked in, as the output unicodedata.c rarely changes (and when they do,Updating-Unicode-Versions.md has steps how to update).

Copy link
Contributor

Tagging subscribers to this area: @tarekgh, @tommcdon, @pjanotti
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR converts the runtime event sources generation from a Python‐based process to a native C# source generator, eliminating the direct Python dependency in our managed build.

  • Removed Python-based eventing file generation targets and related imports.
  • Added a new C# source generator (NativeRuntimeEventSourceGenerator.cs) and updated project files to use AdditionalFiles for event manifest inclusion.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj Removed Python-based generation targets and replaced them with an AdditionalFiles group for event manifest inclusion when FeaturePerfTracing is enabled.
src/libraries/System.Private.CoreLib/gen/System.Private.CoreLib.Generators.csproj Added a new source generator and marked the project as a Roslyn component.
src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj Eliminated Python-based targets and added AdditionalFiles entries for manifest and inclusion list files.
src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj Similar removal of Python-generation logic with an AdditionalFiles group addition.
eng/python.targets Removed entire Python target definitions as they are no longer needed.
Directory.Build.targets Removed the import of python.targets to reflect the new build configuration.
Comments suppressed due to low confidence (1)

src/libraries/System.Private.CoreLib/gen/System.Private.CoreLib.Generators.csproj:17

  • Ensure that the new source generator 'NativeRuntimeEventSourceGenerator.cs' is accompanied by comprehensive tests to verify its output across different build scenarios.
<Compile Include="NativeRuntimeEventSourceGenerator.cs" />

Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What kind of testing do we have in place to validate this is producing the same output as the previous script was?

@jkoritzinsky
Copy link
Member Author

I locally validated of the results of both the scripts to ensure they were byte-for-byte identical.

@jkoritzinsky jkoritzinsky enabled auto-merge (squash) May 28, 2025 22:29
@jkoritzinsky
Copy link
Member Author

/ba-g failures are unrelated

@jkoritzinsky jkoritzinsky merged commit 4b868d2 into dotnet:main May 28, 2025
145 of 150 checks passed
@jkoritzinsky jkoritzinsky deleted the gen-runtime-event-source-csharp branch May 28, 2025 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants