Skip to content

[wasi] Embed the wasi:http component type in an object file instead of passing --component-type #137699

Open

Description

@lewing

System.Net.Http's WasiHttpHandler imports wasi:http 0.2.8 directly from managed code. On its own, the linked core module doesn't give wasm-component-ld enough to reconstruct the component types, so each wasi link path passes the world explicitly with -Wl,--component-type,WasiHttpWorld_component_type.wit:

That means shipping the .wit in the runtime packs and keeping the same plumbing in every toolchain.

Native toolchains embed the type information in an object file instead. wasi-libc's libc.a contains wasip2_component_type.o, generated by wit-bindgen's C generator with a component-type: custom section. It also defines __component_type_object_force_link_wasip2, which wasip2.c.obj references, so the object is only linked when the bindings are. wasm-component-ld then picks up the types with no extra flags.

Proposal: do the same for wasi:http, for both CoreCLR and NativeAOT.

  • Generate the encoded component type alongside the existing bindings. generate-wasi-http-bindings.sh already runs wit-bindgen; the C generator or wasm-tools component embed could produce the section, checked in as a byte array in a C source file.
  • Compile it into libSystem.Native.a together with a force-link function.
  • Have WasiHttpHandler call that function through a System.Native P/Invoke, so the object is linked only when the handler survives trimming. That works for NativeAOT, where System.Native is a direct P/Invoke, and for the CoreCLR relink, through its generated P/Invoke table.
  • Then remove the --component-type flags and NetCoreAppComponentType items, and stop shipping the .wit in the packs.

Open questions:

  • How best to produce the encoded section from the existing generator. The repo build has no wasm-tools or wit-bindgen, so the output has to be generated by the script and checked in.
  • Whether the force-link reference reaches the object through the CoreCLR P/Invoke table in every configuration.

Relates to #137694, #132798

Note

This issue was generated with GitHub Copilot.

Activity

  1. added
    arch-wasm
    os-wasi
    on Nov 16, 2026
  2. added
    untriaged
    on Nov 16, 2026
  3. dotnet-policy-service commented on Nov 16, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
    See info in area-owners.md if you want to be subscribed.

  4. dotnet-policy-service commented on Nov 16, 2026

    @dotnet-policy-service
    Contributor

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

  5. added this to the 12.0.0 milestone on Nov 16, 2026
  6. removed
    untriaged
    on Nov 16, 2026
  7. self-assigned this
    on Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

arch-wasmarea-NativeAOT-coreclros-wasi

Type

No type

Projects

  • Status
    No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions