Skip to content

[wasi] Enable Brotli and Zstandard on CoreCLR WASI - #136257

Merged
lewing merged 6 commits into
dotnet:mainfrom
lewing:lewing-wasi-enable-brotli
Oct 23, 2026
Merged

lewing merged 6 commits into
dotnet:mainfrom
lewing:lewing-wasi-enable-brotli

Conversation

@lewing

@lewing lewing commented Oct 21, 2026

Copy link
Copy Markdown
Member

Enables System.IO.Compression.Brotli and Zstandard (ZstandardStream and related types) on CoreCLR WASI. Browser is unchanged and still excludes both.

Why

Both codecs were excluded on all of wasm because browser leaves them out for download size. WASI apps always relink the native runtime with a P/Invoke table generated from the app's trimmed assemblies, so a codec's native code is only linked into apps that use it.

Measured on relinked, trimmed sample apps (Release, wasm-tools strip -a):

App Host size Delta gzip -9 delta
GZip only 5,521,734 — —
GZip + BrotliStream 6,355,085 +833 KB +316 KB
GZip + ZstandardStream 6,028,091 +506 KB +121 KB

The GZip-only host contains no Brotli* or ZSTD_* symbols.

Changes

  • Native/build: brotli build, includes and entry points are now gated on !browser instead of !wasm. The brotli libs are linked in the CoreCLR WASI app relink, the NativeAOT WASI link and the Mono WASI runtime link; libzstd is linked unconditionally in the CoreCLR relink. Duplicate libs.native copies are excluded from the WASI CoreCLR runtime pack, as for libz.a.
  • Managed: System.IO.Compression.Brotli gains a -wasi TFM. System.IO.Compression compiles the real Zstandard implementation for wasi. wasi is removed from UnsupportedOSPlatform on the Brotli assembly, the Zstandard types, and BrotliCompressedContent/ZstandardCompressedContent (src and ref).
  • Call helpers: src/coreclr/vm/wasm/wasi/callhelpers-pinvoke.cpp is regenerated in the commit that adds each codec's P/Invokes (Compression.Native table: 9 → 21 → 51 entries).
  • Tests: the Brotli tests now target WASI, and CompressedContentTest.NonBrowser.cs is compiled for WASI.

Validation

CoreCLR WASI, Release, wasmtime 49.0.1:

  • System.IO.Compression.Brotli.Tests: 259 run, 251 passed, 0 failed, 8 skipped (existing IsMultithreadingSupported conditions).
  • System.Net.Http.Functional.Tests -class CompressedContentTest: 48 run, 47 passed, 1 skipped (existing 32-bit zstd SmallestSize case). This covers the br and zstd round-trips.
  • System.IO.Compression.Tests built for wasi locally: all 316 Zstandard tests passed, 10 skipped on capability conditions.
  • ApiCompat outer builds of Brotli, System.IO.Compression and System.Net.Http are clean.
  • The Mono WASI runtime (mono.runtime+mono.corelib+mono.wasiruntime) builds and links.
  • Not run locally: a NativeAOT WASI app link that uses Brotli.

