Skip to content

[wasi] Supply the wasi:http component type to NativeAOT links - #137694

Merged
lewing merged 6 commits into
dotnet:mainfrom
lewing:lewing-nativeaot-wasi-http-component-type
Nov 17, 2026
Merged

lewing merged 6 commits into
dotnet:mainfrom
lewing:lewing-nativeaot-wasi-http-component-type

Conversation

@lewing

@lewing lewing commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

NativeAOT wasi-wasm apps that use HttpClient fail to link:

failed to resolve import `wasi:http/[email protected]::[resource-drop]fields`

WasiHttpHandler imports wasi:http from core wasm. wasm-component-ld can't work out the wasi:http resource types from those imports alone; it needs WasiHttpWorld_component_type.wit. The CoreCLR relink and corerun already pass it, but the NativeAOT targets did not, and the CoreCLR/NativeAOT wasi runtime packs never shipped the file.

  • System.Net.Http.csproj binplaces the .wit for wasi (same pattern as System.Net.Quic's native files), and liveBuilds.targets picks up *.wit from the native artifacts dir, so it ships in the runtime packs.
  • Microsoft.NETCore.Native.Wasm.targets passes each NetCoreAppComponentType item as -Wl,--component-type. Apps that don't use wasi:http end up with no wasi:http imports.
  • WasiApp.CoreCLR.targets uses the same NetCoreAppComponentType item for the CoreCLR relink and drops its source-tree fallback and missing-file error.

Relates to #132798

Note

This PR description was generated with GitHub Copilot.

lewing and others added 3 commits November 16, 2026 15:47
System.Net.Http's WasiHttpHandler imports wasi:[email protected] from core wasm.
wasm-component-ld can't rebuild the resource types from core imports alone
and fails at [resource-drop]fields unless the world is passed via
--component-type. Mono, CoreCLR relink and corerun pass
WasiHttpWorld_component_type.wit; the NativeAOT Wasm targets did not, and
the CoreCLR/NativeAOT wasi runtime packs never shipped the .wit.

- Ship WasiHttpWorld_component_type.wit in the CoreCLR and NativeAOT
  wasi-wasm runtime packs (liveBuilds) and stage it into the in-tree
  runtime pack (build-native.proj).
- Pass -Wl,--component-type for it from Microsoft.NETCore.Native.Wasm.targets
  when present. Unused world imports are dropped from the component, so apps
  that don't use HttpClient are unaffected; app-supplied --component-type
  overlays still compose.
- Add a wasi-only NativeAOT smoke test that issues an HttpClient request.

Co-authored-by: Copilot App <[email protected]>
…links

build-native.proj copies WasiHttpWorld_component_type.wit into the
native artifacts dir for every wasi build, so the existing native globs
put it in the runtime packs. The NativeAOT Wasm targets error out when
it is missing instead of producing an untyped wasi:http link failure.

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

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 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.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib
See info in area-owners.md if you want to be subscribed.

@lewing lewing added the arch-wasm WebAssembly architecture label Nov 16, 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.

The owning library now binplaces WasiHttpWorld_component_type.wit into
the runtime pack native dir and the native artifacts dir, following the
System.Net.Quic NativeBinPlaceItem pattern, instead of build-native.proj
reaching into the library's source tree.

Co-authored-by: Copilot App <[email protected]>
@lewing
lewing requested a review from pavelsavara November 16, 2026 22:44
@lewing
lewing enabled auto-merge (squash) November 16, 2026 22:45
@lewing lewing added the os-wasi Related to WASI variant of arch-wasm label Nov 16, 2026
- Pass component types through a NetCoreAppComponentType item group.
- Drop the missing-file error.
- Remove the WasiHttp smoke test; src/libraries testing on wasi will cover it.

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

Copy link
Copy Markdown
Member

Side remark: native toolchains seem to be including this in object files. Should this be in an object file?

@lewing

lewing commented Nov 16, 2026

Copy link
Copy Markdown
Member Author

Side remark: native toolchains seem to be including this in object files. Should this be in an object file?

Good question, I will check.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Runtime-pack staging and component linking remain unverified; publishing from the produced NativeAOT WASI pack with and without HttpClient is needed to confirm WIT placement, import resolution, and unused wasi:http import removal.

No open issues 🎉

What changed in this PR

This PR supplies the wasi:http component type needed to link NativeAOT WASI apps using HttpClient, aligning NativeAOT linking with the existing CoreCLR approach.

Changes:

  • Binplaces WasiHttpWorld_component_type.wit into runtime-pack and native-artifact directories.
  • Includes .wit files in shared runtime-pack native-file collection.
  • Passes component-type items to the NativeAOT WASM linker.
File Description
src/​libraries/​System.Net.Http/​src/​System.Net.Http.csproj Adds WASI HTTP component-type binplacement.
src/​coreclr/​nativeaot/​BuildIntegration/​Microsoft.NETCore.Native.Wasm.targets Registers the HTTP component type and supplies linker arguments.
eng/​liveBuilds.targets Moves .wit collection into the shared native-artifact list.

Review effort: Balanced

@lewing

lewing commented Nov 16, 2026

Copy link
Copy Markdown
Member Author

Side remark: native toolchains seem to be including this in object files. Should this be in an object file?

Good question, I will check.

Opened #137699 because we don't currently install the tooling to do it, but I will take care of it in a follow-up

…t types

Mirror the NativeAOT wasi targets: declare framework WIT worlds as
NetCoreAppComponentType items and transform them into --component-type link
flags against the runtime pack native dir. System.Net.Http now binplaces the
.wit into the runtime pack, so drop the source-tree fallback and the
missing-file error.

Co-authored-by: Copilot App <[email protected]>
@lewing
lewing requested a review from maraf as a code owner November 16, 2026 23:44
@lewing

lewing commented Nov 16, 2026

Copy link
Copy Markdown
Member Author

Did the same small cleanup to coreclr targets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-NativeAOT-coreclr os-wasi Related to WASI variant of arch-wasm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants