cmadh / spiderlightning-dotnet

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

.NET on SpiderLightning

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.

Prerequisites

  • .NET 8 Preview 4 or later
  • Install the wasi-experimental workload
    • Run dotnet workload install wasi-experimental
  • 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 containing bin/lib/share.
  • Slight
    • Download from SpiderLightning Releases
    • Once extracted, add the directory containing slight (or slight.exe on Windows) to your PATH.

How to build

  • git clone https://github.com/SteveSandersonMS/spiderlightning-dotnet.git
  • cd spiderlightning-dotnet
  • dotnet build (or open Spiderlightning.sln in Visual Studio)

Samples

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 (where ProjectName is ConsoleApp or WebServer).

Publishing

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.

About


Languages

Language:C 84.4%Language:C# 14.1%Language:Dockerfile 0.8%Language:Batchfile 0.6%