Skip to content

[wasi] Don't copy runtime pack link inputs to app build and publish output - #135016

Merged
lewing merged 1 commit into
dotnet:mainfrom
lewing:lewing-wasi-sdk-copy-local-fix
Oct 1, 2026
Merged

lewing merged 1 commit into
dotnet:mainfrom
lewing:lewing-wasi-sdk-copy-local-fix

Conversation

@lewing

@lewing lewing commented Oct 1, 2026

Copy link
Copy Markdown
Member

The WASI runtime pack's data/RuntimeList.xml lists the pack's link-time inputs as <File Type="Native" />: the static libraries (18 .a for CoreCLR, 23 for Mono), WasiHttpWorld_component_type.wit on Mono, and the stock corerun on CoreCLR. The SDK treats these as native runtime assets of a self-contained app. It adds them to ReferenceCopyLocalPaths and to ResolvedFileToPublish, so every WASI app gets one copy in bin/.../wasi-wasm/ and another in publish/. Nothing reads those copies. The native link (Mono's _WasiWriteRspForLinking, CoreCLR's _WasiCoreCLRRelinkCoreRun) reads the .a and .wit files from $(MicrosoftNetCoreAppRuntimePackRidNativeDir). On CoreCLR, the AppBundle's managed/corerun is the per-app relinked or R2R-composed host, not the pack's corerun.

Browser doesn't have this problem. ComputeWasmBuildAssets/ComputeWasmPublishAssets filter runtime-pack candidates through AssetsComputingHelper.ShouldFilterCandidate. The WASI targets don't use that pipeline.

Change

src/mono/wasi/build/WasiApp.targets, shared by Mono and CoreCLR (WasiApp.CoreCLR.targets imports it). A new _WasiRemoveRuntimePackLinkInputs target runs AfterTargets="ResolveRuntimePackAssets". It removes the runtime pack's native assets with extensions .a, .o, .c, .h, .rsp, .props, .wit, and wasm-props.json (the browser rules that apply to WASI, plus .wit), and on CoreCLR the stock corerun. They're removed from RuntimePackAsset and ReferenceCopyLocalPaths. Removing them from RuntimePackAsset keeps them out of _ResolvedCopyLocalPublishAssets (and therefore ResolvedFileToPublish) and out of the generated .deps.json. Only RuntimePackAsset items are matched, so app-provided NativeFileReference items aren't touched.

The target is conditioned on '@(RuntimePackAsset)' != ''. WasmNestedPublishApp requests ResolveRuntimePackAssets before @(RuntimePack) is populated, so that first request is skipped by its condition, but its AfterTargets still fire. Without the item condition, this target would run with nothing to remove and be marked done. The .a files would then reach the nested publish's bin copy and publish/. With the condition, it stays un-run until the real resolution.

