LibGodot: Core - Build Godot Engine as a Library by kisg · Pull Request #110863 · godotengine/godot

2 min read Original article ↗

Excellent job so far! This is obviously something that has been in the works for a looong time.

The buildsystem side of things is mostly accounted for, but there's a few things that need tweaking. Most notably: we shouldn't be hardcoding the platforms which support compiling as a library. This information can be conveyed through the "supports" flag that platforms can pass. As this is a more involved change, I've opted to put this implementation specifically in a dedicated diff:

diff
 SConstruct                  | 14 +++++++-------
 platform/linuxbsd/detect.py |  2 +-
 platform/macos/detect.py    |  2 +-
 platform/windows/detect.py  |  2 +-
 4 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/SConstruct b/SConstruct
index 4ccf237cc8..326b4ab88a 100644
--- a/SConstruct
+++ b/SConstruct
@@ -356,13 +356,6 @@ if not env["platform"]:
     if env["platform"]:
         print(f"Automatically detected platform: {env['platform']}")
 
-# Library Support
-if env["library_type"] != "executable":
-    if env["platform"] not in ["linuxbsd", "macos", "windows"]:
-        print_error(f"Library builds not yet supported for {env['platform']}")
-        Exit(255)
-    env.Append(CPPDEFINES=["LIBGODOT_ENABLED"])
-
 # Deprecated aliases kept for compatibility.
 if env["platform"] in compatibility_platform_aliases:
     alias = env["platform"]
@@ -571,6 +564,13 @@ if not env["deprecated"]:
 if env["precision"] == "double":
     env.Append(CPPDEFINES=["REAL_T_IS_DOUBLE"])
 
+# Library Support
+if env["library_type"] != "executable":
+    if "library" not in env.get("supported", []):
+        print_error(f"Library builds unsupported for {env['platform']}")
+        Exit(255)
+    env.Append(CPPDEFINES=["LIBGODOT_ENABLED"])
+
 # Default num_jobs to local cpu count if not user specified.
 # SCons has a peculiarity where user-specified options won't be overridden
 # by SetOption, so we can rely on this to know if we should use our default.
diff --git a/platform/linuxbsd/detect.py b/platform/linuxbsd/detect.py
index 5f929c5925..03fdddd5de 100644
--- a/platform/linuxbsd/detect.py
+++ b/platform/linuxbsd/detect.py
@@ -67,7 +67,7 @@ def get_doc_path():
 def get_flags():
     return {
         "arch": detect_arch(),
-        "supported": ["mono"],
+        "supported": ["library", "mono"],
     }
 
 
diff --git a/platform/macos/detect.py b/platform/macos/detect.py
index 9873233baa..c5846c34a1 100644
--- a/platform/macos/detect.py
+++ b/platform/macos/detect.py
@@ -61,7 +61,7 @@ def get_flags():
         "arch": detect_arch(),
         "use_volk": False,
         "metal": True,
-        "supported": ["metal", "mono"],
+        "supported": ["library", "metal", "mono"],
     }
 
 
diff --git a/platform/windows/detect.py b/platform/windows/detect.py
index d5a8eb5f85..973be3e6b2 100644
--- a/platform/windows/detect.py
+++ b/platform/windows/detect.py
@@ -233,7 +233,7 @@ def get_flags():
 
     return {
         "arch": arch,
-        "supported": ["d3d12", "dcomp", "mono", "xaudio2"],
+        "supported": ["d3d12", "dcomp", "library", "mono", "xaudio2"],
     }
 
 

Everything else is covered in the following suggestions