SteveSandersonMS / dotnet-wasi-sdk

Packages for building .NET projects as standalone WASI-compliant modules
519 stars 36 forks source link

Deprecated

This experimental SDK is now superseded by the .NET SDK's wasi-experimental workload (which itself is still experimental). See https://github.com/dotnet/runtime/blob/main/src/mono/wasi/README.md

Everything below this point is for comparative purposes only. Please move your experiments over to use wasi-experimental instead of the packages in this repo.

Experimental WASI SDK for .NET Core

Wasi.Sdk is an experimental package that can build .NET Core projects (including whole ASP.NET Core applications) into standalone WASI-compliant .wasm files. These can then be run in standard WASI environments or custom WASI-like hosts.

How to use: Console applications

dotnet new console -o MyFirstWasiApp
cd MyFirstWasiApp
dotnet add package Wasi.Sdk --prerelease
dotnet build

You'll see from the build output that this produces bin/Debug/net7.0/MyFirstWasiApp.wasm.

To run it,

Alternatively you can invoke runners like wasmtime or wasmer manually on the command line. For example,

Other WASI hosts work similarly.

How to use: ASP.NET Core applications

dotnet new web -o MyWebApp
cd MyWebApp
dotnet add package Wasi.Sdk --prerelease
dotnet add package Wasi.AspNetCore.Server.Native --prerelease

Then:

That's it! You can now run it via dotnet run (or in VS, use Ctrl+F5)

Optionally, to add support for bundling wwwroot files into the .wasm file and serving them:

What's in this repo

... and more

Building this repo from source

First, build the runtime. This can take quite a long time.

Now you can build the packages and samples in this repo: