Skip to content

[browser][coreCLR] browserhost to load R2R#129634

Draft
pavelsavara wants to merge 7 commits into
dotnet:mainfrom
pavelsavara:browsehost_load_r2r
Draft

[browser][coreCLR] browserhost to load R2R#129634
pavelsavara wants to merge 7 commits into
dotnet:mainfrom
pavelsavara:browsehost_load_r2r

Conversation

@pavelsavara

Copy link
Copy Markdown
Member

No description provided.

@pavelsavara pavelsavara added this to the 11.0.0 milestone Jun 19, 2026
@pavelsavara pavelsavara self-assigned this Jun 19, 2026
Copilot AI review requested due to automatic review settings June 19, 2026 19:59
@pavelsavara pavelsavara added arch-wasm WebAssembly architecture area-Host os-browser Browser variant of arch-wasm labels Jun 19, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 extends the WebAssembly build/publish pipeline to support ReadyToRun (R2R) “webcil-in-wasm” assemblies by staging prebuilt R2R .wasm images, emitting webcil payload/table sizing into the boot config, and updating the JS loader/host to instantiate webcil modules using those sizes (enabling streaming instantiation and avoiding runtime-side wasm parsing).

Changes:

  • Add an MSBuild path to crossgen selected assemblies to R2R webcil-in-wasm and feed those artifacts into webcil conversion/staging.
  • Emit payloadSize (and tableSize for R2R) into the boot config assets so the loader can instantiate without calling getWebcilSize / parsing wasm.
  • Update the JS loader/host surface and typings to pass these sizes through to instantiateWebcilModule.

Reviewed changes

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

Show a summary per file
File Description
src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs Plumbs webcil size metadata into boot config generation and passes it to asset transformation.
src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ConvertDllsToWebCil.cs Adds optional staging of prebuilt R2R .wasm replacements and emits a WebcilSizes output by parsing wasm.
src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/BootJsonData.cs Extends boot asset schema with tableSize/payloadSize fields.
src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/BootJsonBuilderHelper.cs Writes payloadSize/tableSize onto boot assets during resources→assets transformation.
src/native/libs/Common/JavaScript/types/public-api.ts Exposes tableSize/payloadSize on AssemblyAsset in public TS types.
src/native/libs/Common/JavaScript/types/internal.ts Adds internal asset fields for tableSize/payloadSize.
src/native/libs/Common/JavaScript/types/ems-ambient.ts Extends ambient emscripten symbol typing for wasm exports needed by R2R webcil imports.
src/native/libs/Common/JavaScript/loader/dotnet.d.ts Updates loader .d.ts for AssemblyAsset to include tableSize/payloadSize.
src/native/libs/Common/JavaScript/loader/assets.ts Passes tableSize/payloadSize to browser-host instantiateWebcilModule.
src/native/libs/Common/JavaScript/host/assets.ts Reworks instantiateWebcilModule to allocate payload and instantiate webcil wasm (streaming when possible) using boot-config sizes.
src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets Wires R2R candidates into ConvertDllsToWebcil, propagates WebcilSizes, and adds a _WasmCrossgenReadyToRunAssemblies target.
src/mono/browser/build/WasmApp.InTree.props Defines in-tree crossgen2/jit/reference paths consumed by the new R2R target.
src/mono/sample/wasm/browser-R2R/Wasm.Browser.R2R.csproj Adds a new sample that opts its app assembly into R2R cross-compilation.
src/mono/sample/wasm/browser-R2R/Program.cs Sample app entrypoint.
src/mono/sample/wasm/browser-R2R/wwwroot/index.html Sample web page host.
src/mono/sample/wasm/browser-R2R/wwwroot/main.js Sample boot/run script using dotnet.js.

Comment thread src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ConvertDllsToWebCil.cs Outdated
Comment thread src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ConvertDllsToWebCil.cs Outdated
Comment thread src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs Outdated
Comment thread src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/BootJsonData.cs
Comment thread src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ConvertDllsToWebCil.cs Outdated
Comment thread src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ConvertDllsToWebCil.cs Outdated
Comment thread src/native/libs/Common/JavaScript/types/public-api.ts
Copilot AI review requested due to automatic review settings June 20, 2026 10:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 18 out of 19 changed files in this pull request and generated 5 comments.

Comment on lines +258 to +265
// Key by the logical assembly name (".dll"), not the produced ".wasm" file name: the boot
// config lists webcil assemblies under their logical ".dll" name, and GenerateWasmBootJson
// looks these sizes up by that name (resourceName). Using ".wasm" here would never match.
// Keying by ".dll" also avoids colliding with same-stem assets (e.g. a "X.pdb" never matches
// "X.dll").
string fileName = Path.ChangeExtension(Path.GetFileName(webcilPath), ".dll");
string key = string.IsNullOrEmpty(culture) ? fileName : culture + "/" + fileName;
var item = new TaskItem(key);
Comment on lines +49 to +55
export async function instantiateWebcilModule(webcilPromise: Promise<Response>, memory: WebAssembly.Memory, virtualPath: string, tableSize?: number, payloadSize?: number): Promise<void> {
// The boot config carries payloadSize for every webcil asset (and tableSize for R2R images), so
// the loader never buffers the bytes, parses the data section or calls getWebcilSize. Assets
// without a tableSize are plain (Webcil wrapper version 0) images.
if (typeof payloadSize !== "number" || payloadSize === 0) {
throw new Error(`Webcil asset '${virtualPath}' is missing payloadSize in the boot config.`);
}
Comment on lines +424 to +433
<ConvertDllsToWebcil
Candidates="@(_WasmDllBuildCandidates)"
IntermediateOutputPath="$(_WasmBuildTmpWebcilPath)"
OutputPath="$(_WasmBuildWebcilPath)"
IsEnabled="$(_WasmEnableWebcil)"
WebcilVersion="$(_WasmWebcilVersion)"
R2RWebcilCandidates="@(WasmR2RWebcilCandidate)">
<Output TaskParameter="FileWrites" ItemName="FileWrites" />
<Output TaskParameter="FileWrites" ItemName="_WasmConvertedWebcilOutputs" />
<Output TaskParameter="WebcilSizes" ItemName="_WasmWebcilSizes" />
Comment on lines +89 to +94
/// <summary>
/// Payload/table sizes for each webcil (keyed by the logical assembly name, e.g. "App.dll"),
/// produced by ConvertDllsToWebcil. Emitted into the boot config so the runtime loader doesn't
/// parse the wasm or call getWebcilSize.
/// </summary>
public ITaskItem[] WebcilSizes { get; set; }
Comment on lines +40 to +47
/// <summary>
/// Payload/table sizes for each produced webcil, keyed by the logical assembly name as it
/// appears in the boot config: the file name (e.g. "System.Console.dll"), or
/// "{culture}/{name}.dll" for satellite assemblies so that same-named satellites in different
/// cultures don't collide. Lets the boot config carry the sizes so the runtime loader doesn't
/// buffer/parse the wasm. PayloadSize is set for every webcil; TableSize is non-zero only for
/// R2R images.
/// </summary>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-Host os-browser Browser variant of arch-wasm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants