From 793258919b8380e115692d539500ab3cd95a27d9 Mon Sep 17 00:00:00 2001 From: Adam Scott Date: Thu, 12 Jun 2025 13:12:46 -0400 Subject: [PATCH] [Web] Fix Emscripten for WebXR and update minimum version --- .github/workflows/web_builds.yml | 2 +- modules/webxr/native/library_godot_webxr.js | 10 ++--- platform/web/detect.py | 44 +++++++++++++-------- platform/web/eslint.config.cjs | 2 +- 4 files changed, 35 insertions(+), 23 deletions(-) diff --git a/.github/workflows/web_builds.yml b/.github/workflows/web_builds.yml index 704c10d3ff5..4fab005eb65 100644 --- a/.github/workflows/web_builds.yml +++ b/.github/workflows/web_builds.yml @@ -9,7 +9,7 @@ env: tests=no debug_symbols=no use_closure_compiler=yes - EM_VERSION: 3.1.64 + EM_VERSION: 4.0.11 jobs: web-template: diff --git a/modules/webxr/native/library_godot_webxr.js b/modules/webxr/native/library_godot_webxr.js index b827cecf534..b56585653c9 100644 --- a/modules/webxr/native/library_godot_webxr.js +++ b/modules/webxr/native/library_godot_webxr.js @@ -29,7 +29,7 @@ /**************************************************************************/ const GodotWebXR = { - $GodotWebXR__deps: ['$Browser', '$GL', '$GodotRuntime', '$runtimeKeepalivePush', '$runtimeKeepalivePop'], + $GodotWebXR__deps: ['$MainLoop', '$GL', '$GodotRuntime', '$runtimeKeepalivePush', '$runtimeKeepalivePop'], $GodotWebXR: { gl: null, @@ -64,9 +64,9 @@ const GodotWebXR = { }, monkeyPatchRequestAnimationFrame: (enable) => { if (GodotWebXR.orig_requestAnimationFrame === null) { - GodotWebXR.orig_requestAnimationFrame = Browser.requestAnimationFrame; + GodotWebXR.orig_requestAnimationFrame = MainLoop.requestAnimationFrame; } - Browser.requestAnimationFrame = enable + MainLoop.requestAnimationFrame = enable ? GodotWebXR.requestAnimationFrame : GodotWebXR.orig_requestAnimationFrame; }, @@ -76,11 +76,11 @@ const GodotWebXR = { // enabled or disabled. When using the WebXR API Emulator, this // gets picked up automatically, however, in the Oculus Browser // on the Quest, we need to pause and resume the main loop. - Browser.mainLoop.pause(); + MainLoop.pause(); runtimeKeepalivePush(); window.setTimeout(function () { runtimeKeepalivePop(); - Browser.mainLoop.resume(); + MainLoop.resume(); }, 0); }, diff --git a/platform/web/detect.py b/platform/web/detect.py index e714837e194..49dc2c50f52 100644 --- a/platform/web/detect.py +++ b/platform/web/detect.py @@ -101,6 +101,21 @@ def library_emitter(target, source, env): def configure(env: "SConsEnvironment"): + env["CC"] = "emcc" + env["CXX"] = "em++" + + env["AR"] = "emar" + env["RANLIB"] = "emranlib" + + # Get version info for checks below. + cc_version = get_compiler_version(env) + cc_semver = (cc_version["major"], cc_version["minor"], cc_version["patch"]) + + # Minimum emscripten requirements. + if cc_semver < (4, 0, 0): + print_error("The minimum Emscripten version to build Godot is 4.0.0, detected: %s.%s.%s" % cc_semver) + sys.exit(255) + env.Append(LIBEMITTER=[library_emitter]) env["EXPORTED_FUNCTIONS"] = ["_main"] @@ -149,10 +164,15 @@ def configure(env: "SConsEnvironment"): env.Append(LINKFLAGS=["-Wl,--fatal-warnings"]) # LTO - if env["lto"] == "auto": # Enable LTO for production. env["lto"] = "thin" + if env["lto"] == "thin" and cc_semver < (4, 0, 9): + print_warning( + '"lto=thin" support requires Emscripten 4.0.9 (detected %s.%s.%s), using "lto=full" instead.' % cc_semver + ) + env["lto"] = "full" + if env["lto"] != "none": if env["lto"] == "thin": env.Append(CCFLAGS=["-flto=thin"]) @@ -175,6 +195,13 @@ def configure(env: "SConsEnvironment"): env.Append(LINKFLAGS=["-sSAFE_HEAP=1"]) # Closure compiler + if env["use_closure_compiler"] and cc_semver < (4, 0, 11): + print_warning( + '"use_closure_compiler=yes" support requires Emscripten 4.0.11 (detected %s.%s.%s), using "use_closure_compiler=no" instead.' + % cc_semver + ) + env["use_closure_compiler"] = False + if env["use_closure_compiler"]: # For emscripten support code. env.Append(LINKFLAGS=["--closure", "1"]) @@ -201,12 +228,6 @@ def configure(env: "SConsEnvironment"): # Add method for creating the final zip file env.AddMethod(create_template_zip, "CreateTemplateZip") - env["CC"] = "emcc" - env["CXX"] = "em++" - - env["AR"] = "emar" - env["RANLIB"] = "emranlib" - # Use TempFileMunge since some AR invocations are too long for cmd.exe. # Use POSIX-style paths, required with TempFileMunge. env["ARCOM_POSIX"] = env["ARCOM"].replace("$TARGET", "$TARGET.posix").replace("$SOURCES", "$SOURCES.posix") @@ -223,15 +244,6 @@ def configure(env: "SConsEnvironment"): env["LIBPREFIXES"] = ["$LIBPREFIX"] env["LIBSUFFIXES"] = ["$LIBSUFFIX"] - # Get version info for checks below. - cc_version = get_compiler_version(env) - cc_semver = (cc_version["major"], cc_version["minor"], cc_version["patch"]) - - # Minimum emscripten requirements. - if cc_semver < (3, 1, 62): - print_error("The minimum emscripten version to build Godot is 3.1.62, detected: %s.%s.%s" % cc_semver) - sys.exit(255) - env.Prepend(CPPPATH=["#platform/web"]) env.Append(CPPDEFINES=["WEB_ENABLED", "UNIX_ENABLED", "UNIX_SOCKET_UNAVAILABLE"]) diff --git a/platform/web/eslint.config.cjs b/platform/web/eslint.config.cjs index 4f51aec4cff..56a45367f00 100644 --- a/platform/web/eslint.config.cjs +++ b/platform/web/eslint.config.cjs @@ -11,7 +11,6 @@ if (process && process.env && process.env.npm_command && !fs.existsSync('./platf } const emscriptenGlobals = { - 'Browser': true, 'ERRNO_CODES': true, 'FS': true, 'GL': true, @@ -22,6 +21,7 @@ const emscriptenGlobals = { 'HEAPU32': true, 'IDBFS': true, 'LibraryManager': true, + 'MainLoop': true, 'Module': true, 'UTF8ToString': true, 'UTF8Decoder': true,