Notes:

  • .o, .c, .h, .rsp, .props, and wasm-props.json aren't currently in either WASI pack's RuntimeList (Mono ships src/*.c, include/**/*.h, src/*.rsp, and src/wasm-props.json in the pack, but they aren't listed). They're filtered so the WASI rules match browser's and stay correct if those files get listed.
  • Out of scope, possible follow-ups: the existing icudt.dat and dotnet.wasm removals in _GetWasiGenerateAppBundleDependencies run after copy-local and publish have computed their lists, so they don't affect bin/ or publish/. The icudt_CJK/EFIGS/no_CJK shards are still copied. They're runtime data, not link inputs.
  • This is independent of [wasi] Add CoreCLR ReadyToRun library and runtime test CI #134813, but that PR's CI exposed the problem. On upstream main, in-tree CoreCLR WASI library tests don't resolve the runtime pack, because eng/targetingpacks.targets adds wasi-wasm only to the Mono-labeled KnownRuntimePack. Product apps (the workload adds wasi-wasm to KnownRuntimePack), in-tree Mono, and [wasi] Add CoreCLR ReadyToRun library and runtime test CI #134813 do resolve it.

Validation

Local, macOS arm64 host, wasi-sdk 33, wasmtime via xharness. Suite: Microsoft.Extensions.Primitives.Tests. Measured under artifacts/bin/Microsoft.Extensions.Primitives.Tests/Release/net11.0/wasi-wasm: top-level files for bin, all files for publish. "Before" reverts only this change.

Builds:

  • ./build.sh -s clr+libs+host+packs -os wasi -arch wasm -rf CoreCLR -c Release → succeeded, 0 errors
  • ./build.sh -s mono+libs -os wasi -arch wasm -c Release → succeeded, 0 errors (one retry after a transient compiler-server Cannot release a lock error)

Base command: ./dotnet.sh build src/libraries/Microsoft.Extensions.Primitives/tests/Microsoft.Extensions.Primitives.Tests.csproj -f net11.0 /p:TargetOS=wasi /p:TargetArchitecture=wasm /p:Configuration=Release /p:RuntimeFlavor=<flavor> [extra]

Scenario bin before bin after publish before publish after
CoreCLR, interpreter, untrimmed (1) 222 files, 127.2 MB (18 .a = 66.5 MB + 33.5 MB corerun) 203 files, 27.2 MB 228 files, 127.7 MB 209 files, 27.7 MB
CoreCLR, /p:TestWasmReadyToRun=true /p:EnableAggressiveTrimming=true (2) 222 files, 127.6 MB 203 files, 27.6 MB 81 files, 112.2 MB 62 files, 12.2 MB
Mono, interpreter 228 files, 66.8 MB (23 .a = 26.8 MB + .wit) 204 files, 40.0 MB 234 files, 67.3 MB 210 files, 40.5 MB

Per app, this saves about 200 MB on CoreCLR and about 53 MB on Mono across bin and publish. The removed files are exactly the .a files plus corerun (CoreCLR) or .wit (Mono). The AppBundle file list and every file size are identical before and after in all three scenarios. CoreCLR AppBundle/managed/corerun is still the per-app host: 34,743,522 bytes relinked (interpreter) and 77,201,799 bytes composed (R2R), compared with the pack's 35,096,355-byte stock corerun.

Test runs with the change (/t:Test added to the command above), via xharness/wasmtime:

  • CoreCLR interpreter (1) → Tests run: 541 Passed: 538 Failed: 0 Skipped: 3
  • CoreCLR R2R + aggressive trimming (2) → Tests run: 541 Passed: 538 Failed: 0 Skipped: 3 (composite: 88,191 functions)
  • Mono → Tests run: 541 Passed: 538 Failed: 0 Skipped: 3
  • Mono with /p:WasmBuildNative=true (per-app relink of dotnet.wasm from the pack's .a/.wit) → Tests run: 541 Passed: 538 Failed: 0 Skipped: 3

(1) Upstream main doesn't resolve the CoreCLR WASI runtime pack in-tree, so for this row I applied #134813's three-line eng/targetingpacks.targets change locally. It isn't part of this PR.
(2) R2R with trimming needs #134813's framework-resolution changes (with only the targetingpacks.targets change, crossgen2's call-helper generator fails on mixed trimmed and untrimmed framework assemblies, independent of this PR). I validated it on a temporary local merge of #134813 into this branch, rebuilt with the same build.sh command.

Note

This PR description and change were generated with GitHub Copilot.

…utput

The WASI runtime pack's RuntimeList.xml lists its static libraries and the
WasiHttpWorld .wit (and, for CoreCLR, the stock corerun) as native assets, so
the SDK copied them into the bin and publish directories of every
self-contained WASI app. The native link and the AppBundle read them from the
runtime pack, so remove them from RuntimePackAsset/ReferenceCopyLocalPaths
right after ResolveRuntimePackAssets, mirroring the browser filtering in
AssetsComputingHelper.ShouldFilterCandidate.

Co-authored-by: Copilot App <[email protected]>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@lewing
lewing marked this pull request as ready for review October 1, 2026 13:27
@lewing
lewing requested a review from pavelsavara October 1, 2026 13:27
@lewing lewing added os-wasi Related to WASI variant of arch-wasm arch-wasm WebAssembly architecture labels Oct 1, 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.

@lewing
lewing marked this pull request as draft October 1, 2026 13:29
@lewing
lewing marked this pull request as ready for review October 1, 2026 13:29
@lewing
lewing enabled auto-merge (squash) October 1, 2026 13:40
@lewing
lewing merged commit bb1b237 into dotnet:main Oct 1, 2026
57 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 2, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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