Platform Integration Guidelines
These guideline describes how Erbsland Core code should use native Windows, macOS and Linux APIs.
General Rules
Isolate native APIs behind narrow
implclasses or backend interfaces.Prefer virtual backend contracts over platform macro logic inside implementation files.
Keep
#ifplatform switching minimal and close to backend creation and platform-only implementation files.Keep platform dependent code in isolated compilation units (
Windows....cpp/hpp/Posix....cpp/hpp)Use CMake
if (WIN32)to only include the units for the compiled platform.Use
ERBSLAND_CORE_OS_...macros to detect the platform (incore/Definitions.hpp)
Recommended Pattern
Strings and Buffers
Use
text::Stringfor regular library code and POSIX/macOS API inputs.Use
text::U16Stringfor Windows API inputs that require UTF-16.Use
text::StringConverterfor explicit UTF-8/UTF-16 conversion at platform boundaries.Use
text::impl::PlatformU8StringAccessandtext::impl::PlatformU16StringAccessfor null-terminated read-only platform API inputs. These accessors safely materialize sliced strings.Use
text::impl::UnsafeU8StringAccessandtext::impl::UnsafeU16StringAccessonly for bounded span or data-view access inside the library. They deliberately do not expose null-terminated pointers.Use
text::impl::UnsafeU8StringBufferandtext::impl::UnsafeU16StringBufferfor APIs that fill caller-owned buffers.Track buffer sizes with strong unit types such as
unit::ByteLengthandunit::U16DataLengthwhenever the size is part of library logic.
Platform Notes
Wrap Windows headers and platform details through existing core helpers, such as
core/impl/WindowsApi.hpp.Use RAII wrappers for handles, allocated native buffers and other resources.
Avoid leaking platform naming, separators, encodings or handle types into public cross-platform APIs.
Tests
Make sure, backend logic has an abstract interface, that allows to write mock-backends and backend-proxies.
Add platform-specific suites for behavior that depends on real OS APIs.
Let CMake select Windows or POSIX test files instead of guarding whole tests with large macro blocks.