-
Notifications
You must be signed in to change notification settings - Fork 28
docs: add overview documentation for CSharpWasm #134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rabail-aamir
wants to merge
3
commits into
thoth-tech:main
Choose a base branch
from
rabail-aamir:add-csharpwasm-doc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| # 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.| | ||
| | `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: | ||
| - 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. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would add a note here that tells Windows users to use this script with WSL or MINGW to run the script
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it, thx |
||
|
|
||
| ```bash | ||
| 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` | ||
| - 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 | ||
|
|
||
| You can provide C# code directly to the `CompileAndRun` function. For example: | ||
|
|
||
| ```csharp | ||
| using System; | ||
|
|
||
| class Program { | ||
| static void Main() { | ||
| Console.WriteLine("Hello from C#!"); | ||
| } | ||
| } | ||
|
|
||
| ``` | ||
|
|
||
| ### 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. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.