Skip to content

Native libraries

How the engine’s own native libraries are laid out, built, tested, shipped and refreshed.

LibraryBuilt fromP/Invoke nameFiles
ENetNative/ENet/upstream: nxrighthere/ENet-CSharp submodule, tag 2.4.8enet (ENet-CSharp 2.4.8)enet.dll, libenet.so, libenet.dylib
RmlUi shimNative/RmlUi: in-house C ABI over RmlUi 6.3 + FreeType 2.14.3mfrmluimfrmlui.dll, libmfrmlui.so, libmfrmlui.dylib
SVG rasteriserNative/Svg: in-house C ABI over ThorVG 1.0.3 (Godot 4.7.2’s vendored copy, PNG loader off; ADR 0112)mfsvgmfsvg.dll, libmfsvg.so, libmfsvg.dylib
Mesh simplifierNative/MeshOpt: in-house C ABI over meshoptimizer 1.3 (submodule; ADR 0256), for generated LODsmfmeshoptmfmeshopt.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).

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)
macOSWindowsLinux
ToolchainApple clang, NinjaMSVC, newest Visual Studio generator, -A x64GCC on ubuntu-22.04, Ninja
Architectureuniversal arm64;x86_64x64x86_64
Minimum OS / runtimemacOS 11.0static 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>.dylibn/alib<name>.so (no version suffix)
  • Visibility. Everything linked into mfrmlui is 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-conversion on clang/gcc and /W4 /permissive- on MSVC, as errors. -DMF_NATIVES_WERROR=OFF turns 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.
  • 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.

Requirements: CMake ≥ 3.25, Ninja (optional; brew install cmake ninja), a C/C++20 compiler, and the submodules:

Terminal window
git submodule update --init --recursive Native

macOS / Linux, using the helper (universal on macOS):

Terminal window
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 lock
Native/build.sh -DMF_NATIVES_RMLUI=OFF # extra CMake arguments are passed through

Or with plain CMake:

Terminal window
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 only
cmake --build Native/build
ctest --test-dir Native/build --output-on-failure

You 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):

Terminal window
cmake -S Native -B Native/build -A x64
cmake --build Native/build --config Release --parallel
ctest --test-dir Native/build -C Release --output-on-failure

Cross-compiling is not supported. Windows and Linux binaries come from CI.

TestWhat it proves
enet_exportsLoads the built library by path, the way .NET does, and resolves all 65 ENet-CSharp P/Invoke names
enet_smokeLinked version is 2.4.8; a reliable packet round trip over loopback (connect, send, receive, disconnect)
mfrmlui_exportsResolves every function declared in mfrmlui.h; the list is parsed from the header at configure time, currently 121
mfrmlui_smokeA C11 client of the header (details below)
mfmeshopt_smokeABI 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.
  • Triggers: workflow_dispatch, and pull requests touching Native/**, MainframeEngine/runtimes/**, .gitmodules or the workflow itself.
  • Jobs:
    • build is 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, uploads natives-<name> (laid out as MainframeEngine/runtimes/<rid>/native/*) and writes the exports, dependencies and glibc level to the step summary.
    • collect merges all RIDs into natives-all: MainframeEngine/runtimes/** plus a Native/natives.lock stamped for exactly these binaries.
    • verify-lock runs Native/natives-lock.sh verify against the committed tree.
  • Symbols (G15.8, Crash reporting): every leg builds Release with debug info (-O3 -g; MSVC /Zi + /DEBUG), then build/split-native-symbols.sh strips the staged binaries (macOS dsymutil + strip -x, Linux objcopy --only-keep-debug + --strip-debug --add-gnu-debuglink, Windows the linker’s .pdb) and uploads the symbols as native-symbols-<name>; the committed binaries stay stripped and natives.lock records 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 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.txt and the export lists.
    • mfrmlui: Native/CMakeLists.txt, Native/RmlUi/CMakeLists.txt, include/ and shim/.
    • mfmeshopt: Native/CMakeLists.txt, Native/MeshOpt/CMakeLists.txt, include/, shim/ and the meshoptimizer submodule commit.
    • Tests and docs are not inputs.
  • What verify fails 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.

After changing anything under Native/ (or bumping a submodule):

  1. Push the branch. A PR runs natives.yml automatically; otherwise run it from the Actions tab with workflow_dispatch.
  2. When it is green, download natives-all from the run: gh run download <run-id> -n natives-all -D natives-all.
  3. Copy it over the repository root: cp -R natives-all/MainframeEngine natives-all/Native ..
  4. Run Native/natives-lock.sh verify, then commit MainframeEngine/runtimes and Native/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.

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.

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 checks mfrmlui_abi_version() when the UI server starts (RmlCore.EnsureLibrary: a missing or incompatible library fails with a clear RmlException). The runtimes/ 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 with NativeLibrary.TryLoad and checks mfmeshopt_abi_version(); a missing or incompatible library makes MeshSimplifier.IsAvailable false (the importer warns and skips generated LODs) instead of throwing during import.

  • enet. The ENet-CSharp package ships its own natives:

    • an x86_64-only runtimes/osx/native/libenet.dylib, and
    • build/ENet-CSharp.targets, which copies enet.dll, enet.dylib and libenet.so next to the app.

    Exclude those package assets (e.g. ExcludeAssets="build;native" on the PackageReference) and ship ours from MainframeEngine/runtimes/, or the package’s x86_64 dylib may win on Apple Silicon. Verify with NativeLibrary.TryLoad / a run of any game (e.g. the Demo) on osx-arm64.

See THIRD_PARTY_NOTICES.md:

  • 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.

RIDenetmfrmluimfsvgmfmeshopt
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.

Build & platforms · Networking · Game UI (RmlUi) · Networking