Skip to content

[WASI][Mono] Upgrade WASI SDK / wasmtime / WASIp2 to 0.2.8 and fix sockets for new wasi-libc#128997

Merged
pavelsavara merged 12 commits into
dotnet:mainfrom
pavelsavara:wasisdk-mono
Jun 7, 2026
Merged

[WASI][Mono] Upgrade WASI SDK / wasmtime / WASIp2 to 0.2.8 and fix sockets for new wasi-libc#128997
pavelsavara merged 12 commits into
dotnet:mainfrom
pavelsavara:wasisdk-mono

Conversation

@pavelsavara
Copy link
Copy Markdown
Member

Summary

This branch upgrades the Mono WASI toolchain and regenerates the WASIp2 component-model
bindings against the 0.2.8 interfaces. It also fixes System.Net.Sockets to work with the
new wasi-libc descriptor-table layout, removes the obsolete Node.js run scripts, and disables
HTTP/socket test scenarios that the WASI handler does not support.

Component Old New
WASI SDK 25.0 33.0
wasmtime 27.0.0 45.0.0
WASIp2 interfaces (wasi:io, wasi:http, wasi:clocks) 0.2.0 0.2.8
wit-bindgen (C#) 0.32.0 0.57.1

Motivation

The 0.2.0 snapshot of the WASI SDK and the WASIp2 interfaces had drifted well behind the
current ecosystem. wasi-libc also changed its internal socket descriptor table from a tagged
union to a "fat pointer" + vtable design and now creates the embedded pollables lazily, which
broke the existing System.Net.Sockets event loop. This brings the toolchain current and
restores socket functionality on the new wasi-libc.

Changes

Toolchain / build infrastructure

  • eng/AcquireWasiSdk.targets, src/mono/wasi/build/WasiApp.targets: bump expected WASI SDK to
    33.0. The version check now matches by prefix (StartsWith) so future patch releases of the
    same major are accepted.
  • src/mono/wasi/wasmtime-version.txt: bump wasmtime to 45.0.0.
  • eng/native/gen-buildsys.cmd / gen-buildsys.sh: drop the Node.js-based
    CMAKE_CROSSCOMPILING_EMULATOR (the --experimental-wasi-unstable-preview1 Node path is no
    longer used).
  • src/mono/wasi/wasi.proj, WasiApp.targets: stop linking -lwasi-emulated-pthread, which is
    no longer provided / needed by WASI SDK 33.0.

Run-script cleanup

  • WasiApp.targets: remove the _WasmGenerateNodeScripts target and the generated node.mjs /
    run-node.sh files. WASI apps run under wasmtime via the existing
    _GenerateRunWasmtimeScript target.

Test AppBundle generation

  • eng/testing/tests.wasi.targets: force WasmGenerateAppBundle=true for WASI test projects.
    Test projects are OutputType=Library, for which the property defaults to false; unlike
    browser there is no SDK that bundles via static web assets, so the in-tree WasiAppBuilder
    must run to populate the AppBundle.

Regenerated WASIp2 bindings (0.2.00.2.8)

  • System.Net.Http/.../WasiHttpHandler/* and System.Private.CoreLib/.../Threading/Wasi/*:
    regenerated with wit-bindgen 0.57.1. The new generator changes naming conventions
    (Method.get()Method.Get(), ErrorCode.DNS_TIMEOUTErrorCode.Tags.DnsTimeout,
    Result.ok/errOk/Err, IPoll/ITypesIPollImports/ITypesImports, etc.).
  • Hand-written consumers (WasiHttpInterop.cs, WasiHttpHandler.cs, WasiInputStream.cs,
    WasiOutputStream.cs, WasiEventLoop.cs, TimerQueue.Wasi.cs) updated to the new API names.
  • .wit world files and the generate-wasi-*-bindings.{ps1,sh} scripts updated to pin
    0.2.8 and wit-bindgen 0.57.1.
  • .csproj / .projitems compile lists updated to the new generated file names.

Sockets on the new wasi-libc descriptor table

wasi-libc replaced the tagged-union descriptor entry with a fat pointer ({ void* data; descriptor_vtable_t* vtable; }) and now creates the per-socket pollables lazily.

  • src/native/libs/System.Native/pal_networking.c / .h / entrypoints.c:
    • SystemNative_GetWasiSocketDescriptor now returns the descriptor data pointer plus a
      socketType (1 = TCP/stream, 2 = UDP/datagram) discriminated via getsockopt(SO_TYPE),
      since the vtable that previously identified the kind is a private static symbol.
    • New SystemNative_WasiSubscribeSocketPollable lazily calls the wasi-libc subscribe
      imports to materialize a pollable handle on demand.
  • Interop.SocketEvent.cs: matching LibraryImport signature updates.
  • SocketPal.Wasi.cs: struct layouts updated to mirror the new wasi-libc
    tcp_socket_t / udp_socket_t (field reorder, boolbyte, error_code widened to
    int, trailing timeout fields). The obsolete descriptor_table_entry_* types are removed.
  • SocketAsyncEngine.Wasi.cs: BeforePollHook discriminates on the native socketType and
    uses a new EnsurePollable helper that subscribes lazily (storing the handle back so
    wasi-libc owns and later drops it) instead of reading a pre-existing pollable handle.

Test scenario adjustments

  • System.Net.Http tests: added [SkipOnPlatform(TestPlatforms.Wasi, …)] for scenarios the
    WASI handler does not support (authentication, pre-authentication, proxy, client/server
    certificates, decompression, sync Send, version selection, MaxConnectionsPerServer,
    SOCKS proxy, zero-byte read / ConnectCallback, mini-stress / System.Net.Security,
    SocketsHttpHandler argument-validation cases). Several flaky cancellation/metrics cases are
    marked [ActiveIssue(98957, TestPlatforms.Wasi)].
  • System.Net.Sockets tests: skip Socket.Blocking and DualMode scenarios unsupported on WASI.

@pavelsavara pavelsavara added this to the 11.0.0 milestone Jun 4, 2026
@pavelsavara pavelsavara self-assigned this Jun 4, 2026
Copilot AI review requested due to automatic review settings June 4, 2026 16:52
@pavelsavara pavelsavara added arch-wasm WebAssembly architecture area-Build-mono os-wasi Related to WASI variant of arch-wasm labels Jun 4, 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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 updates the Mono WASI toolchain (WASI SDK / wasmtime) and regenerates the WASIp2 (0.2.8) component-model bindings used by CoreLib and the WASI HTTP handler. It also updates the WASI socket event loop plumbing to match wasi-libc’s new descriptor-table layout and lazy pollable creation, cleans up obsolete Node.js run scripts, and adjusts tests for unsupported WASI scenarios.

Changes:

  • Upgrade toolchain inputs (WASI SDK 33.0, wasmtime 45.0.0) and remove Node-based emulation/run-script generation.
  • Regenerate WASIp2 bindings to 0.2.8 and update managed call sites accordingly.
  • Update WASI socket descriptor resolution + pollable subscription (native + managed) and adjust System.Net tests to skip unsupported features on WASI.

Reviewed changes

Copilot reviewed 68 out of 70 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/native/libs/System.Native/pal_networking.h Updates WASI socket descriptor API signature and adds pollable subscription export.
src/native/libs/System.Native/pal_networking.c Implements new WASI descriptor-table probing and lazy pollable subscription helper.
src/native/libs/System.Native/entrypoints.c Exposes the new native entrypoint for managed interop.
src/libraries/Common/src/Interop/Wasi/System.Native/Interop.SocketEvent.cs Updates LibraryImport signatures for the revised native WASI socket APIs.
src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Wasi.cs Mirrors updated wasi-libc tcp/udp socket struct layouts and removes obsolete descriptor tagged-union types.
src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncEngine.Wasi.cs Uses socketType discrimination + lazy pollable subscription to integrate with wasi-libc’s new lazy pollables.
src/mono/wasi/wasmtime-version.txt Bumps the pinned wasmtime version.
src/mono/wasi/wasi.proj Removes obsolete -lwasi-emulated-pthread link flag for WASI SDK 33.
src/mono/wasi/build/WasiApp.targets Updates toolchain version check, removes Node run-script generation, and adjusts link flags.
eng/native/gen-buildsys.sh Removes Node CMAKE_CROSSCOMPILING_EMULATOR usage for WASI.
eng/native/gen-buildsys.cmd Removes Node CMAKE_CROSSCOMPILING_EMULATOR usage for WASI (Windows).
eng/AcquireWasiSdk.targets Bumps acquired WASI SDK version to 33.0.
eng/testing/tests.wasi.targets Forces AppBundle generation for WASI test projects (OutputType=Library).
src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/world.wit Updates WIT imports to WASIp2 0.2.8.
src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPoll.cs Updates generated support types for wit-bindgen 0.57.1 output.
src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiEventLoop.cs Switches event loop to regenerated 0.2.8 poll/clock APIs.
src/libraries/System.Private.CoreLib/src/System/Threading/TimerQueue.Wasi.cs Updates monotonic clock interop usage to 0.2.8.
src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/generate-wasi-poll-bindings.sh Updates binding generation script to fetch 0.2.8 and wit-bindgen 0.57.1.
src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/generate-wasi-poll-bindings.ps1 Updates binding generation script to fetch 0.2.8 and wit-bindgen 0.57.1.
src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems Updates compile item list to new generated file names for 0.2.8.
src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.Imports.wasi.io.v0_2_8.PollImportsInterop.cs New generated 0.2.8 poll imports interop.
src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.Imports.wasi.io.v0_2_8.IPollImports.cs New generated 0.2.8 poll imports API surface.
src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.Imports.wasi.clocks.v0_2_8.MonotonicClockImportsInterop.cs New generated 0.2.8 clock imports interop.
src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.Imports.wasi.clocks.v0_2_8.IMonotonicClockImports.cs New generated 0.2.8 clock imports API surface.
src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.imports.wasi.io.v0_2_0.PollInterop.cs Removes old generated 0.2.0 poll interop.
src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.imports.wasi.io.v0_2_0.IPoll.cs Removes old generated 0.2.0 poll API.
src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.imports.wasi.clocks.v0_2_0.MonotonicClockInterop.cs Removes old generated 0.2.0 clock interop.
src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttp.cs Updates generated support types for wit-bindgen 0.57.1 output.
src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld_component_type.wit Updates WIT package/interface versions from 0.2.0 to 0.2.8.
src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpHandler.cs Updates outgoing-handler invocation to regenerated 0.2.8 API surface.
src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpInterop.cs Updates conversions and error-code mapping to new generated enum/tag conventions.
src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiInputStream.cs Updates stream handling to regenerated 0.2.8 stream error tags.
src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiOutputStream.cs Updates stream handling imports to regenerated 0.2.8 API names.
src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/generate-wasi-http-bindings.sh Updates binding generation script to fetch 0.2.8 and wit-bindgen 0.57.1.
src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/generate-wasi-http-bindings.ps1 Updates binding generation script to fetch 0.2.8 and wit-bindgen 0.57.1.
src/libraries/System.Net.Http/src/System.Net.Http.csproj Updates compile include list to new generated 0.2.8 files.
src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.io.v0_2_8.* Adds new generated 0.2.8 io/poll/streams/error interop surfaces.
src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.http.v0_2_8.* Adds new generated 0.2.8 http types/outgoing-handler interop surfaces.
src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.Imports.wasi.clocks.v0_2_8.* Adds new generated 0.2.8 clocks interop surfaces.
src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.v0_2_0. Removes old generated 0.2.0 HTTP/io/clocks interop surfaces.
src/libraries/System.Net.Http/tests/FunctionalTests/SocksProxyTest.cs Skips proxy tests on WASI where handler support is absent.
src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.cs Adds WASI skips for unsupported SocketsHttpHandler scenarios.
src/libraries/System.Net.Http/tests/FunctionalTests/ResponseStreamZeroByteReadTests.cs Skips ConnectCallback scenarios on WASI.
src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs Marks known-flaky metrics tests as ActiveIssue on WASI.
src/libraries/System.Net.Http/tests/FunctionalTests/HttpContentTest.cs Skips/marks unsupported or flaky scenarios on WASI.
src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientTest.cs Skips unsupported synchronous send / version-selection scenarios on WASI.
src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientMiniStressTest.cs Skips mini-stress scenarios that require System.Net.Security on WASI.
src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTestBase.SocketsHttpHandler.cs Avoids cert-validation callback configuration on WASI.
src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.Proxy.cs Skips proxy tests on WASI handler.
src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.Authentication.cs Skips authentication/preauth tests on WASI handler.
src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketAsyncEventArgsTest.cs Skips DualMode tests on WASI.
src/libraries/System.Net.Sockets/tests/FunctionalTests/CreateSocketTests.cs Skips Socket.Blocking tests on WASI.

Comment thread src/native/libs/System.Native/pal_networking.c
Comment thread src/native/libs/System.Native/pal_networking.c
@pavelsavara
Copy link
Copy Markdown
Member Author

/azp list

@azure-pipelines
Copy link
Copy Markdown

CI/CD Pipelines for this repository:

@pavelsavara
Copy link
Copy Markdown
Member Author

/azp run runtime-wasm

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@pavelsavara pavelsavara marked this pull request as ready for review June 5, 2026 13:33
Copilot AI review requested due to automatic review settings June 5, 2026 13:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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

Comment thread eng/testing/tests.wasi.targets
Comment thread src/mono/wasi/build/WasiApp.targets
@pavelsavara
Copy link
Copy Markdown
Member Author

/azp run runtime-wasm

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@pavelsavara pavelsavara merged commit e17d74b into dotnet:main Jun 7, 2026
190 of 192 checks passed
@pavelsavara pavelsavara deleted the wasisdk-mono branch June 7, 2026 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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.

3 participants