SCsub 3.7 KB

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