module Docs::B_COMPILATION_AND_BUILD

Overview

B. Compilation, Linking & Build System

LibGodot connects three different compilation layers into a unified build system:

  1. C++ GDExtension Loader Bridge (src/bridge/crystal_bridge.cpp)
  2. Crystal Game / Test / Example DLLs (game.dll)
  3. Godot Engine Dynamic Library (libgodot.dll)

1. Compiling the C++ Loader Bridge (crystal_bridge.dll)

The bridge is compiled with MinGW-w64 g++ (or MSVC / clang) into bin/crystal_bridge.dll:

g++ -shared -O3 src/bridge/crystal_bridge.cpp -o bin/crystal_bridge.dll -lgc

Why is a separate loader bridge required?


2. The Shadow Copying Reload Mechanism

Under Windows, when a process loads a DLL via LoadLibraryA, the operating system places an exclusive shared-read lock on the file. Any attempt by the Crystal compiler to overwrite game.dll while Godot is open results in:

Error: Access is denied. (ERROR_SHARING_VIOLATION / Windows error 32)

To solve this, crystal_bridge.cpp implements Shadow Copy Loading in development mode:

  1. When crystal_bridge.dll initializes, it checks for LIBGODOT_RELEASE. If absent, shadow loading is enabled.
  2. Before loading bin/game.dll, the bridge copies bin/game.dll to: bin/game_loaded_<PID>_<TIMESTAMP>.dll
  3. The bridge calls LoadLibraryA on the shadow copy, leaving bin/game.dll unlocked!
  4. The Crystal compiler can now freely rebuild bin/game.dll at any time while the Godot editor is still running.
  5. Old shadow copies from terminated processes are automatically pruned at startup.

In release builds (LIBGODOT_RELEASE=1), shadow copying is disabled to eliminate disk I/O.


3. Compiling Crystal Game Code (game.dll)

Crystal compiles user nodes into a dynamic library via:

crystal build --cross-compile --link-flags="-shared" src/main.cr -o bin/game.dll

Crystal exports two primary C-ABI entry points:


4. Editor Build Hook (EditorPlugin._build)

The Godot editor plugin located at addons/crystal_integration/crystal_integration.gd intercepts Godot's build pipeline:


5. Build System Synchronization (make all)

The root Makefile orchestrates compilation across the entire workspace:

Rule: Always execute make all rather than partial builds to guarantee all consumer directories and bridge DLLs remain synchronized.

Defined in:

libgodot/docs.cr

Class Method Summary

Class Method Detail

def self.rules : Array(String) #

Dummy method for documentation visibility


[View source]