SCsub 3.5 KB

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