Repository navigation
Fix CoreCLR browser-wasm native relink from a packaged SDK - #131646
Conversation
The CoreCLR wasm _CoreCLRSetupEmscripten target populated EmscriptenEnvVars without EM_CACHE/EM_FROZEN_CACHE. With FROZEN_CACHE forced on by the emscripten config, emcc fell back to the empty cache dir inside the Emscripten SDK pack and failed with 'FROZEN_CACHE is set, but cache file is missing: sysroot_install.stamp'. Point EM_CACHE at WasmCachePath (the prebuilt Emscripten Cache pack), mirroring the Mono BrowserWasmApp.targets.
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
Pull request overview
Updates the CoreCLR browser-wasm native relink (native-relink) MSBuild targets to align Emscripten cache environment variable setup with the existing Mono path, ensuring emcc uses the intended cache location.
Changes:
- Add
EM_CACHEto CoreCLR’sEmscriptenEnvVarssoemccuses$(WasmCachePath)when available. - Add
EM_FROZEN_CACHEto CoreCLR’sEmscriptenEnvVars, matching the existing conditional behavior used byBrowserWasmApp.targets.
BrowserWasmApp.CoreCLR.targets force-includes \coreclr_compat.h, but the header was never added to the pack's Sdk/ folder, so CoreCLR native relink from a restored SDK failed with 'coreclr_compat.h file not found'. Add it to the PackageFile list next to the targets.
The generated managed-to-native sources include callhelpers.hpp, minipal/entrypoints.h and minipal/utils.h. These were only resolvable from the in-repo source tree or via env-var overrides, so native relink from a restored SDK failed with file-not-found. Package the three headers next to the targets (Sdk and Sdk/minipal) and make the include-dir fallbacks prefer that packaged location when present.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/mono/browser/build/BrowserWasmApp.CoreCLR.targets:497
- BrowserWasmApp.targets ensures the EM_CACHE directory exists (via a MakeDir) before invoking emcc. The CoreCLR targets now set EM_CACHE too, but never create the directory. If WasmCachePath is overridden to a non-existent location, emcc can fail when trying to use/populate the cache. Consider mirroring the MakeDir behavior here for parity and robustness.
<EmscriptenEnvVars Include="EM_CACHE=$(WasmCachePath)" Condition="'$(WasmCachePath)' != ''" />
<EmscriptenEnvVars Include="EM_FROZEN_CACHE=1" Condition="'$(WasmCachePath)' == '$(EmscriptenCacheSdkCacheDir)'" />
<EmscriptenEnvVars Include="EM_FROZEN_CACHE=0" Condition="'$(WasmCachePath)' != '' and '$(WasmCachePath)' != '$(EmscriptenCacheSdkCacheDir)'" />
Reworks the header shipping to mirror Mono: callhelpers.hpp and minipal/entrypoints.h + utils.h are installed into the CoreCLR browser-wasm runtime pack under native/include, declared in the NetCore.App platform manifest, and resolved by the targets from the runtime pack native dir. coreclr_compat.h stays in the WebAssembly.Sdk pack since it is a build-time shim next to the targets.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.
Suppressed comments (2)
src/mono/browser/build/BrowserWasmApp.CoreCLR.targets:568
- The
Exists(...)path uses backslashes (include\minipal\utils.h). On non-Windows builds MSBuild typically treats\as a literal character (not a directory separator), so this check can fail and prevent using the runtime-pack include dir even when the file is present. Use$([MSBuild]::NormalizePath(...))(or forward slashes) to build an OS-correct path forExists.
<!-- Restored SDK: headers ship in the runtime pack under native/include/minipal. -->
<_MinipalIncludeDir Condition="'$(_MinipalIncludeDir)' == '' and Exists('$(MicrosoftNetCoreAppRuntimePackRidNativeDir)include\minipal\utils.h')">$([MSBuild]::NormalizeDirectory('$(MicrosoftNetCoreAppRuntimePackRidNativeDir)', 'include', 'minipal'))</_MinipalIncludeDir>
<_MinipalIncludeDir Condition="'$(_MinipalIncludeDir)' == ''">$([MSBuild]::NormalizeDirectory('$(MSBuildThisFileDirectory)..', '..', '..', 'native', 'minipal'))</_MinipalIncludeDir>
src/mono/browser/build/BrowserWasmApp.CoreCLR.targets:573
- Same issue as above: the
Exists(...)check uses a backslash path (include\callhelpers.hpp), which can be treated as a literal on Unix/macOS and make the condition false even when the header exists in the runtime pack. Build the path via$([MSBuild]::NormalizePath(...))so this works cross-platform.
<!-- Restored SDK: callhelpers.hpp ships in the runtime pack under native/include. -->
<_VmWasmIncludeDir Condition="'$(_VmWasmIncludeDir)' == '' and Exists('$(MicrosoftNetCoreAppRuntimePackRidNativeDir)include\callhelpers.hpp')">$([MSBuild]::NormalizeDirectory('$(MicrosoftNetCoreAppRuntimePackRidNativeDir)', 'include'))</_VmWasmIncludeDir>
<_VmWasmIncludeDir Condition="'$(_VmWasmIncludeDir)' == ''">$([MSBuild]::NormalizeDirectory('$(MSBuildThisFileDirectory)..', '..', '..', 'coreclr', 'vm', 'wasm'))</_VmWasmIncludeDir>
|
Azure Pipelines: Successfully started running 4 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
|
/ba-g unrelated failure on openbsd |
| <PackageFile Include="$(BrowserProjectRoot)build\BrowserWasmApp.props" TargetPath="Sdk" /> | ||
| <PackageFile Include="$(BrowserProjectRoot)build\BrowserWasmApp.targets" TargetPath="Sdk" /> | ||
| <PackageFile Include="$(BrowserProjectRoot)build\BrowserWasmApp.CoreCLR.targets" TargetPath="Sdk" /> | ||
| <PackageFile Include="$(BrowserProjectRoot)build\coreclr_compat.h" TargetPath="Sdk" /> |
There was a problem hiding this comment.
I would expect this in the same place as callhelpers, etc
Makes CoreCLR browser-wasm native relink work from a restored/packaged SDK (e.g. the daily
wasm-toolsworkload). Found and validated end-to-end while diagnosing a failingnative-relinkbenchmark build — after these fixes the CoreCLR app builds, loads in Chrome, and produces benchmark results.Fix 1 — Set
EM_CACHEfor CoreCLR native relink_CoreCLRSetupEmscripteninBrowserWasmApp.CoreCLR.targetspopulatedEmscriptenEnvVarswithoutEM_CACHE/EM_FROZEN_CACHE. BecauseFROZEN_CACHEis forced on by the dotnet emscripten config,emccfell back to the (empty) cache dir inside the Emscripten SDK pack instead of the prebuilt sysroot that ships in the separate Emscripten Cache pack, and aborted:The Mono path (
BrowserWasmApp.targets) already sets these. Fix mirrors it, pointingEM_CACHEat$(WasmCachePath).Fix 2 — Package
coreclr_compat.hin the WebAssembly.Sdk packBrowserWasmApp.CoreCLR.targetsforce-includes$(MSBuildThisFileDirectory)coreclr_compat.h, but the header was never added to the pack'sSdk/folder, so after Fix 1 the compile failed withcoreclr_compat.h file not found. It's a build-time shim that lives next to the targets, so it's added to thePackageFilelist in the SDK pack (not a runtime artifact → not in the platform manifest).Fix 3 — Ship the VM/minipal headers in the CoreCLR runtime pack
The generated managed-to-native sources include
<callhelpers.hpp>,<minipal/entrypoints.h>and<minipal/utils.h>. These were only resolvable from the in-repo source tree or viaCORECLR_VM_WASM_INCLUDE_DIR/MINIPAL_INCLUDE_DIRoverrides, so a restored SDK failed with'callhelpers.hpp' file not found.Mirroring how Mono ships its relink headers in the runtime pack (
runtime.h/pinvoke.h/… undernative/include/wasm, declared in the platform manifest):native/include(callhelpers.hpp) andnative/include/minipal(entrypoints.h,utils.h) via the browserhostCMakeLists.txt.Microsoft.NETCore.Appplatform manifest (PlatformManifestFileEntry)._VmWasmIncludeDir/_MinipalIncludeDirfrom the runtime pack native dir ($(MicrosoftNetCoreAppRuntimePackRidNativeDir)), keeping the in-repo fallback and env-var overrides intact.Validation
Applied all edits to the restored SDK + runtime packs and ran native-relink build + measure end-to-end: the build completes, the CoreCLR wasm app loads in headless Chrome, and benchmarks run (
Measurement complete: 1/1 succeeded). Each fix individually moved the build past its corresponding error (FROZEN_CACHE →coreclr_compat.h→callhelpers.hpp→ success), with the headers resolved from the runtime packnative/include.Related: #128362