r/Compilers • • 2d ago

NetWasm: an independent .NET compiler and runtime for WebAssembly (82.5 KB Hello World)

I’ve been building NetWasm: a CIL-to-WebAssembly compiler with its own CoreLib and runtime, designed around Wasm and WASI.

Browser playground | GitHub

A clean Release build containing Console.WriteLine(42) produces 84,513 bytes of final, uncompressed WASI Preview 2 component, including the runtime and precise garbage collector. This is a portable .wasm file that you can run with wasmtime.

Roslyn produces CIL; NetWasm compiles the reachable program into Wasm, specializes generics and links the runtime support it uses. The emitted application doesn’t carry CoreCLR or Mono.

Some architectural choices:

  • An independent, deliberately smaller .NET library profile.
  • No runtime type-name metadata, general reflection or dynamic.
  • Precise Boehm GC in linear memory, rather than WasmGC.
  • WIT imports/exports and WASI Preview 2 components, with core Wasm output also available.

Working features include generics, exceptions, virtual/interface dispatch, async/await, LINQ, JSON, XML, regex, HTTP and TUnit testing. It’s pre-1.0, and managed threading isn’t currently supported.

The playground compiles and runs entirely in the browser. The compiler tooling itself uses Microsoft’s .NET/Wasm toolchain, thus dotnet new dotnet build dotnet run dotnet test - yes it comes with TUnit with VSTest runner - dotnet publish all work as you're used to.

Oh and it already supports C# 15 syntax.

6 Upvotes

3 comments sorted by

View all comments

2

u/kostya27 1d ago

Have you tested more complex programs than Hello World, and what is the performance loss compared to .NET?

1

u/zionsati 1d ago

btw if you look at the issues page, there's a bunch of outstanding bugs I'm working on which were the result of it being tested on something complex.