web.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import common_compiler_flags
  2. from SCons.Util import WhereIs
  3. def exists(env):
  4. return WhereIs("emcc") is not None
  5. def generate(env):
  6. if env["arch"] not in ("wasm32"):
  7. print("Only wasm32 supported on web. Exiting.")
  8. env.Exit(1)
  9. # Emscripten toolchain
  10. env["CC"] = "emcc"
  11. env["CXX"] = "em++"
  12. env["AR"] = "emar"
  13. env["RANLIB"] = "emranlib"
  14. # Use TempFileMunge since some AR invocations are too long for cmd.exe.
  15. # Use POSIX-style paths, required with TempFileMunge.
  16. env["ARCOM_POSIX"] = env["ARCOM"].replace("$TARGET", "$TARGET.posix").replace("$SOURCES", "$SOURCES.posix")
  17. env["ARCOM"] = "${TEMPFILE(ARCOM_POSIX)}"
  18. # All intermediate files are just object files.
  19. env["OBJSUFFIX"] = ".o"
  20. env["SHOBJSUFFIX"] = ".o"
  21. # Static libraries clang-style.
  22. env["LIBPREFIX"] = "lib"
  23. env["LIBSUFFIX"] = ".a"
  24. # Shared library as wasm.
  25. env["SHLIBSUFFIX"] = ".wasm"
  26. # Thread support (via SharedArrayBuffer).
  27. if env["threads"]:
  28. env.Append(CCFLAGS=["-sUSE_PTHREADS=1"])
  29. env.Append(LINKFLAGS=["-sUSE_PTHREADS=1"])
  30. # Build as side module (shared library).
  31. env.Append(CCFLAGS=["-sSIDE_MODULE=1"])
  32. env.Append(LINKFLAGS=["-sSIDE_MODULE=1"])
  33. # Enable WebAssembly BigInt <-> i64 conversion.
  34. # This must match the flag used to build Godot (true in official builds since 4.3)
  35. env.Append(LINKFLAGS=["-sWASM_BIGINT"])
  36. # Force wasm longjmp mode.
  37. env.Append(CCFLAGS=["-sSUPPORT_LONGJMP='wasm'"])
  38. env.Append(LINKFLAGS=["-sSUPPORT_LONGJMP='wasm'"])
  39. env.Append(CPPDEFINES=["WEB_ENABLED", "UNIX_ENABLED"])
  40. # Refer to https://github.com/godotengine/godot/blob/master/platform/web/detect.py
  41. if env["lto"] == "auto":
  42. env["lto"] = "full"
  43. common_compiler_flags.generate(env)