SCsub 3.4 KB

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