Skip to content

Commit d9cda33

Browse files
committed
Merge pull request #107415 from adamscott/add-emscripten-version-to-log-header
[Web] Add Web-build specific stdout header
2 parents 4c5c577 + f411c5b commit d9cda33

File tree

9 files changed

+99
-3
lines changed

9 files changed

+99
-3
lines changed

core/os/os.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -591,15 +591,20 @@ bool OS::has_feature(const String &p_feature) {
591591
}
592592
#endif
593593

594-
#ifdef THREADS_ENABLED
595594
if (p_feature == "threads") {
595+
#ifdef THREADS_ENABLED
596596
return true;
597-
}
598597
#else
598+
return false;
599+
#endif
600+
}
599601
if (p_feature == "nothreads") {
602+
#ifdef THREADS_ENABLED
603+
return false;
604+
#else
600605
return true;
601-
}
602606
#endif
607+
}
603608

604609
if (_check_internal_feature_support(p_feature)) {
605610
return true;

platform/web/SCsub

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ sys_env.AddJSLibraries(
4040
[
4141
"js/libs/library_godot_audio.js",
4242
"js/libs/library_godot_display.js",
43+
"js/libs/library_godot_emscripten.js",
4344
"js/libs/library_godot_fetch.js",
4445
"js/libs/library_godot_webmidi.js",
4546
"js/libs/library_godot_os.js",

platform/web/detect.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ def configure(env: "SConsEnvironment"):
276276
print_warning("GDExtension support requires proxy_to_pthread=no, disabling proxy to pthread.")
277277
env["proxy_to_pthread"] = False
278278

279+
env.Append(CPPDEFINES=["WEB_DLINK_ENABLED"])
279280
env.Append(CCFLAGS=["-sSIDE_MODULE=2"])
280281
env.Append(LINKFLAGS=["-sSIDE_MODULE=2"])
281282
env.Append(CCFLAGS=["-fvisibility=hidden"])

platform/web/eslint.config.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const emscriptenGlobals = {
2929
'_free': true,
3030
'_malloc': true,
3131
'autoAddDeps': true,
32+
'addToLibrary': true,
3233
'addOnPostRun': true,
3334
'getValue': true,
3435
'lengthBytesUTF8': true,

platform/web/export/export_plugin.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,11 @@ void EditorExportPlatformWeb::get_preset_features(const Ref<EditorExportPreset>
353353
} else {
354354
r_features->push_back("nothreads");
355355
}
356+
if (p_preset->get("variant/extensions_support").operator bool()) {
357+
r_features->push_back("web_extensions");
358+
} else {
359+
r_features->push_back("web_noextensions");
360+
}
356361
r_features->push_back("wasm32");
357362
}
358363

platform/web/godot_js.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
extern "C" {
3939
#endif
4040

41+
// Emscripten
42+
extern char *godot_js_emscripten_get_version();
43+
4144
// Config
4245
extern void godot_js_config_locale_get(char *p_ptr, int p_ptr_max);
4346
extern void godot_js_config_canvas_id_get(char *p_ptr, int p_ptr_max);
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**************************************************************************/
2+
/* library_godot_emscripten.js */
3+
/**************************************************************************/
4+
/* This file is part of: */
5+
/* GODOT ENGINE */
6+
/* https://godotengine.org */
7+
/**************************************************************************/
8+
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9+
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10+
/* */
11+
/* Permission is hereby granted, free of charge, to any person obtaining */
12+
/* a copy of this software and associated documentation files (the */
13+
/* "Software"), to deal in the Software without restriction, including */
14+
/* without limitation the rights to use, copy, modify, merge, publish, */
15+
/* distribute, sublicense, and/or sell copies of the Software, and to */
16+
/* permit persons to whom the Software is furnished to do so, subject to */
17+
/* the following conditions: */
18+
/* */
19+
/* The above copyright notice and this permission notice shall be */
20+
/* included in all copies or substantial portions of the Software. */
21+
/* */
22+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23+
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24+
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25+
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26+
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27+
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28+
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29+
/**************************************************************************/
30+
31+
const GodotEmscripten = {
32+
$GodotEmscripten__deps: ['$GodotRuntime'],
33+
$GodotEmscripten: {},
34+
35+
godot_js_emscripten_get_version__proxy: 'sync',
36+
godot_js_emscripten_get_version__sig: 'p',
37+
godot_js_emscripten_get_version: function () {
38+
// WARNING: The caller needs to free the string pointer.
39+
const emscriptenVersionPtr = GodotRuntime.allocString('{{{ EMSCRIPTEN_VERSION }}}');
40+
return emscriptenVersionPtr;
41+
},
42+
};
43+
autoAddDeps(GodotEmscripten, '$GodotEmscripten');
44+
addToLibrary(GodotEmscripten);

platform/web/os_web.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,22 @@ bool OS_Web::_check_internal_feature_support(const String &p_feature) {
160160
if (p_feature == "web") {
161161
return true;
162162
}
163+
164+
if (p_feature == "web_extensions") {
165+
#ifdef WEB_DLINK_ENABLED
166+
return true;
167+
#else
168+
return false;
169+
#endif
170+
}
171+
if (p_feature == "web_noextensions") {
172+
#ifdef WEB_DLINK_ENABLED
173+
return false;
174+
#else
175+
return true;
176+
#endif
177+
}
178+
163179
if (godot_js_os_has_feature(p_feature.utf8().get_data())) {
164180
return true;
165181
}

platform/web/web_main.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,24 @@ void main_loop_callback() {
104104
}
105105
}
106106

107+
void print_web_header() {
108+
// Emscripten.
109+
char *emscripten_version_char = godot_js_emscripten_get_version();
110+
String emscripten_version = vformat("Emscripten %s", emscripten_version_char);
111+
memfree(emscripten_version_char);
112+
113+
// Build features.
114+
String thread_support = OS::get_singleton()->has_feature("threads")
115+
? "multi-threaded"
116+
: "single-threaded";
117+
String extensions_support = OS::get_singleton()->has_feature("web_extensions")
118+
? "GDExtension support"
119+
: "no GDExtension support";
120+
121+
Vector<String> build_configuration = { emscripten_version, thread_support, extensions_support };
122+
print_line(vformat("Build configuration: %s.", String(", ").join(build_configuration)));
123+
}
124+
107125
/// When calling main, it is assumed FS is setup and synced.
108126
extern EMSCRIPTEN_KEEPALIVE int godot_web_main(int argc, char *argv[]) {
109127
os = new OS_Web();
@@ -128,6 +146,8 @@ extern EMSCRIPTEN_KEEPALIVE int godot_web_main(int argc, char *argv[]) {
128146
return EXIT_FAILURE;
129147
}
130148

149+
print_web_header();
150+
131151
main_started = true;
132152

133153
// Ease up compatibility.

0 commit comments

Comments
 (0)