Project Overview
What sharp-runtime is, its purpose, goals, and current status.
What is sharp-runtime?
sharp-runtime is a C++23 component library that reimplements a practical subset of
the .NET System.* namespace hierarchy. Its primary goal is to enable source-porting
of C#/XNA game code to C++ with minimal changes, while providing a clean and modern C++ implementation
that does not require the Common Language Runtime (CLR) or any managed runtime.
The public API closely mirrors .NET — class names, method signatures, and namespace structure all follow the .NET standard library conventions. The underlying C++ implementations use standard containers, RAII, and C++23 features.
Main Purpose
sharp-runtime provides building blocks so that ported C#/XNA code can compile and run as native C++ with minimal changes. These building blocks include:
- C#-like primitive type aliases (
intcs,bytecs,shortcs, etc.) - Exception hierarchy matching .NET (
System::Exception,System::ArgumentException, etc.) - Delegate and event mechanisms (
System::Action,System::EventHandler<T>) - String utilities (
System::Stringstatic helpers overstd::string) - Array helpers (
System::Arraystatic templates overstd::vector) - Generic collections (
List<T>,Dictionary<K,V>,HashSet<T>, etc.) - I/O subsystem (
System::IO::Stream,File,Directory, compression) - Threading primitives (
Thread,Mutex,CancellationToken,Timer) - Numerics (
Vector2,Vector3,Vector4,Matrix4x4,Quaternion) - Text processing (
StringBuilder,Encoding, JSON, XML)
Component-Based Integration
The public API remains familiar, while the build is now divided into 40 independently selectable physical components. A project can request a narrow surface such as Text.Json or Net.WebSockets; CMake enables its public dependency closure automatically.
set(SHARP_RUNTIME_COMPONENTS Text.Json)
set(SHARP_RUNTIME_BUILD_TESTS OFF CACHE BOOL "" FORCE)
add_subdirectory(sharp-runtime)
target_link_libraries(MyApp PRIVATE SharpRuntime::Text.Json)
SharpRuntime::All remains available for projects that need the complete runtime. Existing broad integration through SHARP_RUNTIME is retained when the complete runtime is selected.
Relationship to Other Projects
| Project | Relationship |
|---|---|
| CNA | C++ reimplementation of XNA 4.0. CNA is built on top of sharp-runtime. It depends on sharp-runtime for all System::* types, primitives, events, I/O, and threading. |
| mobile-eggbert | C++ port of a Windows Phone game. Uses sharp-runtime for intcs/bytecs types, StringBuilder, TimeSpan, EventArgs, Random, and property macros. |
| dotnet/runtime | Used as reference for API design only (MIT License). sharp-runtime's public API mirrors .NET class/method names. The C++ implementation is original work. |
Main Visible Features
- 40 physical modules with explicit public, private, and test-only dependency boundaries
- 983 public headers and 369 component-owned test sources via GoogleTest
- Core types:
Object,Exceptionhierarchy, primitives (incl.Half,Int128,UInt128) - Collections: generic (
List,Dictionary,HashSet,SortedSet…), immutable, non-generic (Hashtable,ArrayList,BitArray) - Span/Memory:
Span<T>,ReadOnlySpan<T>,Memory<T>,MemoryExtensions - Threading: full synchronization primitives +
Barrier,CountdownEvent,AsyncLocal,Lock, Tasks (Task<T>,ValueTask<T>) - Networking:
HttpClient(plain HTTP),IPAddress, POSIX sockets - I/O: streams, File, Directory, Compression (GZip/Deflate/Zip), Hashing
- Text:
StringBuilder, Encoding, JSON (Utf8JsonReader/Writer), XML (tinyxml2) - Time:
DateTime,DateOnly,TimeOnly,TimeSpan,TimeProvider - Clean C++23 code with zero warnings on GCC/Clang
- Vendored dependencies: GoogleTest, nlohmann/json, tinyxml2, miniz
- SPDX license headers on every file (MIT + .NET Foundation attribution)
- Doxygen-compatible documentation comments with status notes
Supported Platforms
| Platform | Status | Notes |
|---|---|---|
| Linux | Done | Primary development and CI platform |
| macOS | Done | POSIX-compatible; same as Linux |
| Windows | Partial | Links ws2_32; POSIX-only subsystems need Win32 guards |
| Android | Partial | StoragePaths uses SDL3 when available; requires SDL3 from parent project |
| Emscripten | Stub | Compiles cleanly; some features throw PlatformNotSupportedException at runtime |
Important Dependencies
| Dependency | Location | Purpose |
|---|---|---|
| ZLIB | System (external) | Used privately by IO.Compression only when selected |
| GoogleTest | vendor/googletest/ | Test framework (git submodule) |
| nlohmann/json | vendor/nlohmann/json.hpp | System::Text::Json implementation |
| tinyxml2 | vendor/tinyxml2/ | Owned by Xml; exposed because XML headers use its types |
| miniz | vendor/miniz/ | Owned privately by IO.Compression.Zip |
Current Maturity / Status
sharp-runtime is in active development with 983 public headers organized into 40 physical modules. The build keeps module boundaries explicit while preserving existing public namespaces and broad compatibility targets. Porting continues type-by-type driven by CNA and mobile-eggbert dependency analysis.
The status tracking system uses these values, written in Doxygen comments:
| Status | Meaning |
|---|---|
| Todo | Not implemented yet |
| Stub | Skeleton only — returns placeholder or throws |
| Partial | Partially implemented, may have known gaps |
| Implemented | Functionally complete |
| Verified | Validated against expected .NET behavior |
Design Philosophy
- Prefer clarity over completeness
- Avoid unnecessary complexity
- Keep APIs close to .NET where it makes sense
- Use modern C++ (RAII, strong typing, clear ownership)
- No LINQ — use
std::rangesin ported code instead - No GC — RAII and smart pointers replace garbage collection