This is an example of how .NET can be integrated as a guest for SpiderLightning. It uses the wasi-experimental
workload which is first available in .NET 8 Preview 4.
A Dockerfile has been provided to enable using these examples in a container.
- .NET 8 Preview 4 or later
- This can be downloaded from Download .NET 8.0 (Linux, macOS, and Windows)
- Verify that
dotnet --version
tells you it's .NET 8 Preview 4 or later
- Install the
wasi-experimental
workload- Run
dotnet workload install wasi-experimental
- Run
- WASI SDK
- Download from wasi-sdk releases page. If you're using Windows, you need the one with
mingw
in its name. - Create an environment variable called
WASI_SDK_PATH
giving the path where you extracted the WASI SDK download, i.e., the directory containingbin
/lib
/share
.
- Download from wasi-sdk releases page. If you're using Windows, you need the one with
- Slight
- Download from SpiderLightning Releases
- Once extracted, add the directory containing
slight
(orslight.exe
on Windows) to your PATH.
git clone https://github.com/SteveSandersonMS/spiderlightning-dotnet.git
cd spiderlightning-dotnet
dotnet build
(or openSpiderlightning.sln
in Visual Studio)
There are two samples. You can run them from Visual Studio via Ctrl+F5, or from the command line:
- ConsoleApp - demonstrates KeyValue API
cd sample/ConsoleApp
dotnet run
- WebServer - demonstrates HTTP Server
cd sample/WebServer
dotnet run
Note that dotnet run
is configured to run the project using slight
, so you need that to be on your PATH. Alternatively, you can build and run manually:
dotnet build
slight -c slightfile.toml run bin\Debug\net8.0\wasi-wasm\AppBundle\ProjectName.wasm -l
(whereProjectName
isConsoleApp
orWebServer
).
When you're inside one of the sample directories, you can run dotnet publish
. This will generate a .wasm
file inside bin\Release\net8.0\wasi-wasm\AppBundle
. You should be able to transfer that onto another machine/server and run it with slight
.