Known gaps

  • There's no dedicated Zstandard test suite on WASI yet. System.IO.Compression.Tests doesn't target wasi because its WinZip AES and encrypted-zip tests fail there (cryptography isn't supported on WASI) and need gating first.
  • SocketsHttpHandler decompression of br/zstd on WASI is covered by [wasi] Enable SocketsHttpHandler and WebSockets #136234.

Related: #91279 (Brotli on browser; not addressed here)

Note

This PR description was generated with GitHub Copilot.

lewing and others added 5 commits October 21, 2026 18:38
Brotli was excluded on all of wasm because browser omits it for download
size. WASI apps relink the native runtime with a P/Invoke table generated
from the app's trimmed assemblies, so the Brotli static libraries are only
pulled in when the app actually uses them.

- Gate the brotli build/includes/entry points on !browser instead of !wasm.
- Link libbrotlienc/libbrotlidec/libbrotlicommon in the CoreCLR WASI app
  relink, the NativeAOT WASI link, and the Mono WASI runtime link.
- Exclude the duplicate libs.native brotli copies from the WASI CoreCLR
  runtime pack, matching libSystem.IO.Compression.Native.a and libz.a.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Add the wasi target framework so WASI gets the real implementation instead
of the PlatformNotSupported assembly, and drop wasi from the unsupported
platforms of System.IO.Compression.Brotli and BrotliCompressedContent.

Regenerate the WASI call helpers for the new Brotli P/Invokes:
  ./build.sh clr+libs+packs -os wasi -c Release -rf CoreCLR
  src/coreclr/vm/wasm/generate-coreclr-helpers.sh -c Release --target-os wasi

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
libzstd.a is already built for WASI and linked by the CoreCLR WASI app
relink, but the managed Zstandard types were PlatformNotSupported stubs
there. Compile the real implementation for wasi, expose the ZSTD entry
points on !browser, and drop wasi from the unsupported platforms of the
Zstandard types and ZstandardCompressedContent.

The regenerated WASI call helpers now always reference libzstd, so link it
unconditionally in the CoreCLR WASI relink and add it to the Mono WASI
runtime link.

Regenerated with:
  ./build.sh clr+libs+packs -os wasi -c Release -rf CoreCLR
  src/coreclr/vm/wasm/generate-coreclr-helpers.sh -c Release --target-os wasi

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@azure-pipelines

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

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @karelz, @dotnet/area-system-io-compression
See info in area-owners.md if you want to be subscribed.

@lewing lewing added arch-wasm WebAssembly architecture os-wasi Related to WASI variant of arch-wasm labels Oct 21, 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.

@azure-pipelines

Copy link
Copy Markdown
No pipelines are associated with this pull request.

@azure-pipelines

Copy link
Copy Markdown
No pipelines are associated with this pull request.

@lewing

lewing commented Oct 22, 2026

Copy link
Copy Markdown
Member Author

/azp run runtime-coreclr outerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Comment thread eng/liveBuilds.targets
@pavelsavara

Copy link
Copy Markdown
Member

Does src\native\corehost\wasihost need to link new stuff too ?

- Keep the libs.native compression archives in the NativeAOT WASI runtime
  pack: NativeAOT packs take RuntimeFiles from aotsdk rather than
  sharedFramework, so the WASI CoreCLR duplicate exclusion dropped them.
- Update the System.IO.Compression README: Zstandard is now only
  unsupported on browser.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@lewing

lewing commented Oct 23, 2026

Copy link
Copy Markdown
Member Author

@pavelsavara No changes are needed in wasihost itself. src/native/corehost/wasihost only builds the static archive libWasiHost.a and doesn't link any runtime libraries. Those are supplied when each app is relinked in src/mono/wasi/build/WasiApp.CoreCLR.targets, which pulls in libWasiHost.a whole-archive together with the runtime-pack static libs. This PR adds libbrotlienc.a, libbrotlidec.a and libbrotlicommon.a to that link and makes libzstd.a unconditional. The in-tree corerun gets brotli through the PUBLIC link of System.IO.Compression.Native-Static.

Note

This reply was generated with GitHub Copilot.

@lewing
lewing enabled auto-merge (squash) October 23, 2026 20:38
@lewing
lewing merged commit 6f1e2a8 into dotnet:main Oct 23, 2026
158 of 160 checks passed
lewing added a commit to lewing/runtime that referenced this pull request Oct 24, 2026
Brotli and Zstandard now work on WASI (dotnet#136257). The decompression test
servers disposed compression streams synchronously over the connection, which
WASI doesn't support, and the Brotli buffer-limit test's write loop never
yielded to a single-threaded client. The new Alt-Svc test needs TLS.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-System.IO.Compression os-wasi Related to WASI variant of arch-wasm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants