Build wasm JIT and crossgen2 R2R of System.Private.CoreLib for browser target#127935
Conversation
…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>
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
There was a problem hiding this comment.
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:wasmand 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). |
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>
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>
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>
|
JIT changes LGTM but I don't know the build system well enough to greencheck the build parts |
agocke
left a comment
There was a problem hiding this comment.
LGTM although I'm not sure that there's a circumstance where we could ever be running CMake with wasm as the host target
- 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>
Note
This PR was created with assistance from GitHub Copilot.
Enable
build.cmd clr+libs -os browserto:clrjit_universal_wasm_x64(the wasm-targeting JIT for the host platform)Changes
_BuildAnyCrossArch; useClrWasmJitSubsetfor wasm targetsclrjit_universal_wasm_*when target=wasmgcinfo_universal_wasmlibrary--obj-format:wasmand--codegenopt:JitWasmNyiToR2RUnsupported=1; output asSystem.Private.CoreLib.NotReadyYet.wasm#ifdef PROFILING_SUPPORTEDguards