SCsub 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #!/usr/bin/env python
  2. Import("env")
  3. # The HTTP server "targets". Run with "scons p=javascript serve", or "scons p=javascript 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/.javascript_zip").abspath, port, "run" in COMMAND_LINE_TARGETS)
  14. sys.exit(0)
  15. javascript_files = [
  16. "audio_driver_javascript.cpp",
  17. "godot_webgl2.cpp",
  18. "http_client_javascript.cpp",
  19. "javascript_singleton.cpp",
  20. "javascript_main.cpp",
  21. "os_javascript.cpp",
  22. "api/javascript_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. ]
  34. )
  35. if env["javascript_eval"]:
  36. sys_env.AddJSLibraries(["js/libs/library_godot_javascript_singleton.js"])
  37. for lib in sys_env["JS_LIBS"]:
  38. sys_env.Append(LINKFLAGS=["--js-library", lib.abspath])
  39. for js in env["JS_PRE"]:
  40. sys_env.Append(LINKFLAGS=["--pre-js", js.abspath])
  41. for ext in env["JS_EXTERNS"]:
  42. sys_env["ENV"]["EMCC_CLOSURE_ARGS"] += " --externs " + ext.abspath
  43. build = []
  44. if env["gdnative_enabled"]:
  45. build_targets = ["#bin/godot${PROGSUFFIX}.js", "#bin/godot${PROGSUFFIX}.wasm"]
  46. if env["threads_enabled"]:
  47. build_targets.append("#bin/godot${PROGSUFFIX}.worker.js")
  48. # Reset libraries. The main runtime will only link emscripten libraries, not godot ones.
  49. sys_env["LIBS"] = []
  50. # We use IDBFS. Since Emscripten 1.39.1 it needs to be linked explicitly.
  51. sys_env.Append(LIBS=["idbfs.js"])
  52. # Configure it as a main module (dynamic linking support).
  53. sys_env.Append(CCFLAGS=["-s", "MAIN_MODULE=1"])
  54. sys_env.Append(LINKFLAGS=["-s", "MAIN_MODULE=1"])
  55. sys_env.Append(CCFLAGS=["-s", "EXPORT_ALL=1"])
  56. sys_env.Append(LINKFLAGS=["-s", "EXPORT_ALL=1"])
  57. sys_env.Append(LINKFLAGS=["-s", "WARN_ON_UNDEFINED_SYMBOLS=0"])
  58. # Force exporting the standard library (printf, malloc, etc.)
  59. sys_env["ENV"]["EMCC_FORCE_STDLIBS"] = "libc,libc++,libc++abi"
  60. # The main emscripten runtime, with exported standard libraries.
  61. sys = sys_env.Program(build_targets, ["javascript_runtime.cpp"])
  62. # The side library, containing all Godot code.
  63. wasm_env = env.Clone()
  64. wasm_env.Append(CPPDEFINES=["WASM_GDNATIVE"]) # So that OS knows it can run GDNative libraries.
  65. wasm_env.Append(CCFLAGS=["-s", "SIDE_MODULE=2"])
  66. wasm_env.Append(LINKFLAGS=["-s", "SIDE_MODULE=2"])
  67. wasm = wasm_env.add_program("#bin/godot.side${PROGSUFFIX}.wasm", javascript_files)
  68. build = sys + [wasm[0]]
  69. else:
  70. build_targets = ["#bin/godot${PROGSUFFIX}.js", "#bin/godot${PROGSUFFIX}.wasm"]
  71. if env["threads_enabled"]:
  72. build_targets.append("#bin/godot${PROGSUFFIX}.worker.js")
  73. # We use IDBFS. Since Emscripten 1.39.1 it needs to be linked explicitly.
  74. sys_env.Append(LIBS=["idbfs.js"])
  75. build = sys_env.Program(build_targets, javascript_files + ["javascript_runtime.cpp"])
  76. sys_env.Depends(build[0], sys_env["JS_LIBS"])
  77. sys_env.Depends(build[0], sys_env["JS_PRE"])
  78. sys_env.Depends(build[0], sys_env["JS_EXTERNS"])
  79. engine = [
  80. "js/engine/preloader.js",
  81. "js/engine/config.js",
  82. "js/engine/engine.js",
  83. ]
  84. externs = [env.File("#platform/javascript/js/engine/engine.externs.js")]
  85. js_engine = env.CreateEngineFile("#bin/godot${PROGSUFFIX}.engine.js", engine, externs)
  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. # Extra will be the thread worker, or the GDNative side, or None
  93. extra = build[2:] if len(build) > 2 else None
  94. env.CreateTemplateZip(js_wrapped, build[1], extra)