-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Add streamlined CoreCLR WebAssembly documentation with essential build and debug workflows #119104
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
AaronRobinsonMSFT
merged 11 commits into
main
from
copilot/fix-a6cf036d-78cb-4dd0-ab7e-ded31276babc
Aug 28, 2025
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c815681
Initial plan
Copilot f6d52bb
Add CoreCLR WebAssembly documentation and update main README
Copilot 8ff8097
Update CoreCLR WebAssembly documentation with latest workflow improve…
Copilot ec5981f
Apply review feedback: update build commands, remove manual testing s…
Copilot a418782
Add dotnet-serve GitHub link as requested in review feedback
Copilot 2ce0382
Apply suggestions from code review
AaronRobinsonMSFT e67bc97
Update docs/workflow/building/coreclr/wasm.md
AaronRobinsonMSFT 3b8eb3c
Update docs/workflow/building/coreclr/wasm.md
AaronRobinsonMSFT b28c4bb
Update docs/workflow/building/coreclr/wasm.md
AaronRobinsonMSFT 3e8a5bf
Update wasm.md
AaronRobinsonMSFT 918b95c
Refine WebAssembly debugging options in VS Code
AaronRobinsonMSFT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| # Building CoreCLR for WebAssembly | ||
|
|
||
| This guide provides instructions for building, running, and debugging CoreCLR on WebAssembly (WASM). This is experimental support and is currently under active development. | ||
|
|
||
| ## Table of Contents | ||
|
|
||
| - [Prerequisites](#prerequisites) | ||
| - [Building CoreCLR for WebAssembly](#building-coreclr-for-webassembly) | ||
| - [Testing the Runtime](#testing-the-runtime) | ||
| - [Debugging](#debugging) | ||
| - [Chrome DevTools with DWARF Support](#chrome-devtools-with-dwarf-support) | ||
| - [VS Code WebAssembly Debugging](#vs-code-webassembly-debugging) | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| Make sure you've prepared your environment and installed all the requirements for your platform. If not, follow this [link](/docs/workflow/README.md#introduction) for the corresponding instructions. | ||
|
|
||
| ## Building CoreCLR for WebAssembly | ||
|
|
||
| To build the CoreCLR runtime for WebAssembly, use the following command from the repository root: | ||
|
|
||
| **Linux/macOS:** | ||
| ```bash | ||
| ./build.sh -os browser -c Debug -subset clr.runtime | ||
| ``` | ||
|
|
||
| **Windows:** | ||
| ```cmd | ||
| .\build.cmd -os browser -c Debug -subset clr.runtime | ||
| ``` | ||
|
|
||
| This command will: | ||
| - Install the Emscripten SDK (emsdk) automatically | ||
| - Build the CoreCLR runtime for WebAssembly | ||
| - Build the required libraries | ||
|
|
||
| **Note:** The first build may take longer as it downloads and sets up the Emscripten toolchain. | ||
|
|
||
| ## Testing the Runtime | ||
|
|
||
| ### Browser Testing (Recommended) | ||
|
|
||
| If you don't have `dotnet-serve` installed, you can install it as a global .NET tool with: | ||
|
|
||
| ```bash | ||
| dotnet tool install --global dotnet-serve | ||
| ``` | ||
|
|
||
| **Linux/macOS:** | ||
| ```bash | ||
| dotnet-serve --directory "artifacts/bin/coreclr/browser.wasm.Debug/corewasmrun" | ||
| ``` | ||
|
|
||
| **Windows:** | ||
| ```cmd | ||
| dotnet-serve --directory "artifacts\bin\coreclr\browser.wasm.Debug\corewasmrun" | ||
| ``` | ||
|
|
||
| This will start a local HTTP server and you can open the provided URL in your browser. | ||
|
|
||
| ### Console Testing | ||
|
|
||
| You can also run the runtime directly in Node.js: | ||
|
|
||
| ```bash | ||
| cd artifacts/bin/coreclr/browser.wasm.Debug/corewasmrun/ | ||
| node corewasmrun.js | ||
| ``` | ||
|
|
||
| ## Debugging | ||
|
|
||
| ### Chrome DevTools with DWARF Support | ||
|
|
||
| For debugging CoreCLR WebAssembly code, the recommended approach is using Chrome browser with the **C/C++ DevTools Support (DWARF)** extension: | ||
|
|
||
| 1. **Install the Chrome extension:** | ||
| - [C/C++ DevTools Support (DWARF)](https://chrome.google.com/webstore/detail/cc-devtools-support-dwar/odljcjlcidgdhcjhoijagojpnjcgocgd) | ||
|
|
||
| 2. **Open Chrome DevTools** (F12) while running your WebAssembly application | ||
|
|
||
| 3. **Set breakpoints** in the Sources tab: | ||
| - Navigate to the WebAssembly modules | ||
| - You can step through C code, set breakpoints, and inspect WebAssembly linear memory | ||
| - The extension provides source-level debugging with DWARF debug information | ||
|
|
||
| **Note:** The debugging experience is not perfect but works most of the time. You can step through C code, set breakpoints, and inspect the WebAssembly linear memory. | ||
|
|
||
| ### VS Code WebAssembly Debugging | ||
|
|
||
| VS Code, through Node.js, provides a good debugging option for WebAssembly CoreCLR: | ||
|
|
||
| 1. **Install the VS Code extension (Optional):** | ||
| - [WebAssembly Dwarf Debugging](https://marketplace.visualstudio.com/items?itemName=ms-vscode.wasm-dwarf-debugging) | ||
|
|
||
| 2. **Create a launch.json configuration:** | ||
| ```json | ||
| { | ||
| "version": "0.2.0", | ||
| "configurations": [ | ||
| { | ||
| "type": "node", | ||
| "request": "launch", | ||
| "name": "corewasmrun", | ||
| "skipFiles": [ | ||
| "<node_internals>/**" | ||
| ], | ||
| "program": "corewasmrun.js", | ||
| "cwd": "${workspaceFolder}/artifacts/bin/coreclr/browser.wasm.Debug/corewasmrun/" | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| 3. **Set breakpoints** in `corewasmrun.js` in one of the `put_char` functions (the `stdout`/`stderr` implementation) | ||
|
|
||
| 4. **Start debugging** and step through the WebAssembly code using the call stack | ||
|
|
||
| This approach allows you to debug the JavaScript host and step into WebAssembly code or into the C/C++ code if the Dwarf Debugging extension was installed. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.