This is a fully working prototype for .NET 7 with Raylib ahead-of-time 🚀 compiled into WebAssembly (wasm). See a couple of known issues for limitations.
Make sure you have the latest version of .NET 7 for example from here, the prototype was built with:
dotnet --version
7.0.100
Install the official wasm tooling:
dotnet workload install wasm-tools
dotnet workload install wasm-experimental
Install a tool to create ad-hoc http server to server application/wasm
:
dotnet tool install --global dotnet-serve
libraylib.a
included in the repository is pre-compiled from my machine, but GitHub Pages workflow compiles Raylib form PLATFORM=WEB on its own every build.
Examples are copied from ChrisDill/Raylib-cs-Examples. Few examples were removed since they used functionality removed from Raylib 4.2. This project uses 4.2.0.2 of the Raylib-cs
nuget package.
./Examples
The project which makes the WebAssembly possible is here:
./DotnetRaylibWasm
Note The latest version of main branch is available here. To run it locally follow these instructions.
publish
the solution from the root of the repository. Don't even try to use just build
, it's buggy. Note the publishing takes a while:
dotnet publish -C Release
To serve the files use this command from the root (change \
to /
in file path if you are not on Windows):
dotnet serve --mime .wasm=application/wasm --mime .js=text/javascript --mime .json=application/json --directory DotnetRaylibWasm\bin\Debug\net7.0\browser-wasm\AppBundle\
Copy the link from the output and open it in your browser (tested on the latest Chrome).
Plenty of information isn't really public or well documented, so this section collects found information:
NativeFileReference
https://github.com/dotnet/runtime/tree/3b0ef303e0969fa376569baa38a98c870a8f7561/src/mono/sample/wasm/browser-advanceddotnet
JS module https://github.com/dotnet/runtime/blob/main/src/mono/wasm/runtime/dotnet.d.ts