From 9b4c5f056220b55cfe2e33f2758a6579dda62c24 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Tue, 30 Apr 2024 19:06:51 +0200 Subject: [PATCH] [SCons] Add option to build without threads This is relevant for the Web platform, where builds with and without threads are incompatible. (cherry picked from commit b0296bb562af0ff812b732586c06ae6b3f96ef84) --- test/project/example.gdextension | 16 ++++++++++++++-- tools/godotcpp.py | 7 +++++++ tools/web.py | 5 +++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/test/project/example.gdextension b/test/project/example.gdextension index 30279e6d..93872c5a 100644 --- a/test/project/example.gdextension +++ b/test/project/example.gdextension @@ -21,5 +21,17 @@ android.debug.x86_64 = "res://bin/libgdexample.android.template_debug.x86_64.so" android.release.x86_64 = "res://bin/libgdexample.android.template_release.x86_64.so" android.debug.arm64 = "res://bin/libgdexample.android.template_debug.arm64.so" android.release.arm64 = "res://bin/libgdexample.android.template_release.arm64.so" -web.debug.wasm32 = "res://bin/libgdexample.web.template_debug.wasm32.wasm" -web.release.wasm32 = "res://bin/libgdexample.web.template_release.wasm32.wasm" +ios.debug = "res://bin/libgdexample.ios.template_debug.xcframework" +ios.release = "res://bin/libgdexample.ios.template_release.xcframework" +web.debug.threads.wasm32 = "res://bin/libgdexample.web.template_debug.wasm32.wasm" +web.release.threads.wasm32 = "res://bin/libgdexample.web.template_release.wasm32.wasm" +web.debug.wasm32 = "res://bin/libgdexample.web.template_debug.wasm32.nothreads.wasm" +web.release.wasm32 = "res://bin/libgdexample.web.template_release.wasm32.nothreads.wasm" + +[dependencies] +ios.debug = { + "res://bin/libgodot-cpp.ios.template_debug.xcframework": "" +} +ios.release = { + "res://bin/libgodot-cpp.ios.template_release.xcframework": "" +} diff --git a/tools/godotcpp.py b/tools/godotcpp.py index cc2b02fe..e16b17dc 100644 --- a/tools/godotcpp.py +++ b/tools/godotcpp.py @@ -267,6 +267,8 @@ def options(opts, env): ) ) + opts.Add(BoolVariable(key="threads", help="Enable threading support", default=env.get("threads", True))) + # compiledb opts.Add( BoolVariable( @@ -396,6 +398,9 @@ def generate(env): tool.generate(env) + if env["threads"]: + env.Append(CPPDEFINES=["THREADS_ENABLED"]) + if env.editor_build: env.Append(CPPDEFINES=["TOOLS_ENABLED"]) @@ -436,6 +441,8 @@ def generate(env): suffix += "." + env["arch"] if env["ios_simulator"]: suffix += ".simulator" + if not env["threads"]: + suffix += ".nothreads" env["suffix"] = suffix # Exposed when included from another project env["OBJSUFFIX"] = suffix + env["OBJSUFFIX"] diff --git a/tools/web.py b/tools/web.py index 79b4b24c..8953325c 100644 --- a/tools/web.py +++ b/tools/web.py @@ -34,8 +34,9 @@ def generate(env): env["SHLIBSUFFIX"] = ".wasm" # Thread support (via SharedArrayBuffer). - env.Append(CCFLAGS=["-s", "USE_PTHREADS=1"]) - env.Append(LINKFLAGS=["-s", "USE_PTHREADS=1"]) + if env["threads"]: + env.Append(CCFLAGS=["-s", "USE_PTHREADS=1"]) + env.Append(LINKFLAGS=["-s", "USE_PTHREADS=1"]) # Build as side module (shared library). env.Append(CPPFLAGS=["-s", "SIDE_MODULE=1"])