2024-02-14 14:32:27 +00:00
|
|
|
import common_compiler_flags
|
2023-09-20 08:08:09 +00:00
|
|
|
from SCons.Util import WhereIs
|
2022-06-06 13:09:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
def exists(env):
|
2023-09-20 08:08:09 +00:00
|
|
|
return WhereIs("emcc") is not None
|
2022-06-06 13:09:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
def generate(env):
|
|
|
|
if env["arch"] not in ("wasm32"):
|
|
|
|
print("Only wasm32 supported on web. Exiting.")
|
2023-09-09 08:55:53 +00:00
|
|
|
env.Exit(1)
|
2022-06-06 13:09:32 +00:00
|
|
|
|
2023-10-15 10:01:45 +00:00
|
|
|
# Emscripten toolchain
|
2022-06-06 13:09:32 +00:00
|
|
|
env["CC"] = "emcc"
|
|
|
|
env["CXX"] = "em++"
|
|
|
|
env["AR"] = "emar"
|
|
|
|
env["RANLIB"] = "emranlib"
|
2023-10-15 10:01:45 +00:00
|
|
|
|
2022-06-06 13:09:32 +00:00
|
|
|
# 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")
|
|
|
|
env["ARCOM"] = "${TEMPFILE(ARCOM_POSIX)}"
|
|
|
|
|
2023-10-15 10:01:45 +00:00
|
|
|
# All intermediate files are just object files.
|
|
|
|
env["OBJSUFFIX"] = ".o"
|
|
|
|
env["SHOBJSUFFIX"] = ".o"
|
|
|
|
|
|
|
|
# Static libraries clang-style.
|
|
|
|
env["LIBPREFIX"] = "lib"
|
|
|
|
env["LIBSUFFIX"] = ".a"
|
|
|
|
|
|
|
|
# Shared library as wasm.
|
|
|
|
env["SHLIBSUFFIX"] = ".wasm"
|
|
|
|
|
2023-09-20 08:08:09 +00:00
|
|
|
# Thread support (via SharedArrayBuffer).
|
2024-04-30 17:06:51 +00:00
|
|
|
if env["threads"]:
|
2024-06-13 23:42:39 +00:00
|
|
|
env.Append(CCFLAGS=["-sUSE_PTHREADS=1"])
|
|
|
|
env.Append(LINKFLAGS=["-sUSE_PTHREADS=1"])
|
2023-09-20 08:08:09 +00:00
|
|
|
|
2023-10-15 10:01:45 +00:00
|
|
|
# Build as side module (shared library).
|
2024-08-24 09:56:27 +00:00
|
|
|
env.Append(CCFLAGS=["-sSIDE_MODULE=1"])
|
2024-06-13 23:42:39 +00:00
|
|
|
env.Append(LINKFLAGS=["-sSIDE_MODULE=1"])
|
|
|
|
|
|
|
|
# Force wasm longjmp mode.
|
|
|
|
env.Append(CCFLAGS=["-sSUPPORT_LONGJMP='wasm'"])
|
|
|
|
env.Append(LINKFLAGS=["-sSUPPORT_LONGJMP='wasm'"])
|
2022-06-06 13:09:32 +00:00
|
|
|
|
2023-07-22 12:46:14 +00:00
|
|
|
env.Append(CPPDEFINES=["WEB_ENABLED", "UNIX_ENABLED"])
|
2024-02-14 14:32:27 +00:00
|
|
|
|
2024-09-21 10:52:50 +00:00
|
|
|
# Refer to https://github.com/godotengine/godot/blob/master/platform/web/detect.py
|
|
|
|
if env["lto"] == "auto":
|
|
|
|
env["lto"] = "full"
|
|
|
|
|
2024-02-14 14:32:27 +00:00
|
|
|
common_compiler_flags.generate(env)
|