Uh oh!
There was an error while loading. Please reload this page.
[WASI][Mono] Enable Mono AOT on WASI in runtime-wasm CI leg - #129098
Conversation
pavelsavara
commented
Jun 7, 2026
/azp run runtime-wasm |
|
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
Updates the Mono WASI runtime and WASM CI/test configuration to improve coverage and avoid early startup issues when using AOT on WASI.
Changes:
- Enable lazy loading of assemblies referenced by AOT images during WASI runtime initialization to avoid early-resolution reentrancy.
- Disable the default
EventSourceSupport=truesetting for WASI in browser/WASM test targets. - Configure the
runtime-wasmpipeline wrapper to include optional jobs by settingexcludeOptional: false.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/mono/wasi/runtime/driver.c | Sets mono_opt_aot_lazy_assembly_load during WASI runtime startup (plus adds an extern declaration). |
| eng/testing/tests.browser.targets | Avoids enabling EventSourceSupport by default when TargetOS is wasi. |
| eng/pipelines/runtime-wasm.yml | Forces optional wasm jobs on by passing excludeOptional: false into the wasm job template. |
Uh oh!
There was an error while loading. Please reload this page.
pavelsavara
commented
Jun 7, 2026
/azp run runtime-wasm |
|
Azure Pipelines successfully started running 1 pipeline(s). |
pavelsavara
commented
Jun 8, 2026
/azp run runtime-wasm |
|
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 14 changed files in this pull request and generated no new comments.
Files not reviewed (1)
- src/mono/sample/wasi/jco/package-lock.json: Language not supported
Comments suppressed due to low confidence (1)
src/mono/wasi/runtime/driver.c:262
- monoeg_g_getenv() can return NULL (see main.c usage), but this code unconditionally passes the result to strcmp(). If DOTNET_SYSTEM_GLOBALIZATION_INVARIANT is unset, this will dereference NULL and crash during runtime initialization.
char* invariant_globalization = monoeg_g_getenv ("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT");
if (strcmp(invariant_globalization, "true") != 0 && strcmp(invariant_globalization, "1") != 0)
load_icu_data();
pavelsavara
commented
Jun 8, 2026
/azp run runtime-wasm |
|
Azure Pipelines successfully started running 1 pipeline(s). |
pavelsavara
commented
Jun 9, 2026
/azp run runtime-wasm |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
pavelsavara
commented
Jun 10, 2026
/ba-g unrelated issues |
Uh oh!
There was an error while loading. Please reload this page.
Summary
This change enables Mono AOT for the WASI target and fixes the test
infrastructure and test gating that the AOT-trimmed WASI builds need.
The core runtime fix is a single line in the WASI driver that defers eager
assembly loading from AOT images. The remaining changes adapt the build
pipelines, AOT test build flow, and platform-detection / test gating so the
trimmed WASI test legs pass.
Motivation
Mono AOT on WASI previously aborted during startup with:
On WASI, assemblies are resolved through filesystem probing, which is not yet
available while corlib itself is being set up. Eagerly loading the assemblies
referenced by corlib's AOT image (e.g.
System.Security.Claims) during thatearly phase falls back to the managed
AssemblyLoadContextresolving event,which needs corlib metadata that isn't initialized yet — a reentrancy that
aborts startup.
Changes
Runtime
src/mono/wasi/runtime/driver.c— Setmono_opt_aot_lazy_assembly_load = 1inmono_wasm_load_runtime. This loadsassemblies referenced by AOT images lazily (when actually needed) instead of
eagerly, avoiding the early-startup reentrancy described above. A comment
documents the rationale.
Build / test infrastructure
eng/testing/tests.wasm.targets— Skip importing theBrowserWasmApp.targets-based local AOT proxy logic on WASI(
'$(TargetOS)' != 'wasi'), since WASI uses its own AOT build flow.eng/pipelines/extra-platforms/runtime-extra-platforms-wasm.yml—RunWasmSamples=falsefor the WASI smoke and AOT legs.shouldRunSmokeOnly: true).eng/pipelines/runtime-wasm.yml— AddexcludeOptional: falseso theWASM-only pipeline runs the WASI legs.
Platform detection & test gating
PlatformDetection.cs—IsBuiltWithAggressiveTrimmingnow includesIsWasi. WASI apps always build withTrimMode=full, but the non-AOTLibraryTestsleg did not embed the substitution that flips this flag, so itreported
false. UsingIsWasi(notIsWasm) keeps Browser non-AOTuntrimmed.
NumberFormatInfoTests.cs—FullICUPlatformnow uses!PlatformDetection.IsWasminstead ofIsNotBrowser, so the WASI target(which also lacks full ICU) is excluded.
DataContractJsonSerializer.cs/DataContractSerializer.cs— Gate theFileStreamSurrogatetests with[SkipOnPlatform(TestPlatforms.Wasi, ...)]./tmpis not preopened in thewasmtime --dir .sandbox, soTempFile.Create()cannot create temp files.Cleanup
src/mono/sample/wasi/jcosample (Program.cs, csproj,main.mjs, package.json, package-lock.json,
.npmrc).