Merge pull request #110863 from kisg/libgodot_migeran_core

LibGodot: Core - Build Godot Engine as a Library
This commit is contained in:
Thaddeus Crews
2025-10-08 13:56:34 -05:00
23 changed files with 752 additions and 16 deletions

View File

@@ -21,7 +21,6 @@ files = [
"godot_window_delegate.mm",
"godot_window.mm",
"key_mapping_macos.mm",
"godot_main_macos.mm",
"godot_menu_delegate.mm",
"godot_menu_item.mm",
"godot_open_save_delegate.mm",
@@ -39,7 +38,17 @@ if env.editor_build:
"editor/embedded_process_macos.mm",
]
prog = env.add_program("#bin/godot", files)
if env["library_type"] == "executable":
files += ["godot_main_macos.mm"]
else:
files += ["libgodot_macos.mm"]
if env["library_type"] == "static_library":
prog = env.add_library("#bin/godot", files)
elif env["library_type"] == "shared_library":
prog = env.add_shared_library("#bin/godot", files)
else:
prog = env.add_program("#bin/godot", files)
if env["debug_symbols"] and env["separate_debug_symbols"]:
env.AddPostAction(prog, env.Run(platform_macos_builders.make_debug_macos))

View File

@@ -61,7 +61,7 @@ def get_flags():
"arch": detect_arch(),
"use_volk": False,
"metal": True,
"supported": ["metal", "mono"],
"supported": ["library", "metal", "mono"],
}
@@ -172,8 +172,9 @@ def configure(env: "SConsEnvironment"):
env.Append(CCFLAGS=["-fsanitize=thread"])
env.Append(LINKFLAGS=["-fsanitize=thread"])
env.Append(LINKFLAGS=["-Wl,-stack_size," + hex(STACK_SIZE_SANITIZERS)])
else:
if env["library_type"] == "executable":
env.Append(LINKFLAGS=["-Wl,-stack_size," + hex(STACK_SIZE_SANITIZERS)])
elif env["library_type"] == "executable":
env.Append(LINKFLAGS=["-Wl,-stack_size," + hex(STACK_SIZE)])
if env["use_coverage"]:

View File

@@ -0,0 +1,74 @@
/**************************************************************************/
/* libgodot_macos.mm */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "core/extension/libgodot.h"
#include "core/extension/godot_instance.h"
#include "main/main.h"
#include "os_macos.h"
static OS_MacOS *os = nullptr;
static GodotInstance *instance = nullptr;
GDExtensionObjectPtr libgodot_create_godot_instance(int p_argc, char *p_argv[], GDExtensionInitializationFunction p_init_func) {
ERR_FAIL_COND_V_MSG(instance != nullptr, nullptr, "Only one Godot Instance may be created.");
uint32_t remaining_args = p_argc - 1;
os = new OS_MacOS_NSApp(p_argv[0], remaining_args, remaining_args > 0 ? &p_argv[1] : nullptr);
@autoreleasepool {
Error err = Main::setup(p_argv[0], remaining_args, remaining_args > 0 ? &p_argv[1] : nullptr, false);
if (err != OK) {
return nullptr;
}
instance = memnew(GodotInstance);
if (!instance->initialize(p_init_func)) {
memdelete(instance);
instance = nullptr;
return nullptr;
}
return (GDExtensionObjectPtr)instance;
}
}
void libgodot_destroy_godot_instance(GDExtensionObjectPtr p_godot_instance) {
GodotInstance *godot_instance = (GodotInstance *)p_godot_instance;
if (instance == godot_instance) {
godot_instance->stop();
memdelete(godot_instance);
// Note: When Godot Engine supports reinitialization, clear the instance pointer here.
//instance = nullptr;
Main::cleanup();
}
}