[wasm] Emit webcil-in-wasm component stubs for composite R2R#130394
Merged
lewing merged 2 commits intoJul 13, 2026
Conversation
Composite ReadyToRun builds rewrite each input assembly into a small
per-assembly component stub that forwards to the composite image. The
container format for these stubs was hardcoded to PE
(ReadyToRunContainerFormat.PE) in RewriteComponentFile. On a wasm build
that routes the stub through PEObjectWriter -> CoffObjectWriter, which
throws "Unsupported architecture" for Wasm32, so composite crossgen2
fails after successfully emitting the composite-r2r.wasm image:
System.NotSupportedException: Unsupported architecture
at ILCompiler.ObjectWriter.CoffObjectWriter..ctor(...)
Use the composite image's own container format for the component stubs:
wasm targets emit webcil-in-wasm stubs (loaded by name as
"<assembly>.wasm", matching the browser/wasi external-assembly probe),
while PE/Apple targets keep emitting PE stubs as before. This is not
wasm-arch specific to any single target OS - it fixes composite mode for
both browser and wasi, which previously could not complete a composite
crossgen2 build at all.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
lewing
marked this pull request as draft
July 9, 2026 03:09
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates crossgen2 composite ReadyToRun component-stub emission so that when the compilation container format is Wasm, the per-assembly forwarding “component stubs” are emitted as webcil-in-wasm modules (.wasm) rather than being forced through the PE/COFF pipeline.
Changes:
- When emitting standalone component stubs in composite mode, switch their output filename extension to
.wasmforReadyToRunContainerFormat.Wasm. - Pass a
componentFormatinto the component-stub emission pipeline so Wasm usesReadyToRunContainerFormat.Wasmand non-Wasm continues to use PE.
This was referenced Jul 9, 2026
Open
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
pavelsavara
approved these changes
Jul 9, 2026
pavelsavara
approved these changes
Jul 10, 2026
AndyAyersMS
approved these changes
Jul 13, 2026
eiriktsarpalis
pushed a commit
that referenced
this pull request
Jul 15, 2026
Composite ReadyToRun builds rewrite each input assembly into a small per-assembly *component stub* that forwards to the composite image. In `RewriteComponentFile`, the container format for these stubs was hardcoded to `ReadyToRunContainerFormat.PE`. On a wasm build this routes the stub through `PEObjectWriter` → `CoffObjectWriter`, which throws for the Wasm32 architecture, so a composite crossgen2 build fails **after** successfully emitting the `composite-r2r.wasm` image: ``` Emitting R2R Wasm file: .../composite-r2r.wasm Error: Unsupported architecture System.NotSupportedException: Unsupported architecture at ILCompiler.ObjectWriter.CoffObjectWriter..ctor(...) at ILCompiler.DependencyAnalysis.ReadyToRunObjectWriter.CreatePEObjectWriter() at ILCompiler.ReadyToRunCodegenCompilation.RewriteComponentFile(...) ``` As a result, composite mode could not complete a crossgen2 build for **any** wasm target (browser or wasi). ## Fix Use the composite image's own container format for the per-assembly component stubs: - **wasm** targets emit webcil-in-wasm stubs, written as `<assembly>.wasm` (loaded by name via the browser/wasi external-assembly probe, matching how the composite image itself is loaded). - **PE / Apple** targets keep emitting PE stubs exactly as before (`componentFormat` resolves to `PE` for any non-wasm format). This is a small change (15 insertions) local to `RewriteComponentFile` and its output-path selection; non-wasm behavior is unchanged. ## Validation With this change, `crossgen2 --composite --targetos wasi --targetarch wasm` (and `--targetos browser`) on a set of assemblies emits the `composite-r2r.wasm` image plus one webcil-in-wasm stub per input assembly, all passing `wasm-tools validate`. Verified locally on macOS/arm64. > [!NOTE] > This change was authored with the assistance of GitHub Copilot. --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Co-authored-by: Pavel Savara <pavelsavara@microsoft.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.
Composite ReadyToRun builds rewrite each input assembly into a small per-assembly component stub that forwards to the composite image. In
RewriteComponentFile, the container format for these stubs was hardcoded toReadyToRunContainerFormat.PE.On a wasm build this routes the stub through
PEObjectWriter→CoffObjectWriter, which throws for the Wasm32 architecture, so a composite crossgen2 build fails after successfully emitting thecomposite-r2r.wasmimage:As a result, composite mode could not complete a crossgen2 build for any wasm target (browser or wasi).
Fix
Use the composite image's own container format for the per-assembly component stubs:
<assembly>.wasm(loaded by name via the browser/wasi external-assembly probe, matching how the composite image itself is loaded).componentFormatresolves toPEfor any non-wasm format).This is a small change (15 insertions) local to
RewriteComponentFileand its output-path selection; non-wasm behavior is unchanged.Validation
With this change,
crossgen2 --composite --targetos wasi --targetarch wasm(and--targetos browser) on a set of assemblies emits thecomposite-r2r.wasmimage plus one webcil-in-wasm stub per input assembly, all passingwasm-tools validate. Verified locally on macOS/arm64.Note
This change was authored with the assistance of GitHub Copilot.