Skip to content

[WASI][Mono] Enable Mono AOT on WASI in runtime-wasm CI leg#129098

Open
pavelsavara wants to merge 6 commits into
dotnet:mainfrom
pavelsavara:wasi-mono-aot
Open

[WASI][Mono] Enable Mono AOT on WASI in runtime-wasm CI leg#129098
pavelsavara wants to merge 6 commits into
dotnet:mainfrom
pavelsavara:wasi-mono-aot

Conversation

@pavelsavara
Copy link
Copy Markdown
Member

@pavelsavara pavelsavara commented Jun 7, 2026

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:

Runtime critical type System.Runtime.Loader.AssemblyLoadContext not found

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 that
early phase falls back to the managed AssemblyLoadContext resolving event,
which needs corlib metadata that isn't initialized yet — a reentrancy that
aborts startup.

Changes

Runtime

  • src/mono/wasi/runtime/driver.c — Set
    mono_opt_aot_lazy_assembly_load = 1 in mono_wasm_load_runtime. This loads
    assemblies 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 the
    BrowserWasmApp.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
    • Set RunWasmSamples=false for the WASI smoke and AOT legs.
    • Run smoke-only on the WASI AOT leg (shouldRunSmokeOnly: true).
  • eng/pipelines/runtime-wasm.yml — Add excludeOptional: false so the
    WASM-only pipeline runs the WASI legs.

Platform detection & test gating

  • PlatformDetection.csIsBuiltWithAggressiveTrimming now includes
    IsWasi. WASI apps always build with TrimMode=full, but the non-AOT
    LibraryTests leg did not embed the substitution that flips this flag, so it
    reported false. Using IsWasi (not IsWasm) keeps Browser non-AOT
    untrimmed.
  • NumberFormatInfoTests.csFullICUPlatform now uses
    !PlatformDetection.IsWasm instead of IsNotBrowser, so the WASI target
    (which also lacks full ICU) is excluded.
  • DataContractJsonSerializer.cs / DataContractSerializer.cs — Gate the
    FileStreamSurrogate tests with
    [SkipOnPlatform(TestPlatforms.Wasi, ...)]. /tmp is not preopened in the
    wasmtime --dir . sandbox, so TempFile.Create() cannot create temp files.

Cleanup

  • Remove the unused src/mono/sample/wasi/jco sample (Program.cs, csproj,
    main.mjs, package.json, package-lock.json, .npmrc).

@pavelsavara pavelsavara added this to the 11.0.0 milestone Jun 7, 2026
@pavelsavara pavelsavara self-assigned this Jun 7, 2026
Copilot AI review requested due to automatic review settings June 7, 2026 16:02
@pavelsavara pavelsavara added arch-wasm WebAssembly architecture area-Build-mono os-wasi Related to WASI variant of arch-wasm labels Jun 7, 2026
@pavelsavara
Copy link
Copy Markdown
Member Author

/azp run runtime-wasm

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

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

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=true setting for WASI in browser/WASM test targets.
  • Configure the runtime-wasm pipeline wrapper to include optional jobs by setting excludeOptional: 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.

Comment thread src/mono/wasi/runtime/driver.c
@pavelsavara
Copy link
Copy Markdown
Member Author

/azp run runtime-wasm

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Copilot AI review requested due to automatic review settings June 8, 2026 08:35
@pavelsavara
Copy link
Copy Markdown
Member Author

/azp run runtime-wasm

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

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 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 pavelsavara changed the title [mono][wasi] More testing [WASI][Mono] Enable Mono AOT on WASI in runtime-wasm CI leg Jun 8, 2026
@pavelsavara pavelsavara marked this pull request as ready for review June 8, 2026 08:53
@pavelsavara
Copy link
Copy Markdown
Member Author

/azp run runtime-wasm

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-Build-mono os-wasi Related to WASI variant of arch-wasm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants