Skip to content

Conversation

@radekdoulik
Copy link
Member

@radekdoulik radekdoulik commented Nov 10, 2025

Port of the generator task to the CoreCLR.

It can be now used to update wasm callhelpers manually. Example usage:

./dotnet.sh build /t:RunGenerator /p:GeneratorOutputPath="./" /p:AssembliesScanPath="<your-path-to-assemblies>" src/tasks/WasmAppBuilder/WasmAppBuilder.csproj

The call helper files are split to 2 files, similar as on Mono. The pinvoke/reverse parts of the generator will be updated in the followup PR.

Contributes to #113692

It can be now used to update wasm callhelpers manually. Example usage:

    ./dotnet.sh build /t:RunGenerator /p:GeneratorOutputPath="./" /p:AssembliesScanPath="<your-path-to-assemblies>" src/tasks/WasmAppBuilder/WasmAppBuilder.csproj

The call helper files are split to 2 files, similar as on mono. The
pinvoke/reverse parts of the generator will be updated in the
followup PR.
Copilot AI review requested due to automatic review settings November 10, 2025 11:33
@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Nov 10, 2025
@radekdoulik radekdoulik added area-VM-coreclr and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Nov 10, 2025
@radekdoulik radekdoulik added this to the Future milestone Nov 10, 2025
@radekdoulik radekdoulik requested review from AaronRobinsonMSFT, jkotas, maraf and pavelsavara and removed request for maraf November 10, 2025 11:34
Copy link
Contributor

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 adds managed-to-native code generation infrastructure for WebAssembly builds, implementing signature mapping and interop thunk generation for both Mono and CoreCLR runtimes.

  • Introduces new ManagedToNativeGenerator, SignatureMapper, and InterpToNativeGenerator classes to generate C++ interop code from managed assembly metadata
  • Splits the existing callhelpers.cpp into separate files for forward and reverse thunks in CoreCLR
  • Adds runtime-flavor-specific compilation support in the build system to maintain separate implementations for Mono and CoreCLR

Reviewed Changes

Copilot reviewed 7 out of 10 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/tasks/WasmAppBuilder/mono/SignatureMapper.cs Maps .NET types to WASM signature characters (uppercase) for Mono runtime
src/tasks/WasmAppBuilder/mono/ManagedToNativeGenerator.cs MSBuild task that orchestrates pinvoke and icall scanning/generation for Mono
src/tasks/WasmAppBuilder/mono/InterpToNativeGenerator.cs Generates C trampoline functions for interpreter-to-native transitions in Mono
src/tasks/WasmAppBuilder/coreclr/SignatureMapper.cs Maps .NET types to WASM signature characters (lowercase) with additional 'n' type for CoreCLR runtime
src/tasks/WasmAppBuilder/coreclr/ManagedToNativeGenerator.cs MSBuild task with temporary hardcoded signatures for CoreCLR interop generation
src/tasks/WasmAppBuilder/coreclr/InterpToNativeGenerator.cs Generates CallFunc_* helper functions for CoreCLR interpreter-to-native calls
src/tasks/WasmAppBuilder/WasmAppBuilder.csproj Adds conditional compilation to exclude runtime-specific files and defines RunGenerator target
src/coreclr/vm/wasm/callhelpers-reverse.cpp New file containing reverse thunk implementations for unmanaged-to-managed calls
src/coreclr/vm/wasm/callhelpers-interp-to-managed.cpp Generated file with signature-specific trampoline functions for interpreter transitions
src/coreclr/vm/CMakeLists.txt Updates build to reference split callhelpers files instead of single file

Co-authored-by: Copilot <[email protected]>
@radekdoulik radekdoulik requested a review from lewing November 10, 2025 12:05
@AaronRobinsonMSFT
Copy link
Member

/cc @agocke @jkoritzinsky

Remove the build logic from the task, let handle it at msbuild level
Co-authored-by: Larry Ewing <[email protected]>
@radekdoulik
Copy link
Member Author

/ba-g unrelated timeout

@radekdoulik radekdoulik merged commit e01de4e into dotnet:main Nov 18, 2025
110 of 113 checks passed
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.

6 participants