[wasi] Use the <entry>.r2r.wasm composite owner name on WASI - #134874
Merged
Merged
Conversation
Drop the WASI TargetOS special case in PrepareForReadyToRunCompilation so WASI composite publishing gets the same <entry>.r2r.wasm owner name the ReadyToRun tasks give browser. The composite's own file name (the owner every component stub records) is now the single authority. The WASI targets take the composite path from the planned composite compilation instead of assuming a name, and the composer writes that file name into a host-owned buffer through an active data segment in its shim. The probe answers only to the recorded name, so an uncomposed host serves no composite and a prebuilt host (such as the runtime-test corerun) can be composed with a composite of any name. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
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. |
Contributor
|
Tagging subscribers to this area: @dotnet/crossgen-contrib |
Member
Author
|
@maraf ptal |
Contributor
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
lewing
marked this pull request as draft
September 29, 2026 19:17
lewing
marked this pull request as ready for review
September 29, 2026 19:18
Member
Author
|
This is very much open to discussion, I was just looking at doing less special casing in the targets |
Member
|
I'm in favor of naming the binary after the project/application |
maraf
approved these changes
Oct 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
CoreCLR WASI composite ReadyToRun currently names the composite owner image
composite-r2r.wasm.PrepareForReadyToRunCompilationin Crossgen2Tasks forces that name wheneverCrossgen2ToolTargetOS iswasi. The browser composite work in #134618 uses the task's default name instead:<entry>.r2r.wasm, the main assembly name with.r2r.wasm.This PR drops the TargetOS special case so WASI gets the same owner name as browser. It lands ahead of the dotnet/sdk#56395 port, so that PR doesn't carry the WASI rule into the SDK.
The two delivery models stay different on purpose. Browser instantiates the composite at runtime through the JS loader. WASI composes it offline into the host with
wasm-merge/wasm-opt. Only the naming contract changes.Design
The composite's own file name, as written by crossgen2, is the single authority. It is also the owner name every component stub records.
PrepareForReadyToRunCompilation: thewasibranch is removed. A wasm composite owner is now<entry>.r2r.wasmon both targets.WasiApp.CoreCLR.targets: the composite path now comes from the planned composite compilation,@(_ReadyToRunCompileList)withCreateCompositeImage=true, via%(OutputR2RImage). The build errors unless there is exactly one composite compilation. Because the path isn't hardcoded, WASI keeps working with either SDK naming.wasi_r2r_probe.hpp: the host reserves a 256-byte composite name buffer, zero-initialized, and exports its address and capacity (wasi_r2r_composite_name_base,wasi_r2r_composite_name_cap). The probe serves the composite only when the requested name matches the recorded name, and only if that name is non-empty. An uncomposed host therefore serves no composite. There is no wildcard matching and no name compiled into C++.ComposeWasiReadyToRun: the composer reads the two new exports and checks that the name is non-empty, contains no NUL, and fits the buffer. Its shim now importswebcil.memoryand includes an active data segment that writesPath.GetFileName(CompositePath), NUL-terminated, into the host buffer. This is the same mechanism that already installs the payload. A prebuilt host, such as the runtime-test corerun, can therefore be composed with a composite of any name.docs/design/mono/webcil.mdanddocs/workflow/building/coreclr/wasi-r2r.md.Validation
./build.sh clr+libs+host+packs -os wasi -arch wasm -c Releasefinished with 0 warnings and 0 errors../dotnet.sh publish src/mono/sample/wasi/console/Wasi.Console.Sample.csproj -c Release -p:TargetOS=wasi -p:TargetArchitecture=wasm -p:RuntimeFlavor=CoreCLR -p:PublishReadyToRun=truesucceeded. The composer loggedcomposite='Wasi.Console.Sample.r2r.wasm'.DOTNET_ReadyToRunLogFileset. It exited 0, and the log showsReady to Run initialized successfullyfor System.Private.CoreLib, Wasi.Console.Sample, System.Runtime, System.Console, System.Threading and System.Runtime.InteropServices.Wrong.r2r.wasm. Startup then traps inEEStartupbecause CoreLib's owner composite isn't served. A name mismatch fails loudly rather than silently interpreting.Ready to Run header not found.ReadyToRunTests. The removed code only executed when TargetOS waswasi, and the browser naming path is unchanged.Interaction with #134813
This PR merges cleanly with #134813's head (checked with
git merge-tree); it doesn't depend on #134813. The runtime-test harness in #134813 passes the samecomposite-r2r.wasmpath to both crossgen2 andWasiR2RComposer.proj. The composer records that name in the shared corerun, so the harness needs no changes. I did not build or run the runtime tests with both PRs merged.Follow-up in dotnet/sdk#56395
wasiTargetOS block fromCreateReadyToRunFileToPublish.It_uses_the_fixed_wasm_path_for_a_wasi_composite_ownerto expect<entry>.r2r.wasm, the same as browser.Note
This pull request description was generated with assistance from GitHub Copilot.