SCsub 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #!/usr/bin/env python
  2. Import("env")
  3. javascript_files = [
  4. "audio_driver_javascript.cpp",
  5. "display_server_javascript.cpp",
  6. "http_client_javascript.cpp",
  7. "javascript_eval.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_http_request.js",
  18. "js/libs/library_godot_os.js",
  19. "js/libs/library_godot_runtime.js",
  20. ]
  21. )
  22. if env["tools"]:
  23. sys_env.AddJSLibraries(["js/libs/library_godot_editor_tools.js"])
  24. if env["javascript_eval"]:
  25. sys_env.AddJSLibraries(["js/libs/library_godot_eval.js"])
  26. for lib in sys_env["JS_LIBS"]:
  27. sys_env.Append(LINKFLAGS=["--js-library", lib])
  28. for js in env["JS_PRE"]:
  29. sys_env.Append(LINKFLAGS=["--pre-js", env.File(js).path])
  30. for ext in env["JS_EXTERNS"]:
  31. sys_env["ENV"]["EMCC_CLOSURE_ARGS"] += " --externs " + ext.path
  32. build = []
  33. if env["gdnative_enabled"]:
  34. build_targets = ["#bin/godot${PROGSUFFIX}.js", "#bin/godot${PROGSUFFIX}.wasm"]
  35. # Reset libraries. The main runtime will only link emscripten libraries, not godot ones.
  36. sys_env["LIBS"] = []
  37. # We use IDBFS. Since Emscripten 1.39.1 it needs to be linked explicitly.
  38. sys_env.Append(LIBS=["idbfs.js"])
  39. # Configure it as a main module (dynamic linking support).
  40. sys_env.Append(CCFLAGS=["-s", "MAIN_MODULE=1"])
  41. sys_env.Append(LINKFLAGS=["-s", "MAIN_MODULE=1"])
  42. sys_env.Append(CCFLAGS=["-s", "EXPORT_ALL=1"])
  43. sys_env.Append(LINKFLAGS=["-s", "EXPORT_ALL=1"])
  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/utils.js",
  68. "js/engine/config.js",
  69. "js/engine/engine.js",
  70. ]
  71. externs = [env.File("#platform/javascript/js/engine/engine.externs.js")]
  72. js_engine = env.CreateEngineFile("#bin/godot${PROGSUFFIX}.engine.js", engine, externs)
  73. env.Depends(js_engine, externs)
  74. wrap_list = [
  75. build[0],
  76. js_engine,
  77. ]
  78. js_wrapped = env.Textfile("#bin/godot", [env.File(f) for f in wrap_list], TEXTFILESUFFIX="${PROGSUFFIX}.wrapped.js")
  79. zip_dir = env.Dir("#bin/.javascript_zip")
  80. binary_name = "godot.tools" if env["tools"] else "godot"
  81. out_files = [
  82. zip_dir.File(binary_name + ".js"),
  83. zip_dir.File(binary_name + ".wasm"),
  84. zip_dir.File(binary_name + ".html"),
  85. zip_dir.File(binary_name + ".audio.worklet.js"),
  86. ]
  87. html_file = "#misc/dist/html/full-size.html"
  88. if env["tools"]:
  89. subst_dict = {"\$GODOT_VERSION": env.GetBuildVersion()}
  90. html_file = env.Substfile(
  91. target="#bin/godot${PROGSUFFIX}.html", source="#misc/dist/html/editor.html", SUBST_DICT=subst_dict
  92. )
  93. in_files = [js_wrapped, build[1], html_file, "#platform/javascript/js/libs/audio.worklet.js"]
  94. if env["gdnative_enabled"]:
  95. in_files.append(build[2]) # Runtime
  96. out_files.append(zip_dir.File(binary_name + ".side.wasm"))
  97. elif env["threads_enabled"]:
  98. in_files.append(build[2]) # Worker
  99. out_files.append(zip_dir.File(binary_name + ".worker.js"))
  100. if env["tools"]:
  101. in_files.append("#misc/dist/html/logo.svg")
  102. out_files.append(zip_dir.File("logo.svg"))
  103. in_files.append("#icon.png")
  104. out_files.append(zip_dir.File("favicon.png"))
  105. zip_files = env.InstallAs(out_files, in_files)
  106. env.Zip(
  107. "#bin/godot",
  108. zip_files,
  109. ZIPROOT=zip_dir,
  110. ZIPSUFFIX="${PROGSUFFIX}${ZIPSUFFIX}",
  111. ZIPCOMSTR="Archiving $SOURCES as $TARGET",
  112. )