SCsub 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/usr/bin/env python
  2. Import("env")
  3. javascript_files = [
  4. "audio_driver_javascript.cpp",
  5. "display_server_javascript.cpp",
  6. "http_client_javascript.cpp",
  7. "javascript_singleton.cpp",
  8. "javascript_main.cpp",
  9. "os_javascript.cpp",
  10. "api/javascript_tools_editor_plugin.cpp",
  11. ]
  12. sys_env = env.Clone()
  13. sys_env.AddJSLibraries(
  14. [
  15. "js/libs/library_godot_audio.js",
  16. "js/libs/library_godot_display.js",
  17. "js/libs/library_godot_fetch.js",
  18. "js/libs/library_godot_os.js",
  19. "js/libs/library_godot_runtime.js",
  20. ]
  21. )
  22. if env["javascript_eval"]:
  23. sys_env.AddJSLibraries(["js/libs/library_godot_javascript_singleton.js"])
  24. for lib in sys_env["JS_LIBS"]:
  25. sys_env.Append(LINKFLAGS=["--js-library", lib])
  26. for js in env["JS_PRE"]:
  27. sys_env.Append(LINKFLAGS=["--pre-js", env.File(js).path])
  28. for ext in env["JS_EXTERNS"]:
  29. sys_env["ENV"]["EMCC_CLOSURE_ARGS"] += " --externs " + ext.path
  30. build = []
  31. if env["gdnative_enabled"]:
  32. build_targets = ["#bin/godot${PROGSUFFIX}.js", "#bin/godot${PROGSUFFIX}.wasm"]
  33. # Reset libraries. The main runtime will only link emscripten libraries, not godot ones.
  34. sys_env["LIBS"] = []
  35. # We use IDBFS. Since Emscripten 1.39.1 it needs to be linked explicitly.
  36. sys_env.Append(LIBS=["idbfs.js"])
  37. # Configure it as a main module (dynamic linking support).
  38. sys_env.Append(CCFLAGS=["-s", "MAIN_MODULE=1"])
  39. sys_env.Append(LINKFLAGS=["-s", "MAIN_MODULE=1"])
  40. sys_env.Append(CCFLAGS=["-s", "EXPORT_ALL=1"])
  41. sys_env.Append(LINKFLAGS=["-s", "EXPORT_ALL=1"])
  42. sys_env.Append(LINKFLAGS=["-s", "WARN_ON_UNDEFINED_SYMBOLS=0"])
  43. # Force exporting the standard library (printf, malloc, etc.)
  44. sys_env["ENV"]["EMCC_FORCE_STDLIBS"] = "libc,libc++,libc++abi"
  45. # The main emscripten runtime, with exported standard libraries.
  46. sys = sys_env.Program(build_targets, ["javascript_runtime.cpp"])
  47. # The side library, containing all Godot code.
  48. wasm_env = env.Clone()
  49. wasm_env.Append(CPPDEFINES=["WASM_GDNATIVE"]) # So that OS knows it can run GDNative libraries.
  50. wasm_env.Append(CCFLAGS=["-s", "SIDE_MODULE=2"])
  51. wasm_env.Append(LINKFLAGS=["-s", "SIDE_MODULE=2"])
  52. wasm = wasm_env.add_program("#bin/godot.side${PROGSUFFIX}.wasm", javascript_files)
  53. build = [sys[0], sys[1], wasm[0]]
  54. else:
  55. build_targets = ["#bin/godot${PROGSUFFIX}.js", "#bin/godot${PROGSUFFIX}.wasm"]
  56. if env["threads_enabled"]:
  57. build_targets.append("#bin/godot${PROGSUFFIX}.worker.js")
  58. # We use IDBFS. Since Emscripten 1.39.1 it needs to be linked explicitly.
  59. sys_env.Append(LIBS=["idbfs.js"])
  60. build = sys_env.Program(build_targets, javascript_files + ["javascript_runtime.cpp"])
  61. sys_env.Depends(build[0], sys_env["JS_LIBS"])
  62. sys_env.Depends(build[0], sys_env["JS_PRE"])
  63. sys_env.Depends(build[0], sys_env["JS_EXTERNS"])
  64. engine = [
  65. "js/engine/preloader.js",
  66. "js/engine/config.js",
  67. "js/engine/engine.js",
  68. ]
  69. externs = [env.File("#platform/javascript/js/engine/engine.externs.js")]
  70. js_engine = env.CreateEngineFile("#bin/godot${PROGSUFFIX}.engine.js", engine, externs)
  71. env.Depends(js_engine, externs)
  72. wrap_list = [
  73. build[0],
  74. js_engine,
  75. ]
  76. js_wrapped = env.Textfile("#bin/godot", [env.File(f) for f in wrap_list], TEXTFILESUFFIX="${PROGSUFFIX}.wrapped.js")
  77. # Extra will be the thread worker, or the GDNative side, or None
  78. extra = build[2] if len(build) > 2 else None
  79. env.CreateTemplateZip(js_wrapped, build[1], extra)