Native libraries
Purpose
Section titled “Purpose”How the engine’s own native libraries are laid out, built, tested, shipped and refreshed.
| Library | Built from | P/Invoke name | Files |
|---|---|---|---|
| ENet | Native/ENet/upstream: nxrighthere/ENet-CSharp submodule, tag 2.4.8 | enet (ENet-CSharp 2.4.8) | enet.dll, libenet.so, libenet.dylib |
| RmlUi shim | Native/RmlUi: in-house C ABI over RmlUi 6.3 + FreeType 2.14.3 | mfrmlui | mfrmlui.dll, libmfrmlui.so, libmfrmlui.dylib |
| SVG rasteriser | Native/Svg: in-house C ABI over ThorVG 1.0.3 (Godot 4.7.2’s vendored copy, PNG loader off; ADR 0112) | mfsvg | mfsvg.dll, libmfsvg.so, libmfsvg.dylib |
| Mesh simplifier | Native/MeshOpt: in-house C ABI over meshoptimizer 1.3 (submodule; ADR 0256), for generated LODs | mfmeshopt | mfmeshopt.dll, libmfmeshopt.so, libmfmeshopt.dylib |
Valve’s steam_api (steam_api64.dll, libsteam_api.so, libsteam_api.dylib) also lives in
MainframeEngine/runtimes/<rid>/native, but it is not ours: see Valve’s steam_api.
The editor’s helper executable mfplughost is built in the mainframe-editor repository.
Decisions: ADR 0001 (ENet) and ADR 0002 (RmlUi shim, ABI rules, licence finding).
Layout
Section titled “Layout”Native/ CMakeLists.txt top level: options MF_NATIVES_ENET, MF_NATIVES_RMLUI, MF_NATIVES_SVG, MF_NATIVES_MESHOPT (all ON) build.sh local build + test (+ --stage into runtimes/) for macOS / Linux natives-lock.sh update / verify Native/natives.lock natives.lock provenance of the committed binaries (generated) ENet/ CMakeLists.txt shared library `enet`, exports limited to enet_* exports.macos.txt ld64 export list exports.linux.map GNU ld version script pinvoke-exports.txt the 65 entry points ENet-CSharp 2.4.8 P/Invokes tests/ enet_exports, enet_smoke upstream/ submodule (nxrighthere/ENet-CSharp @ 2.4.8) RmlUi/ CMakeLists.txt shared library `mfrmlui` (RmlUi Core + Debugger + FreeType, all static) include/mfrmlui.h public C header: the ABI contract shim/ C++ implementation, export lists, NOTICE.md tests/ mfrmlui_exports, mfrmlui_smoke external/RmlUi/ submodule (mikke89/RmlUi @ 6.3) external/freetype/ submodule (freetype/freetype @ VER-2-14-3) MeshOpt/ CMakeLists.txt shared library `mfmeshopt` (meshoptimizer's simplifier, vertex cache and allocator, static) include/mfmeshopt.h public C header: abi/library version, simplify, simplify_scale, optimize_vertex_cache shim/ C++ implementation (argument checks before meshoptimizer's asserts), export lists tests/ mfmeshopt_smoke external/meshoptimizer/ submodule (zeux/meshoptimizer @ v1.3)MainframeEngine/runtimes/ osx-arm64/native/ libenet.dylib, libmfrmlui.dylib, libmfsvg.dylib, libmfmeshopt.dylib (universal arm64 + x86_64) osx-x64/native/ the same universal files (NuGet does not pick osx-x64 assets for arm64, so both RIDs) win-x64/native/ enet.dll, mfrmlui.dll (from natives.yml) linux-x64/native/ libenet.so, libmfrmlui.so (from natives.yml) */native/steam_api* Valve's steam_api64.dll / libsteam_api.so / libsteam_api.dylib (vendored, not built here)Build settings
Section titled “Build settings”| macOS | Windows | Linux | |
|---|---|---|---|
| Toolchain | Apple clang, Ninja | MSVC, newest Visual Studio generator, -A x64 | GCC on ubuntu-22.04, Ninja |
| Architecture | universal arm64;x86_64 | x64 | x86_64 |
| Minimum OS / runtime | macOS 11.0 | static CRT (/MT) | glibc ≤ 2.35; libstdc++/libgcc linked statically into mfrmlui |
| Exports | -exported_symbols_list (_enet_*, _mfrmlui_*) | __declspec(dllexport) | --version-script (+ --exclude-libs,ALL) |
| Install name / SONAME | @rpath/lib<name>.dylib | n/a | lib<name>.so (no version suffix) |
- Visibility. Everything linked into
mfrmluiis compiled with-fvisibility=hidden. ENet relies on its export list only: upstream has no visibility macro, so hiding everything would hide its API too. - Warnings.
- Our code is built with
-Wall -Wextra -Wpedantic -Wshadow -Wconversion -Wsign-conversionon clang/gcc and/W4 /permissive-on MSVC, as errors.-DMF_NATIVES_WERROR=OFFturns off warnings-as-errors. - Third-party code builds with its own settings.
- For upstream ENet, three reviewed, benign warning categories are silenced (see
Native/ENet/CMakeLists.txt). - A clean macOS build currently prints zero warnings.
- Our code is built with
- No system dependencies. FreeType is configured without zlib/bzip2/png/harfbuzz/brotli; it uses its bundled zlib. Homebrew libraries are single-architecture and would break the universal build.
- Determinism. On the same toolchain, rebuilding produces byte-identical binaries.
Building locally
Section titled “Building locally”Requirements: CMake ≥ 3.25, Ninja (optional; brew install cmake ninja), a C/C++20 compiler, and the submodules:
git submodule update --init --recursive NativemacOS / Linux, using the helper (universal on macOS):
Native/build.sh # configure + build + ctest into Native/build (git-ignored)Native/build.sh --stage # ...and copy the libraries into MainframeEngine/runtimes/<rid>/native + update the lockNative/build.sh -DMF_NATIVES_RMLUI=OFF # extra CMake arguments are passed throughOr with plain CMake:
cmake -S Native -B Native/build -G Ninja -DCMAKE_BUILD_TYPE=Release \ "-DCMAKE_OSX_ARCHITECTURES=arm64;x86_64" -DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 # macOS onlycmake --build Native/buildctest --test-dir Native/build --output-on-failureYou can also build one library on its own, e.g. cmake -S Native/RmlUi -B Native/build/rmlui -G Ninja -DCMAKE_BUILD_TYPE=Release.
Windows (Developer PowerShell not required):
cmake -S Native -B Native/build -A x64cmake --build Native/build --config Release --parallelctest --test-dir Native/build -C Release --output-on-failureCross-compiling is not supported. Windows and Linux binaries come from CI.
Tests (CTest)
Section titled “Tests (CTest)”| Test | What it proves |
|---|---|
enet_exports | Loads the built library by path, the way .NET does, and resolves all 65 ENet-CSharp P/Invoke names |
enet_smoke | Linked version is 2.4.8; a reliable packet round trip over loopback (connect, send, receive, disconnect) |
mfrmlui_exports | Resolves every function declared in mfrmlui.h; the list is parsed from the header at configure time, currently 121 |
mfrmlui_smoke | A C11 client of the header (details below) |
mfmeshopt_smoke | ABI and library version; a flat grid collapses to two triangles, locked borders keep every border vertex, a bumpy grid with normals halves with a positive error; the vertex cache order keeps every index; out-of-range indices, bad counts and strides return 0 |
What mfrmlui_smoke exercises:
- Setup. A no-op counting render interface and an in-memory file interface. It loads a font and a data-bound document (scalar getter, dynamic array of structs, event callback), then updates and renders it.
- Checks.
- Geometry and the FreeType atlas callbacks.
TranslateString.- Element and attribute APIs.
- Input routing: consumed vs propagate, click, text input.
- Listener lifetime.
- Data-model dirtying.
- The debugger.
- Hot reload.
- Handle validation.
- On shutdown: every compiled geometry and texture is released, and no unexpected RmlUi errors or warnings were logged.
CI: .github/workflows/natives.yml
Section titled “CI: .github/workflows/natives.yml”- Triggers:
workflow_dispatch, and pull requests touchingNative/**,MainframeEngine/runtimes/**,.gitmodulesor the workflow itself. - Jobs:
buildis a matrix:macos-15: universal build, uploaded for both osx RIDs.windows-latest: win-x64.ubuntu-22.04: linux-x64. Each leg checks out with recursive submodules, builds, runs CTest, uploadsnatives-<name>(laid out asMainframeEngine/runtimes/<rid>/native/*) and writes the exports, dependencies and glibc level to the step summary.
collectmerges all RIDs intonatives-all:MainframeEngine/runtimes/**plus aNative/natives.lockstamped for exactly these binaries.verify-lockrunsNative/natives-lock.sh verifyagainst the committed tree.
- Symbols (G15.8, Crash reporting): every leg builds Release with debug info (
-O3 -g; MSVC/Zi+/DEBUG), thenbuild/split-native-symbols.shstrips the staged binaries (macOSdsymutil+strip -x, Linuxobjcopy --only-keep-debug+--strip-debug --add-gnu-debuglink, Windows the linker’s.pdb) and uploads the symbols asnative-symbols-<name>; the committed binaries stay stripped andnatives.lockrecords binaries only. Binaries committed before this change have no debug info until the workflow next runs. - Actions: only official ones (
actions/checkout,actions/upload-artifact,actions/download-artifact).
Native/natives.lock
Section titled “Native/natives.lock”Native builds are not bit-reproducible across toolchains, so CI cannot rebuild a binary and compare hashes. The lock records provenance instead:
component <enet|mfrmlui> inputs <sha256 over the component's build inputs + submodule commits>submodule <component> <path> <commit>binary <sha256> <component> <inputs hash it was built from> <path>- Build inputs.
- ENet:
Native/CMakeLists.txt,Native/ENet/CMakeLists.txtand the export lists. - mfrmlui:
Native/CMakeLists.txt,Native/RmlUi/CMakeLists.txt,include/andshim/. - mfmeshopt:
Native/CMakeLists.txt,Native/MeshOpt/CMakeLists.txt,include/,shim/and the meshoptimizer submodule commit. - Tests and docs are not inputs.
- ENet:
- What
verifyfails on:- A runtime binary of a known component that is not in the lock (files it has no component for, such as Valve’s
steam_api, are ignored). - A missing locked binary, or one whose sha256 has changed.
- A binary built from inputs that no longer match the tree, i.e. the sources changed but the binaries were not refreshed.
- A runtime binary of a known component that is not in the lock (files it has no component for, such as Valve’s
Refreshing the committed binaries
Section titled “Refreshing the committed binaries”After changing anything under Native/ (or bumping a submodule):
- Push the branch. A PR runs
natives.ymlautomatically; otherwise run it from the Actions tab withworkflow_dispatch. - When it is green, download
natives-allfrom the run:gh run download <run-id> -n natives-all -D natives-all. - Copy it over the repository root:
cp -R natives-all/MainframeEngine natives-all/Native .. - Run
Native/natives-lock.sh verify, then commitMainframeEngine/runtimesandNative/natives.lock.
The CI binaries are the canonical set, including the macOS ones. To iterate on macOS locally, use
Native/build.sh --stage. It restamps only the binaries it rebuilt, so verify-lock keeps flagging the other RIDs
until CI artifacts are committed.
Valve’s steam_api
Section titled “Valve’s steam_api”steam_api64.dll (win-x64), libsteam_api.so (linux-x64) and libsteam_api.dylib (osx-arm64 and osx-x64: one
universal x86_64 + arm64 file) are the Steamworks SDK’s redistributable_bin, the build Facepunch.Steamworks 2.4.1 was
made against. They are vendored binaries: natives.yml does not build them, they are not in natives.lock, and
natives-lock.sh ignores them (it has no component for them). Refresh them only together with
Plugins/Facepunch.Steamworks (same SDK version). See Steamworks → Natives.
Consuming the binaries from .NET
Section titled “Consuming the binaries from .NET”This is the managed lane’s job (csproj changes); the native layer only provides the files.
-
mfrmlui. The managed binding (MainframeEngine/Src/UI/Rml/, M8) uses[LibraryImport("mfrmlui")]and checksmfrmlui_abi_version()when the UI server starts (RmlCore.EnsureLibrary: a missing or incompatible library fails with a clearRmlException). Theruntimes/files are copied flat next to the app at build time. See Game UI. -
mfmeshopt.MeshSimplifier(MainframeEngine/Src/Rendering/Meshes/MeshSimplifier.cs, ADR 0256) uses[LibraryImport("mfmeshopt")], loads it once withNativeLibrary.TryLoadand checksmfmeshopt_abi_version(); a missing or incompatible library makesMeshSimplifier.IsAvailablefalse (the importer warns and skips generated LODs) instead of throwing during import. -
enet. TheENet-CSharppackage ships its own natives:- an x86_64-only
runtimes/osx/native/libenet.dylib, and build/ENet-CSharp.targets, which copiesenet.dll,enet.dylibandlibenet.sonext to the app.
Exclude those package assets (e.g.
ExcludeAssets="build;native"on thePackageReference) and ship ours fromMainframeEngine/runtimes/, or the package’s x86_64 dylib may win on Apple Silicon. Verify withNativeLibrary.TryLoad/ a run of any game (e.g. the Demo) on osx-arm64. - an x86_64-only
Licences
Section titled “Licences”- ENet and ENet-CSharp: MIT.
- RmlUi: MIT. Its bundled robin_hood/itlib are MIT, and the Courier Prime font in the Debugger is OFL.
- FreeType: FTL. Credit required: “Portions of this software are copyright © 2026 The FreeType Project (https://freetype.org). All rights reserved.” It must appear on the credits screen (M8 task list).
- FreeType’s bundled zlib: zlib licence.
- meshoptimizer (in
mfmeshopt): MIT, notice text reproduced. - Valve’s
steam_api: © Valve Corporation, redistributed under the Steamworks SDK Access Agreement (not MIT).
The RmlUi.Net attribution is in Native/RmlUi/shim/NOTICE.md.
Status
Section titled “Status”| RID | enet | mfrmlui | mfsvg | mfmeshopt |
|---|---|---|---|---|
| osx-arm64 / osx-x64 | ✅ committed (CI) | ✅ committed (CI) | ✅ committed (CI) | ✅ committed (CI) |
| win-x64 | ✅ committed (CI) | ✅ committed (CI) | ✅ committed (CI) | ✅ committed (CI) |
| linux-x64 | ✅ committed (CI) | ✅ committed (CI) | ✅ committed (CI) | ✅ committed (CI; glibc 2.34) |
natives-all also carries Valve’s steam_api files from the collect job’s checkout, which does not fetch Git LFS:
its steam_api64.dll is an LFS pointer. Restore that file (git checkout -- MainframeEngine/runtimes/win-x64/native/steam_api64.dll)
after copying the artifact in; the lock ignores it.
Related
Section titled “Related”Build & platforms · Networking · Game UI (RmlUi) · Networking