From 0b38759741e5d953b0fcb0946318feb54840ac88 Mon Sep 17 00:00:00 2001 From: rabail-aamir Date: Mon, 8 Sep 2025 00:11:45 +1000 Subject: [PATCH 1/3] docs: add overview documentation for CSharpWasm --- CSharpWasm/overview.md | 90 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 CSharpWasm/overview.md diff --git a/CSharpWasm/overview.md b/CSharpWasm/overview.md new file mode 100644 index 0000000..7ce4788 --- /dev/null +++ b/CSharpWasm/overview.md @@ -0,0 +1,90 @@ +# CSharpWasm Documentation + +## Purpose + +CSharpWasm project enables users to execute C# code directly within their browser for SK Online (SKO). +The system relies on .NET 8 WebAssembly and Roslyn to execute user-submitted C# code while providing SplashKit functions through JavaScript interop. + +The documentation provides essential information to help contributors understand the system architecture and build process and usage of the system. + + + +## Project Layout + +The following shows the structure of the `CSharpWasm/` + +``` +CSharpWasm/ +├─ Properties/ +│ ├─ AssemblyInfo.cs +│ └─ launchSettings.json +├─ .gitignore +├─ CSharpCodeRunner.cs +├─ CSharpWasm.csproj +├─ Program.cs +├─ SplashKitBindings.Generated.cs +├─ buildAndCopy.sh +└─ runtimeconfig.template.json +``` + +| File / Folder | Role | Responsibilities | +| -------------------------------- | ----------------- | ------------------------------------------------------------------------------------------ | +| `CSharpCodeRunner.cs` | Compiler & Runner |The `CompileAndRun` function performs main operations which include loading reference assemblies followed by Roslyn-based C# compilation and then running the `Main()` function when it exists.| +| `SplashKitBindings.Generated.cs` | C# ↔ JS Interop | The generated file contains `JSImport` bindings which expose SplashKitBackendWASM functions (graphics, audio, input).| +| `Program.cs` | Wasm Bootstrap |The code provides a basic starting point for browser execution.| +| `buildAndCopy.sh` | Build Script | Shell script that builds the project and copies DLLs and `_framework` files into `../CSharpWasmExpo/`.| +| `CSharpWasm.csproj` | Project File | Targets .NET 8 WebAssembly, includes `Microsoft.CodeAnalysis` (Roslyn).| +| `Properties/AssemblyInfo.cs` | Assembly Metadata | Marks supported platform as “browser”.| +| `Properties/launchSettings.json` | Launch Config | Settings for running/debugging locally in browser.| +| `runtimeconfig.template.json` | Runtime Template | Template for browser runtime behavior.| + +## Prerequisites +Before starting the build process you need to verify that you have: +- The .NET 8 SDK needs to be installed on your system. +- You need to install the WebAssembly tools workload using the command dotnet workload install wasm-tools. +- Your project folder CSharpWasmExpo requires either a local development environment or a hosting solution to function. + +## Build and Copy Process +You can create and distribute the artifacts through the following command which needs to be executed from the `CSharpWasm/` directory. + +```bash +chmod +x buildAndCopy.sh # first time only +./buildAndCopy.sh +``` + +This script is responsible for +- Building project with `dotnet build` +- Required DLLs will be copied into the `../CSharpWasmExpo/bin/` +- WebAssembly runtime files need to be added to the Expo host at a path which depends on your specific setup. + +## Usage in the Browser + +```C# +Example of JavaScript call: + +const code = +using System; +class Program { + static void Main() { + Console.WriteLine("Hello from C#!"); + } +}; + +const result = await globalThis.CSharpCodeRunner.CompileAndRun(code); +console.log(result); +``` + +### Output Expected + +``` +Hello from C#! +``` + +- The program displays its output in the console after compilation completes successfully. +- The compiler returns a list of compilation errors when syntax or build problems occur. +- A program requires a valid entry point which should be static void Main(). + +## Troubleshooting +- No entry point: This means program lacks an entry point which should be defined through `static void Main()`. +- Error loading assembly: Then build script requires DLLs to exist in the `../CSharpWasmExpo/bin/` directory for successful execution. +- Check your submitted code lines against the error messages because they show exact locations of the problems. \ No newline at end of file From 8bf6af23fa5b21fdf947651c14b644b86b224d79 Mon Sep 17 00:00:00 2001 From: rabail-aamir Date: Mon, 8 Sep 2025 00:22:43 +1000 Subject: [PATCH 2/3] docs: move CSharpWasm overview into Documentation folder --- CSharpWasm/overview.md => Documentation/CSharpWasm.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename CSharpWasm/overview.md => Documentation/CSharpWasm.md (100%) diff --git a/CSharpWasm/overview.md b/Documentation/CSharpWasm.md similarity index 100% rename from CSharpWasm/overview.md rename to Documentation/CSharpWasm.md From 90997754057b584ebb4f64573412f6da1c9dedc1 Mon Sep 17 00:00:00 2001 From: rabail-aamir Date: Sat, 27 Sep 2025 01:08:18 +1000 Subject: [PATCH 3/3] docs: update CSharpWasm.md with Windows note, bindingGenerator.py, and corrected usage example --- Documentation/CSharpWasm.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Documentation/CSharpWasm.md b/Documentation/CSharpWasm.md index 7ce4788..d048a93 100644 --- a/Documentation/CSharpWasm.md +++ b/Documentation/CSharpWasm.md @@ -37,6 +37,7 @@ CSharpWasm/ | `Properties/AssemblyInfo.cs` | Assembly Metadata | Marks supported platform as “browser”.| | `Properties/launchSettings.json` | Launch Config | Settings for running/debugging locally in browser.| | `runtimeconfig.template.json` | Runtime Template | Template for browser runtime behavior.| +| `bindingGenerator.py` | Binding Generator | Used to generate the `SplashKitBindings.Generated.cs` file.| ## Prerequisites Before starting the build process you need to verify that you have: @@ -51,6 +52,8 @@ You can create and distribute the artifacts through the following command which chmod +x buildAndCopy.sh # first time only ./buildAndCopy.sh ``` +> **Note for Windows users:** The Unix shell script `buildAndCopy.sh` operates under Unix shell systems. The script requires execution from either WSL (Ubuntu on Windows) or Git Bash/MinGW environments. The script fails to execute properly when run from Command Prompt or PowerShell. +You can execute the script through Git Bash by running `bash buildAndCopy.sh`. This script is responsible for - Building project with `dotnet build` @@ -59,19 +62,17 @@ This script is responsible for ## Usage in the Browser -```C# -Example of JavaScript call: +You can provide C# code directly to the `CompileAndRun` function. For example: -const code = +```csharp using System; + class Program { static void Main() { Console.WriteLine("Hello from C#!"); } -}; - -const result = await globalThis.CSharpCodeRunner.CompileAndRun(code); -console.log(result); +} + ``` ### Output Expected