Stream: C#/.net-collaboration

Topic: NativeAOT targeting WASIp2 directly


view this post on Zulip Joel Dice (Jun 20 2024 at 15:29):

FYI, once https://github.com/dotnet/runtimelab/pull/2614 is ready and merged, the NativeAOT-LLVM toolchain will target WASIp2 directly and therefore generate components itself, meaning there's no need to run wasm-tools component new afterward.

This has been an interesting exercise, since it's pretty much the first toolchain to use WASI-SDK's wasm32-wasip2 target in a non-trivial way, which has required patching a few things up here and there. The upshot is that .NET is helping pave the way for really good WASIp2 support in the next WASI-SDK release, which should make the transition easier for other languages and tools (e.g. CPython).

This adds WasiHttpHandler, a new implementation of HttpMessageHandler based on wasi:http/outgoing-handler, plus tweaks to System.Threading to allow async Tasks to work in a single-threaded context,...

view this post on Zulip James Sturtevant (Jun 20 2024 at 18:14):

will need to update the componentize-dotnet to skip that step if on .net 9?

view this post on Zulip Joel Dice (Jun 20 2024 at 18:16):

I think we'll want componentize-dotnet to skip it no matter what. Although I'm a bit fuzzy on the relationship between the dotnet you build with and the <PackageReference Include="runtime.linux-arm64.Microsoft.DotNet.ILCompiler.LLVM" Version="9.0.0-*"> package reference. Can you use the ILC version 9.0.0-* with a dotnet earlier than 9? Does any of this work with dotnet 8?

view this post on Zulip Scott Waye (Jun 20 2024 at 18:35):

yes, this should all work with dotnet 8, if there are breaking changes, which I don't think dotnet does much, if it all, then it could cause a problem, e.g. you compiled against an API that you thought did "A", but we compiled against the same API that was changed to do "B".

view this post on Zulip Scott Waye (Jun 20 2024 at 18:35):

I don't think that happens though

view this post on Zulip Joel Dice (Jun 20 2024 at 18:38):

Makes sense. I think that (once my PR is merged) runtime.linux-arm64.Microsoft.DotNet.ILCompiler.LLVM will create a component regardless of whether it's used with dotnet 8 or 9, so componentize-dotnet should not try to use wasm-tools component new in any case.

view this post on Zulip James Sturtevant (Jun 20 2024 at 19:32):

Will we still need to adapt the component to point at cli, reactor and proxy adapters? Or does that get built in automatically after the pr linked?

view this post on Zulip Joel Dice (Jun 20 2024 at 19:33):

wasm-component-ld (which now ships as part of WASI-SDK) takes care of that, so yeah, it will happen automatically.

view this post on Zulip James Sturtevant (Jun 20 2024 at 20:06):

cool! Do potentially wanto still include wasmtools binary in componetize-dotnet for things like https://github.com/dicej/dotnet9-wasi-http-example/blob/1941836215e0301ccf7738c9008ae29d0f0d143b/build.sh#L20? Is it common or maybe improtant to run a strip on release builds?

Contribute to dicej/dotnet9-wasi-http-example development by creating an account on GitHub.

view this post on Zulip Joel Dice (Jun 20 2024 at 20:07):

Stripping can definitely reduce the size of the component, which is nice, but I don't think that needs to be a built-in feature of componentize-dotnet necessarily.

view this post on Zulip James Sturtevant (Jun 20 2024 at 20:08):

Having the binary there makes it easy to add an addtioinal step, I might keep it there and document how you would extend your build to do that type of thing

view this post on Zulip James Sturtevant (Jun 20 2024 at 20:13):

I opened https://github.com/bytecodealliance/componentize-dotnet/issues/26 to track this update to compontize-dotnet

After dotnet/runtimelab#2614 merges, we will no longer need to call component new as the compiler will produce wasi p2 components directly. This is an issue to track that change once the pr merges

Last updated: Dec 06 2025 at 06:05 UTC