SCsub 3.8 KB

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