Skip to content

Build wasm JIT and crossgen2 R2R of System.Private.CoreLib for browser target#127935

Merged
davidwrighton merged 5 commits into
dotnet:mainfrom
davidwrighton:Build_CrossGen_andR2R_SPC
May 13, 2026
Merged

Build wasm JIT and crossgen2 R2R of System.Private.CoreLib for browser target#127935
davidwrighton merged 5 commits into
dotnet:mainfrom
davidwrighton:Build_CrossGen_andR2R_SPC

Conversation

@davidwrighton
Copy link
Copy Markdown
Member

Note

This PR was created with assistance from GitHub Copilot.

Enable build.cmd clr+libs -os browser to:

  1. Build clrjit_universal_wasm_x64 (the wasm-targeting JIT for the host platform)
  2. Build crossgen2 that can use the wasm JIT
  3. Run crossgen2 on System.Private.CoreLib to produce a .wasm R2R output

Changes

  • eng/Subsets.props: Remove wasm exclusion from _BuildAnyCrossArch; use ClrWasmJitSubset for wasm targets
  • src/coreclr/CMakeLists.txt: Early-return for wasm cross-component builds (only configure JIT + dependencies)
  • src/coreclr/jit/CMakeLists.txt: Create clrjit_universal_wasm_* when target=wasm
  • src/coreclr/gcinfo/CMakeLists.txt: Create gcinfo_universal_wasm library
  • src/coreclr/crossgen-corelib.proj: Enable crossgen2 for browser with --obj-format:wasm and --codegenopt:JitWasmNyiToR2RUnsupported=1; output as System.Private.CoreLib.NotReadyYet.wasm
  • eng/native/configureplatform.cmake: Guard emscripten link/compile options from cross-component builds
  • src/coreclr/jit/compiler.cpp & codegenwasm.cpp: Add missing #ifdef PROFILING_SUPPORTED guards
  • src/coreclr/utilcode/CMakeLists.txt: Guard natvis for wasm target
  • src/coreclr/tools/aot/crossgen2/crossgen2.props: Allow jitinterface pickup for wasm when CrossHostArch is set

…r target

Enable 'build.cmd clr+libs -os browser' to:
1. Build clrjit_universal_wasm_x64 (the wasm-targeting JIT for the host platform)
2. Build crossgen2 that can use the wasm JIT
3. Run crossgen2 on System.Private.CoreLib to produce a .wasm R2R output

Key changes:
- eng/Subsets.props: Remove wasm exclusion from cross-arch build; use ClrWasmJitSubset
- src/coreclr/CMakeLists.txt: Early-return for wasm cross-component (only JIT+deps)
- src/coreclr/jit/CMakeLists.txt: Create clrjit_universal_wasm_* target
- src/coreclr/gcinfo/CMakeLists.txt: Create gcinfo_universal_wasm library
- src/coreclr/crossgen-corelib.proj: Enable crossgen2 for browser with wasm format
- eng/native/configureplatform.cmake: Guard emscripten flags from cross-component builds
- Fix missing PROFILING_SUPPORTED guards in JIT wasm codegen

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 7, 2026 23:38
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label May 7, 2026
@davidwrighton davidwrighton requested a review from agocke May 7, 2026 23:38
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
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 updates the CoreCLR build and crossgen plumbing to enable a browser/wasm-targeting “cross-components” build that produces a wasm-targeting standalone JIT (clrjit_universal_wasm_*), builds a crossgen2 that can consume that JIT, and runs crossgen2 over System.Private.CoreLib to emit a wasm object/container output.

Changes:

  • Enable building the wasm-targeting standalone JIT and its gcinfo dependency under wasm targeting.
  • Adjust subset/build logic so wasm targets build only the needed cross-component pieces (wasm JIT subset) rather than all cross-arch JITs.
  • Enable browser corelib crossgen2 invocation with --obj-format:wasm and a wasm-specific codegen option; tighten a few wasm/cross-component guards (profiling, natvis, emscripten flags).

Reviewed changes

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

Show a summary per file
File Description
eng/Subsets.props Enables cross-component builds for wasm targets and selects ClrWasmJitSubset instead of ClrAllJitsSubset when targeting wasm.
eng/native/configureplatform.cmake Avoids applying emscripten-specific compile/link flags to cross-component builds.
src/coreclr/CMakeLists.txt Adds an early-return path for wasm cross-components builds and ensures jitinterface is configured for browser when cross-component building.
src/coreclr/crossgen-corelib.proj Enables browser crossgen2 with wasm obj-format and a wasm-specific codegen opt; sets wasm output path.
src/coreclr/gcinfo/CMakeLists.txt Adds gcinfo_universal_wasm library creation for wasm-targeting builds.
src/coreclr/jit/CMakeLists.txt Creates clrjit_universal_wasm_${ARCH_HOST_NAME} when targeting wasm.
src/coreclr/jit/compiler.cpp Guards verbose printing of profiler-hook state behind PROFILING_SUPPORTED.
src/coreclr/jit/codegenwasm.cpp Guards genProfilingLeaveCallback definition behind PROFILING_SUPPORTED.
src/coreclr/tools/aot/crossgen2/crossgen2.props Allows shipping/picking up jitinterface content for wasm scenarios when CrossHostArch is set.
src/coreclr/utilcode/CMakeLists.txt Skips linking natvis into utilcode_dac when targeting wasm (where that target isn’t built).

