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 | CMake links ws2_32. POSIX-only subsystems need Win32 platform guards (known gaps). |
| Android | Partial | StoragePaths uses SDL3 when available. SDL3 must be provided by the parent project (CNA). |
| 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
CMake automatically links ws2_32 on Windows for socket support:
if(WIN32)
target_link_libraries(SHARP_RUNTIME PRIVATE ws2_32)
endif()
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.
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
include/SharpRuntime/Storage/StoragePaths.hpp | 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
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.