Platform Layer
Platform support, POSIX-only subsystems, platform guards, and portability rules.
Platform Support Overview
| Platform | Status | Notes |
|---|---|---|
| Linux | Full | Primary development platform. All tests pass. |
| macOS | Full | POSIX-compatible. Same as Linux. |
| Windows | Partial | The Net component links ws2_32 privately. POSIX-only subsystems remain known gaps. |
| Android | Partial | The Storage component uses SDL3 when selected; SDL3 must be provided by the parent project first. |
| Emscripten | Partial | Compiles cleanly. Some features throw PlatformNotSupportedException at runtime. |
POSIX-Only Subsystems
These subsystems currently use POSIX-specific APIs and are documented as known bugs, not completed features:
| Subsystem | POSIX API Used | Status |
|---|---|---|
System::Net::Sockets | <sys/socket.h>, <unistd.h> | POSIX-only |
System::IO::RandomAccess | pread, pwrite, fsync | Done (has Win32 fallback) |
System::AppDomain / AppContext | /proc/self/exe | Linux-only |
System::TimeZoneInfo | localtime_r, /usr/share/zoneinfo | POSIX-only |
Platform Guard Rules
These rules are enforced project-wide (see CLAUDE.md):
- POSIX includes (
<unistd.h>,<sys/socket.h>, etc.) must not appear in public.hppheaders. - Platform-specific code lives only in
.cppfiles. - Use
#ifdef _WIN32/#elif defined(__EMSCRIPTEN__)/#else(POSIX) guards. - On unsupported platforms, throw
System::PlatformNotSupportedExceptionwith a clear message. - Emscripten builds must compile without errors even when features are runtime-unavailable.
Example Guard Pattern
// In a .cpp file — platform-specific implementation
#ifdef _WIN32
#include <windows.h>
// Win32 implementation
#elif defined(__EMSCRIPTEN__)
throw System::PlatformNotSupportedException("Not available on Emscripten.");
#else
#include <unistd.h>
// POSIX implementation
#endif
Windows-Specific
The Net component automatically links ws2_32 privately on Windows. Consumers request SharpRuntime::Net or a higher-level networking component and do not link ws2_32 themselves.
Android-Specific
On Android, SharpRuntime::Storage::StoragePaths uses SDL3 APIs to determine storage paths:
SDL_GetPrefPath()for the isolated storage rootSDL_GetAndroidInternalStoragePath()as fallback
SDL3 headers and library must be available via the parent project before add_subdirectory(sharp-runtime) is called when Storage is selected. The component accepts either SDL3::SDL3 or SDL3::SDL3-static.
Emscripten-Specific
Emscripten (WebAssembly) support requires:
- All platform-guarded code must be guarded by
#elif defined(__EMSCRIPTEN__) - Features that cannot work in a browser should throw
PlatformNotSupportedException - The build must produce zero errors
StoragePaths
modules/storage/include/SharpRuntime/Storage/StoragePaths.hpp | modules/storage/src/SharpRuntime/Storage/StoragePaths.cpp
Provides platform-aware isolated storage paths:
std::filesystem::path root = SharpRuntime::Storage::StoragePaths::GetIsolatedStorageRoot();
Implementation varies by platform: uses SDL_GetPrefPath on Android, appropriate paths on other platforms.
Network Sockets
modules/net-sockets/include/System/Net/Sockets/
Status: POSIX-only
| Class | Header |
|---|---|
TcpClient | System/Net/Sockets/TcpClient.hpp |
UdpClient | System/Net/Sockets/UdpClient.hpp |
NetworkStream | System/Net/Sockets/NetworkStream.hpp |
These use <sys/socket.h> and related POSIX headers. Windows and Emscripten support is incomplete.