SCsub 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #!/usr/bin/env python
  2. Import("env")
  3. javascript_files = [
  4. "audio_driver_javascript.cpp",
  5. "http_client_javascript.cpp",
  6. "javascript_eval.cpp",
  7. "javascript_main.cpp",
  8. "os_javascript.cpp",
  9. "api/javascript_tools_editor_plugin.cpp",
  10. ]
  11. sys_env = env.Clone()
  12. sys_env.AddJSLibraries(
  13. [
  14. "js/libs/library_godot_audio.js",
  15. "js/libs/library_godot_display.js",
  16. "js/libs/library_godot_http_request.js",
  17. "js/libs/library_godot_os.js",
  18. "js/libs/library_godot_runtime.js",
  19. ]
  20. )
  21. if env["tools"]:
  22. sys_env.AddJSLibraries(["js/libs/library_godot_editor_tools.js"])
  23. if env["javascript_eval"]:
  24. sys_env.AddJSLibraries(["js/libs/library_godot_eval.js"])
  25. for lib in sys_env["JS_LIBS"]:
  26. sys_env.Append(LINKFLAGS=["--js-library", lib])
  27. for js in env["JS_PRE"]:
  28. sys_env.Append(LINKFLAGS=["--pre-js", env.File(js).path])
  29. for ext in env["JS_EXTERNS"]:
  30. sys_env["ENV"]["EMCC_CLOSURE_ARGS"] += " --externs " + ext.path
  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. # Force exporting the standard library (printf, malloc, etc.)
  44. sys_env["ENV"]["EMCC_FORCE_STDLIBS"] = "libc,libc++,libc++abi"
  45. # The main emscripten runtime, with exported standard libraries.
  46. sys = sys_env.Program(build_targets, ["javascript_runtime.cpp"])
  47. # The side library, containing all Godot code.
  48. wasm_env = env.Clone()
  49. wasm_env.Append(CPPDEFINES=["WASM_GDNATIVE"]) # So that OS knows it can run GDNative libraries.
  50. wasm_env.Append(CCFLAGS=["-s", "SIDE_MODULE=2"])
  51. wasm_env.Append(LINKFLAGS=["-s", "SIDE_MODULE=2"])
  52. wasm = wasm_env.add_program("#bin/godot.side${PROGSUFFIX}.wasm", javascript_files)
  53. build = [sys[0], sys[1], wasm[0]]
  54. else:
  55. build_targets = ["#bin/godot${PROGSUFFIX}.js", "#bin/godot${PROGSUFFIX}.wasm"]
  56. if env["threads_enabled"]:
  57. build_targets.append("#bin/godot${PROGSUFFIX}.worker.js")
  58. # We use IDBFS. Since Emscripten 1.39.1 it needs to be linked explicitly.
  59. sys_env.Append(LIBS=["idbfs.js"])
  60. build = sys_env.Program(build_targets, javascript_files + ["javascript_runtime.cpp"])
  61. sys_env.Depends(build[0], sys_env["JS_LIBS"])
  62. sys_env.Depends(build[0], sys_env["JS_PRE"])
  63. sys_env.Depends(build[0], sys_env["JS_EXTERNS"])
  64. engine = [
  65. "js/engine/preloader.js",
  66. "js/engine/utils.js",
  67. "js/engine/engine.js",
  68. ]
  69. externs = [env.File("#platform/javascript/js/engine/engine.externs.js")]
  70. js_engine = env.CreateEngineFile("#bin/godot${PROGSUFFIX}.engine.js", engine, externs)
  71. env.Depends(js_engine, externs)
  72. wrap_list = [
  73. build[0],
  74. js_engine,
  75. ]
  76. js_wrapped = env.Textfile("#bin/godot", [env.File(f) for f in wrap_list], TEXTFILESUFFIX="${PROGSUFFIX}.wrapped.js")
  77. zip_dir = env.Dir("#bin/.javascript_zip")
  78. binary_name = "godot.tools" if env["tools"] else "godot"
  79. out_files = [
  80. zip_dir.File(binary_name + ".js"),
  81. zip_dir.File(binary_name + ".wasm"),
  82. zip_dir.File(binary_name + ".html"),
  83. zip_dir.File(binary_name + ".audio.worklet.js"),
  84. ]
  85. html_file = "#misc/dist/html/full-size.html"
  86. if env["tools"]:
  87. subst_dict = {"\$GODOT_VERSION": env.GetBuildVersion()}
  88. html_file = env.Substfile(
  89. target="#bin/godot${PROGSUFFIX}.html", source="#misc/dist/html/editor.html", SUBST_DICT=subst_dict
  90. )
  91. in_files = [js_wrapped, build[1], html_file, "#platform/javascript/js/libs/audio.worklet.js"]
  92. if env["gdnative_enabled"]:
  93. in_files.append(build[2]) # Runtime
  94. out_files.append(zip_dir.File(binary_name + ".side.wasm"))
  95. elif env["threads_enabled"]:
  96. in_files.append(build[2]) # Worker
  97. out_files.append(zip_dir.File(binary_name + ".worker.js"))
  98. if env["tools"]:
  99. in_files.append("#misc/dist/html/logo.svg")
  100. out_files.append(zip_dir.File("logo.svg"))
  101. in_files.append("#icon.png")
  102. out_files.append(zip_dir.File("favicon.png"))
  103. zip_files = env.InstallAs(out_files, in_files)
  104. env.Zip(
  105. "#bin/godot",
  106. zip_files,
  107. ZIPROOT=zip_dir,
  108. ZIPSUFFIX="${PROGSUFFIX}${ZIPSUFFIX}",
  109. ZIPCOMSTR="Archiving $SOURCES as $TARGET",
  110. )