Comment thread src/coreclr/CMakeLists.txt
davidwrighton and others added 2 commits May 11, 2026 10:42
The wasm cross-component build (host=x64, target=wasm) produces
libclrjit_universal_wasm_x64.so for crossgen2. Several CMake files
used CLR_CMAKE_TARGET_ARCH_WASM where CLR_CMAKE_HOST_ARCH_WASM is
correct, since the PAL and minipal code runs on the host, not the
target.

Changes:
- pal/src/CMakeLists.txt: Use HOST_ARCH_WASM for libunwind, arch
  source selection, and multithreading guards.
- clrfeatures.cmake: Disable FEATURE_EVENT_TRACE and
  FEATURE_EVENTSOURCE_XPLAT for wasm cross-builds (not needed for
  crossgen2, and eventing dependencies are unavailable).
- CMakeLists.txt: Add build_resources(), nativeresources, and
  dlls/mscorrc to the wasm cross-build early-return block so the
  JIT can link mscorrc and coreclrpal.
- native/minipal/CMakeLists.txt: Include ospagesize.c in cross-builds
  where host is not wasm (the POSIX implementation is needed on x64).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use setBBProfileWeight(BB_ZERO_WEIGHT) instead of bbSetRunRarely()
for the switch and rethrow blocks created by the wasm EH pass.
bbSetRunRarely() only scales the weight to zero without setting the
BBF_PROF_WEIGHT flag, which causes a checked build assertion when
PGO data (.mibc) is applied.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread src/coreclr/jit/fgwasm.cpp Outdated
NYI_WASM was always fatal in release builds because:
1. The JitWasmNyiToR2RUnsupported config was CONFIG_INTEGER (debug-only)
2. The NYI_WASM macro had an #if DEBUG guard that fell back to NYIRAW

Change CONFIG_INTEGER to RELEASE_CONFIG_INTEGER and remove the #if
DEBUG split so NYI_WASM can gracefully skip unsupported methods via
implReadyToRunUnsupported() in all build configurations.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 11, 2026 20:12
@davidwrighton davidwrighton requested a review from AndyAyersMS May 11, 2026 20:22
Copy link
Copy Markdown
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

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

Comment thread src/coreclr/jit/fgwasm.cpp Outdated
Comment thread src/coreclr/pal/src/CMakeLists.txt
Address review feedback: use inheritWeightPercentage(regionEntryBlock, 0)
instead of setBBProfileWeight(BB_ZERO_WEIGHT). This properly propagates
the BBF_PROF_WEIGHT flag from the source block and handles both PGO and
non-PGO cases correctly.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@kg
Copy link
Copy Markdown
Member

kg commented May 12, 2026

JIT changes LGTM but I don't know the build system well enough to greencheck the build parts

Comment thread src/coreclr/pal/src/CMakeLists.txt
Copy link
Copy Markdown
Member

@agocke agocke left a comment

Choose a reason for hiding this comment

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

LGTM although I'm not sure that there's a circumstance where we could ever be running CMake with wasm as the host target

@davidwrighton davidwrighton merged commit a7cda92 into dotnet:main May 13, 2026
207 checks passed
davidwrighton added a commit that referenced this pull request May 14, 2026
- Add --help output for `--obj-format` switch to crossgen2.
- Minor tweak to R2RTest, if anyone is still using that
- Add support for the detail that R2R on wasm targets produces .wasm
files instead of .dll files
- When tests are built with RuntimeFlavor=coreclr, then they will
default to setting RunWithNodeJS to true
- Copy crossgen2 from a cross-build directory on Wasm
- Enable bash and batch precommands when building wasm tests
  - Disable a few tests that had problematic precommands for testing
  
When this PR and PR #127935 are merged, it will be straightforward
enough to run tests.

The process will be something like:
```
Commands to run tests, starting from a fresh build

; Build runtime+libs
./build.sh clr+libs -rc debug -c release -os browser
; Build TestRoot
./src/tests/build.sh skipmanaged browser
; Build test project from the test tree
./dotnet.sh /p:TargetArchitecture=wasm /p:TargetOS=browser /p:RuntimeFlavor=coreclr src/tests/GC/API/GCSettings/InducedGen0GC.csproj

export CORE_ROOT=/home/davidwr/git/runtime/artifacts/tests/coreclr/browser.wasm.Debug/Tests/Core_Root
export RunCrossGen2=1
/home/davidwr/git/runtime/artifacts/tests/coreclr/browser.wasm.Debug/GC/API/GCSettings/InducedGen0GC/InducedGen0GC.sh
```

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants