SCsub 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/usr/bin/env python
  2. Import("env")
  3. web_files = [
  4. "audio_driver_web.cpp",
  5. "display_server_web.cpp",
  6. "http_client_web.cpp",
  7. "javascript_singleton.cpp",
  8. "web_main.cpp",
  9. "os_web.cpp",
  10. "api/web_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. "js/libs/library_godot_input.js",
  21. ]
  22. )
  23. if env["javascript_eval"]:
  24. sys_env.AddJSLibraries(["js/libs/library_godot_javascript_singleton.js"])
  25. for lib in sys_env["JS_LIBS"]:
  26. sys_env.Append(LINKFLAGS=["--js-library", lib.abspath])
  27. for js in env["JS_PRE"]:
  28. sys_env.Append(LINKFLAGS=["--pre-js", js.abspath])
  29. for ext in env["JS_EXTERNS"]:
  30. sys_env["ENV"]["EMCC_CLOSURE_ARGS"] += " --externs " + ext.abspath
  31. build = []
  32. build_targets = ["#bin/godot${PROGSUFFIX}.js", "#bin/godot${PROGSUFFIX}.wasm", "#bin/godot${PROGSUFFIX}.worker.js"]
  33. if env["dlink_enabled"]:
  34. # Reset libraries. The main runtime will only link emscripten libraries, not godot ones.
  35. sys_env["LIBS"] = []
  36. # We use IDBFS. Since Emscripten 1.39.1 it needs to be linked explicitly.
  37. sys_env.Append(LIBS=["idbfs.js"])
  38. # Configure it as a main module (dynamic linking support).
  39. sys_env["CCFLAGS"].remove("SIDE_MODULE=2")
  40. sys_env["LINKFLAGS"].remove("SIDE_MODULE=2")
  41. sys_env.Append(CCFLAGS=["-s", "MAIN_MODULE=1"])
  42. sys_env.Append(LINKFLAGS=["-s", "MAIN_MODULE=1"])
  43. sys_env.Append(LINKFLAGS=["-s", "EXPORT_ALL=1"])
  44. sys_env.Append(LINKFLAGS=["-s", "WARN_ON_UNDEFINED_SYMBOLS=0"])
  45. # Force exporting the standard library (printf, malloc, etc.)
  46. sys_env["ENV"]["EMCC_FORCE_STDLIBS"] = "libc,libc++,libc++abi"
  47. # The main emscripten runtime, with exported standard libraries.
  48. sys = sys_env.Program(build_targets, ["web_runtime.cpp"])
  49. # The side library, containing all Godot code.
  50. wasm = env.add_program("#bin/godot.side${PROGSUFFIX}.wasm", web_files)
  51. build = sys + [wasm[0]]
  52. else:
  53. # We use IDBFS. Since Emscripten 1.39.1 it needs to be linked explicitly.
  54. sys_env.Append(LIBS=["idbfs.js"])
  55. build = sys_env.Program(build_targets, web_files + ["web_runtime.cpp"])
  56. sys_env.Depends(build[0], sys_env["JS_LIBS"])
  57. sys_env.Depends(build[0], sys_env["JS_PRE"])
  58. sys_env.Depends(build[0], sys_env["JS_EXTERNS"])
  59. engine = [
  60. "js/engine/preloader.js",
  61. "js/engine/config.js",
  62. "js/engine/engine.js",
  63. ]
  64. externs = [env.File("#platform/web/js/engine/engine.externs.js")]
  65. js_engine = env.CreateEngineFile("#bin/godot${PROGSUFFIX}.engine.js", engine, externs)
  66. env.Depends(js_engine, externs)
  67. wrap_list = [
  68. build[0],
  69. js_engine,
  70. ]
  71. js_wrapped = env.Textfile("#bin/godot", [env.File(f) for f in wrap_list], TEXTFILESUFFIX="${PROGSUFFIX}.wrapped.js")
  72. # 0 - unwrapped js file (use wrapped one instead)
  73. # 1 - wasm file
  74. # 2 - worker file
  75. # 3 - wasm side (when dlink is enabled).
  76. env.CreateTemplateZip(js_wrapped, build[1], build[2], build[3] if len(build) > 3 else None)