SCsub 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/usr/bin/env python
  2. from methods import print_error
  3. Import("env")
  4. # The HTTP server "targets". Run with "scons p=web serve", or "scons p=web run"
  5. if "serve" in COMMAND_LINE_TARGETS or "run" in COMMAND_LINE_TARGETS:
  6. import os
  7. from serve import serve
  8. port = os.environ.get("GODOT_WEB_TEST_PORT", 8060)
  9. try:
  10. port = int(port)
  11. except Exception:
  12. print_error("GODOT_WEB_TEST_PORT must be a valid integer")
  13. sys.exit(255)
  14. serve(env.Dir(env.GetTemplateZipPath()).abspath, port, "run" in COMMAND_LINE_TARGETS)
  15. sys.exit(0)
  16. web_files = [
  17. "audio_driver_web.cpp",
  18. "display_server_web.cpp",
  19. "http_client_web.cpp",
  20. "javascript_bridge_singleton.cpp",
  21. "web_main.cpp",
  22. "os_web.cpp",
  23. "api/web_tools_editor_plugin.cpp",
  24. ]
  25. sys_env = env.Clone()
  26. sys_env.AddJSLibraries(
  27. [
  28. "js/libs/library_godot_audio.js",
  29. "js/libs/library_godot_display.js",
  30. "js/libs/library_godot_fetch.js",
  31. "js/libs/library_godot_os.js",
  32. "js/libs/library_godot_runtime.js",
  33. "js/libs/library_godot_input.js",
  34. "js/libs/library_godot_webgl2.js",
  35. ]
  36. )
  37. sys_env.AddJSExterns(
  38. [
  39. "js/libs/library_godot_webgl2.externs.js",
  40. ]
  41. )
  42. if env["javascript_eval"]:
  43. sys_env.AddJSLibraries(["js/libs/library_godot_javascript_singleton.js"])
  44. for lib in sys_env["JS_LIBS"]:
  45. sys_env.Append(LINKFLAGS=["--js-library", lib.abspath])
  46. for js in sys_env["JS_PRE"]:
  47. sys_env.Append(LINKFLAGS=["--pre-js", js.abspath])
  48. for ext in sys_env["JS_EXTERNS"]:
  49. sys_env["ENV"]["EMCC_CLOSURE_ARGS"] += " --externs " + ext.abspath
  50. build = []
  51. build_targets = ["#bin/godot${PROGSUFFIX}.js", "#bin/godot${PROGSUFFIX}.wasm", "#bin/godot${PROGSUFFIX}.worker.js"]
  52. if env["dlink_enabled"]:
  53. # Reset libraries. The main runtime will only link emscripten libraries, not godot ones.
  54. sys_env["LIBS"] = []
  55. # We use IDBFS. Since Emscripten 1.39.1 it needs to be linked explicitly.
  56. sys_env.Append(LIBS=["idbfs.js"])
  57. # Configure it as a main module (dynamic linking support).
  58. sys_env["CCFLAGS"].remove("-sSIDE_MODULE=2")
  59. sys_env["LINKFLAGS"].remove("-sSIDE_MODULE=2")
  60. sys_env.Append(CCFLAGS=["-s", "MAIN_MODULE=1"])
  61. sys_env.Append(LINKFLAGS=["-s", "MAIN_MODULE=1"])
  62. sys_env.Append(LINKFLAGS=["-s", "EXPORT_ALL=1"])
  63. sys_env.Append(LINKFLAGS=["-s", "WARN_ON_UNDEFINED_SYMBOLS=0"])
  64. sys_env["CCFLAGS"].remove("-fvisibility=hidden")
  65. sys_env["LINKFLAGS"].remove("-fvisibility=hidden")
  66. # The main emscripten runtime, with exported standard libraries.
  67. sys = sys_env.Program(build_targets, ["web_runtime.cpp"])
  68. # The side library, containing all Godot code.
  69. wasm = env.add_program("#bin/godot.side${PROGSUFFIX}.wasm", web_files)
  70. build = sys + [wasm[0]]
  71. else:
  72. # We use IDBFS. Since Emscripten 1.39.1 it needs to be linked explicitly.
  73. sys_env.Append(LIBS=["idbfs.js"])
  74. build = sys_env.Program(build_targets, web_files + ["web_runtime.cpp"])
  75. sys_env.Depends(build[0], sys_env["JS_LIBS"])
  76. sys_env.Depends(build[0], sys_env["JS_PRE"])
  77. sys_env.Depends(build[0], sys_env["JS_EXTERNS"])
  78. engine = [
  79. "js/engine/features.js",
  80. "js/engine/preloader.js",
  81. "js/engine/config.js",
  82. "js/engine/engine.js",
  83. ]
  84. externs = [env.File("#platform/web/js/engine/engine.externs.js")]
  85. js_engine = env.CreateEngineFile("#bin/godot${PROGSUFFIX}.engine.js", engine, externs, env["threads"])
  86. env.Depends(js_engine, externs)
  87. wrap_list = [
  88. build[0],
  89. js_engine,
  90. ]
  91. js_wrapped = env.Textfile("#bin/godot", [env.File(f) for f in wrap_list], TEXTFILESUFFIX="${PROGSUFFIX}.wrapped.js")
  92. # 0 - unwrapped js file (use wrapped one instead)
  93. # 1 - wasm file
  94. # 2 - worker file
  95. # 3 - wasm side (when dlink is enabled).
  96. env.CreateTemplateZip(js_wrapped, build[1], build[2], build[3] if len(build) > 3 else None)