SCsub 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. #!/usr/bin/env python
  2. Import("env")
  3. import core_builders
  4. env.core_sources = []
  5. # Generate AES256 script encryption key
  6. import os
  7. txt = "0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0"
  8. if "SCRIPT_AES256_ENCRYPTION_KEY" in os.environ:
  9. key = os.environ["SCRIPT_AES256_ENCRYPTION_KEY"]
  10. ec_valid = True
  11. if len(key) != 64:
  12. ec_valid = False
  13. else:
  14. txt = ""
  15. for i in range(len(key) >> 1):
  16. if i > 0:
  17. txt += ","
  18. txts = "0x" + key[i * 2 : i * 2 + 2]
  19. try:
  20. int(txts, 16)
  21. except Exception:
  22. ec_valid = False
  23. txt += txts
  24. if not ec_valid:
  25. print("Error: Invalid AES256 encryption key, not 64 hexadecimal characters: '" + key + "'.")
  26. print(
  27. "Unset 'SCRIPT_AES256_ENCRYPTION_KEY' in your environment "
  28. "or make sure that it contains exactly 64 hexadecimal characters."
  29. )
  30. Exit(255)
  31. # NOTE: It is safe to generate this file here, since this is still executed serially
  32. with open("script_encryption_key.gen.cpp", "w") as f:
  33. f.write('#include "core/config/project_settings.h"\nuint8_t script_encryption_key[32]={' + txt + "};\n")
  34. # Add required thirdparty code.
  35. thirdparty_obj = []
  36. env_thirdparty = env.Clone()
  37. env_thirdparty.disable_warnings()
  38. # Misc thirdparty code: header paths are hardcoded, we don't need to append
  39. # to the include path (saves a few chars on the compiler invocation for touchy MSVC...)
  40. thirdparty_misc_dir = "#thirdparty/misc/"
  41. thirdparty_misc_sources = [
  42. # C sources
  43. "fastlz.c",
  44. "r128.c",
  45. "smaz.c",
  46. # C++ sources
  47. "pcg.cpp",
  48. "polypartition.cpp",
  49. "clipper.cpp",
  50. "smolv.cpp",
  51. ]
  52. thirdparty_misc_sources = [thirdparty_misc_dir + file for file in thirdparty_misc_sources]
  53. env_thirdparty.add_source_files(thirdparty_obj, thirdparty_misc_sources)
  54. # Brotli
  55. if env["brotli"] and env["builtin_brotli"]:
  56. thirdparty_brotli_dir = "#thirdparty/brotli/"
  57. thirdparty_brotli_sources = [
  58. "common/constants.c",
  59. "common/context.c",
  60. "common/dictionary.c",
  61. "common/platform.c",
  62. "common/shared_dictionary.c",
  63. "common/transform.c",
  64. "dec/bit_reader.c",
  65. "dec/decode.c",
  66. "dec/huffman.c",
  67. "dec/state.c",
  68. ]
  69. thirdparty_brotli_sources = [thirdparty_brotli_dir + file for file in thirdparty_brotli_sources]
  70. env_thirdparty.Prepend(CPPPATH=[thirdparty_brotli_dir + "include"])
  71. env.Prepend(CPPPATH=[thirdparty_brotli_dir + "include"])
  72. if env.get("use_ubsan") or env.get("use_asan") or env.get("use_tsan") or env.get("use_lsan") or env.get("use_msan"):
  73. env_thirdparty.Append(CPPDEFINES=["BROTLI_BUILD_PORTABLE"])
  74. env_thirdparty.add_source_files(thirdparty_obj, thirdparty_brotli_sources)
  75. # Clipper2 Thirdparty source files used for polygon and polyline boolean operations.
  76. if env["builtin_clipper2"]:
  77. thirdparty_clipper_dir = "#thirdparty/clipper2/"
  78. thirdparty_clipper_sources = [
  79. "src/clipper.engine.cpp",
  80. "src/clipper.offset.cpp",
  81. "src/clipper.rectclip.cpp",
  82. ]
  83. thirdparty_clipper_sources = [thirdparty_clipper_dir + file for file in thirdparty_clipper_sources]
  84. env_thirdparty.Prepend(CPPPATH=[thirdparty_clipper_dir + "include"])
  85. env.Prepend(CPPPATH=[thirdparty_clipper_dir + "include"])
  86. env_thirdparty.Append(CPPDEFINES=["CLIPPER2_ENABLED"])
  87. env.Append(CPPDEFINES=["CLIPPER2_ENABLED"])
  88. env_thirdparty.add_source_files(thirdparty_obj, thirdparty_clipper_sources)
  89. # Zlib library, can be unbundled
  90. if env["builtin_zlib"]:
  91. thirdparty_zlib_dir = "#thirdparty/zlib/"
  92. thirdparty_zlib_sources = [
  93. "adler32.c",
  94. "compress.c",
  95. "crc32.c",
  96. "deflate.c",
  97. "inffast.c",
  98. "inflate.c",
  99. "inftrees.c",
  100. "trees.c",
  101. "uncompr.c",
  102. "zutil.c",
  103. ]
  104. thirdparty_zlib_sources = [thirdparty_zlib_dir + file for file in thirdparty_zlib_sources]
  105. env_thirdparty.Prepend(CPPPATH=[thirdparty_zlib_dir])
  106. # Needs to be available in main env too
  107. env.Prepend(CPPPATH=[thirdparty_zlib_dir])
  108. if env.dev_build:
  109. env_thirdparty.Append(CPPDEFINES=["ZLIB_DEBUG"])
  110. env_thirdparty.add_source_files(thirdparty_obj, thirdparty_zlib_sources)
  111. # Minizip library, could be unbundled in theory
  112. # However, our version has some custom modifications, so it won't compile with the system one
  113. thirdparty_minizip_dir = "#thirdparty/minizip/"
  114. thirdparty_minizip_sources = ["ioapi.c", "unzip.c", "zip.c"]
  115. thirdparty_minizip_sources = [thirdparty_minizip_dir + file for file in thirdparty_minizip_sources]
  116. env_thirdparty.add_source_files(thirdparty_obj, thirdparty_minizip_sources)
  117. # Zstd library, can be unbundled in theory
  118. # though we currently use some private symbols
  119. # https://github.com/godotengine/godot/issues/17374
  120. if env["builtin_zstd"]:
  121. thirdparty_zstd_dir = "#thirdparty/zstd/"
  122. thirdparty_zstd_sources = [
  123. "common/debug.c",
  124. "common/entropy_common.c",
  125. "common/error_private.c",
  126. "common/fse_decompress.c",
  127. "common/pool.c",
  128. "common/threading.c",
  129. "common/xxhash.c",
  130. "common/zstd_common.c",
  131. "compress/fse_compress.c",
  132. "compress/hist.c",
  133. "compress/huf_compress.c",
  134. "compress/zstd_compress.c",
  135. "compress/zstd_double_fast.c",
  136. "compress/zstd_fast.c",
  137. "compress/zstd_lazy.c",
  138. "compress/zstd_ldm.c",
  139. "compress/zstd_opt.c",
  140. "compress/zstdmt_compress.c",
  141. "compress/zstd_compress_literals.c",
  142. "compress/zstd_compress_sequences.c",
  143. "compress/zstd_compress_superblock.c",
  144. "decompress/huf_decompress.c",
  145. "decompress/zstd_ddict.c",
  146. "decompress/zstd_decompress_block.c",
  147. "decompress/zstd_decompress.c",
  148. ]
  149. if env["platform"] in ["android", "ios", "linuxbsd", "macos"]:
  150. # Match platforms with ZSTD_ASM_SUPPORTED in common/portability_macros.h
  151. thirdparty_zstd_sources.append("decompress/huf_decompress_amd64.S")
  152. thirdparty_zstd_sources = [thirdparty_zstd_dir + file for file in thirdparty_zstd_sources]
  153. env_thirdparty.Prepend(CPPPATH=[thirdparty_zstd_dir, thirdparty_zstd_dir + "common"])
  154. env_thirdparty.Append(CPPDEFINES=["ZSTD_STATIC_LINKING_ONLY"])
  155. env.Prepend(CPPPATH=thirdparty_zstd_dir)
  156. # Also needed in main env includes will trigger warnings
  157. env.Append(CPPDEFINES=["ZSTD_STATIC_LINKING_ONLY"])
  158. env_thirdparty.add_source_files(thirdparty_obj, thirdparty_zstd_sources)
  159. env.core_sources += thirdparty_obj
  160. # Godot source files
  161. env.add_source_files(env.core_sources, "*.cpp")
  162. env.add_source_files(env.core_sources, "script_encryption_key.gen.cpp")
  163. env.add_source_files(env.core_sources, "version_hash.gen.cpp")
  164. # Certificates
  165. env.Depends(
  166. "#core/io/certs_compressed.gen.h",
  167. ["#thirdparty/certs/ca-certificates.crt", env.Value(env["builtin_certs"]), env.Value(env["system_certs_path"])],
  168. )
  169. env.CommandNoCache(
  170. "#core/io/certs_compressed.gen.h",
  171. "#thirdparty/certs/ca-certificates.crt",
  172. env.Run(core_builders.make_certs_header, "Building ca-certificates header."),
  173. )
  174. # Authors
  175. env.Depends("#core/authors.gen.h", "../AUTHORS.md")
  176. env.CommandNoCache(
  177. "#core/authors.gen.h", "../AUTHORS.md", env.Run(core_builders.make_authors_header, "Generating authors header.")
  178. )
  179. # Donors
  180. env.Depends("#core/donors.gen.h", "../DONORS.md")
  181. env.CommandNoCache(
  182. "#core/donors.gen.h", "../DONORS.md", env.Run(core_builders.make_donors_header, "Generating donors header.")
  183. )
  184. # License
  185. env.Depends("#core/license.gen.h", ["../COPYRIGHT.txt", "../LICENSE.txt"])
  186. env.CommandNoCache(
  187. "#core/license.gen.h",
  188. ["../COPYRIGHT.txt", "../LICENSE.txt"],
  189. env.Run(core_builders.make_license_header, "Generating license header."),
  190. )
  191. # Chain load SCsubs
  192. SConscript("os/SCsub")
  193. SConscript("math/SCsub")
  194. SConscript("crypto/SCsub")
  195. SConscript("io/SCsub")
  196. SConscript("debugger/SCsub")
  197. SConscript("input/SCsub")
  198. SConscript("variant/SCsub")
  199. SConscript("extension/SCsub")
  200. SConscript("object/SCsub")
  201. SConscript("templates/SCsub")
  202. SConscript("string/SCsub")
  203. SConscript("config/SCsub")
  204. SConscript("error/SCsub")
  205. # Build it all as a library
  206. lib = env.add_library("core", env.core_sources)
  207. env.Prepend(LIBS=[lib])
  208. # Needed to force rebuilding the core files when the thirdparty code is updated.
  209. env.Depends(lib, thirdparty_obj)