This commit is contained in:
Spartan322
2025-06-20 02:38:24 -04:00
699 changed files with 21288 additions and 9565 deletions

View File

@@ -40,6 +40,7 @@ sys_env.AddJSLibraries(
[
"js/libs/library_godot_audio.js",
"js/libs/library_godot_display.js",
"js/libs/library_godot_emscripten.js",
"js/libs/library_godot_fetch.js",
"js/libs/library_godot_webmidi.js",
"js/libs/library_godot_os.js",

View File

@@ -1,5 +1,6 @@
import os
import sys
from pathlib import Path
from typing import TYPE_CHECKING
from emscripten_helpers import (
@@ -115,6 +116,14 @@ def configure(env: "SConsEnvironment"):
print_error("Initial memory must be a valid integer")
sys.exit(255)
# Add Emscripten to the included paths (for compile_commands.json completion)
emcc_path = Path(str(WhereIs("emcc")))
while emcc_path.is_symlink():
# For some reason, mypy trips on `Path.readlink` not being defined, somehow.
emcc_path = emcc_path.readlink() # type: ignore[attr-defined]
emscripten_include_path = emcc_path.parent.joinpath("cache", "sysroot", "include")
env.Append(CPPPATH=[emscripten_include_path])
## Build type
if env.debug_features:
@@ -247,7 +256,7 @@ def configure(env: "SConsEnvironment"):
env.Append(CCFLAGS=["-sUSE_PTHREADS=1"])
env.Append(LINKFLAGS=["-sUSE_PTHREADS=1"])
env.Append(LINKFLAGS=["-sDEFAULT_PTHREAD_STACK_SIZE=%sKB" % env["default_pthread_stack_size"]])
env.Append(LINKFLAGS=["-sPTHREAD_POOL_SIZE='Module[\"emscriptenPoolSize\"]||8'"])
env.Append(LINKFLAGS=["-sPTHREAD_POOL_SIZE=\"Module['emscriptenPoolSize']||8\""])
env.Append(LINKFLAGS=["-sWASM_MEM_MAX=2048MB"])
if not env["dlink_enabled"]:
# Workaround https://github.com/emscripten-core/emscripten/issues/21844#issuecomment-2116936414.
@@ -267,6 +276,7 @@ def configure(env: "SConsEnvironment"):
print_warning("GDExtension support requires proxy_to_pthread=no, disabling proxy to pthread.")
env["proxy_to_pthread"] = False
env.Append(CPPDEFINES=["WEB_DLINK_ENABLED"])
env.Append(CCFLAGS=["-sSIDE_MODULE=2"])
env.Append(LINKFLAGS=["-sSIDE_MODULE=2"])
env.Append(CCFLAGS=["-fvisibility=hidden"])

View File

@@ -29,6 +29,7 @@ const emscriptenGlobals = {
'_free': true,
'_malloc': true,
'autoAddDeps': true,
'addToLibrary': true,
'addOnPostRun': true,
'getValue': true,
'lengthBytesUTF8': true,

View File

@@ -355,6 +355,11 @@ void EditorExportPlatformWeb::get_preset_features(const Ref<EditorExportPreset>
} else {
r_features->push_back("nothreads");
}
if (p_preset->get("variant/extensions_support").operator bool()) {
r_features->push_back("web_extensions");
} else {
r_features->push_back("web_noextensions");
}
r_features->push_back("wasm32");
}

View File

@@ -40,6 +40,9 @@
extern "C" {
#endif
// Emscripten
extern char *godot_js_emscripten_get_version();
// Config
extern void godot_js_config_locale_get(char *p_ptr, int p_ptr_max);
extern void godot_js_config_canvas_id_get(char *p_ptr, int p_ptr_max);

View File

@@ -0,0 +1,46 @@
/**************************************************************************/
/* library_godot_emscripten.js */
/**************************************************************************/
/* This file is part of: */
/* REDOT ENGINE */
/* https://redotengine.org */
/**************************************************************************/
/* Copyright (c) 2024-present Redot Engine contributors */
/* (see REDOT_AUTHORS.md) */
/* 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. */
/**************************************************************************/
const GodotEmscripten = {
$GodotEmscripten__deps: ['$GodotRuntime'],
$GodotEmscripten: {},
godot_js_emscripten_get_version__proxy: 'sync',
godot_js_emscripten_get_version__sig: 'p',
godot_js_emscripten_get_version: function () {
// WARNING: The caller needs to free the string pointer.
const emscriptenVersionPtr = GodotRuntime.allocString('{{{ EMSCRIPTEN_VERSION }}}');
return emscriptenVersionPtr;
},
};
autoAddDeps(GodotEmscripten, '$GodotEmscripten');
addToLibrary(GodotEmscripten);

View File

@@ -162,6 +162,22 @@ bool OS_Web::_check_internal_feature_support(const String &p_feature) {
if (p_feature == "web") {
return true;
}
if (p_feature == "web_extensions") {
#ifdef WEB_DLINK_ENABLED
return true;
#else
return false;
#endif
}
if (p_feature == "web_noextensions") {
#ifdef WEB_DLINK_ENABLED
return false;
#else
return true;
#endif
}
if (godot_js_os_has_feature(p_feature.utf8().get_data())) {
return true;
}

View File

@@ -106,6 +106,24 @@ void main_loop_callback() {
}
}
void print_web_header() {
// Emscripten.
char *emscripten_version_char = godot_js_emscripten_get_version();
String emscripten_version = vformat("Emscripten %s", emscripten_version_char);
memfree(emscripten_version_char);
// Build features.
String thread_support = OS::get_singleton()->has_feature("threads")
? "multi-threaded"
: "single-threaded";
String extensions_support = OS::get_singleton()->has_feature("web_extensions")
? "GDExtension support"
: "no GDExtension support";
Vector<String> build_configuration = { emscripten_version, thread_support, extensions_support };
print_line(vformat("Build configuration: %s.", String(", ").join(build_configuration)));
}
/// When calling main, it is assumed FS is setup and synced.
extern EMSCRIPTEN_KEEPALIVE int godot_web_main(int argc, char *argv[]) {
os = new OS_Web();
@@ -130,6 +148,8 @@ extern EMSCRIPTEN_KEEPALIVE int godot_web_main(int argc, char *argv[]) {
return EXIT_FAILURE;
}
print_web_header();
main_started = true;
// Ease up compatibility.