SCsub 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. # Zlib library, can be unbundled
  76. if env["builtin_zlib"]:
  77. thirdparty_zlib_dir = "#thirdparty/zlib/"
  78. thirdparty_zlib_sources = [
  79. "adler32.c",
  80. "compress.c",
  81. "crc32.c",
  82. "deflate.c",
  83. "inffast.c",
  84. "inflate.c",
  85. "inftrees.c",
  86. "trees.c",
  87. "uncompr.c",
  88. "zutil.c",
  89. ]
  90. thirdparty_zlib_sources = [thirdparty_zlib_dir + file for file in thirdparty_zlib_sources]
  91. env_thirdparty.Prepend(CPPPATH=[thirdparty_zlib_dir])
  92. # Needs to be available in main env too
  93. env.Prepend(CPPPATH=[thirdparty_zlib_dir])
  94. if env.dev_build:
  95. env_thirdparty.Append(CPPDEFINES=["ZLIB_DEBUG"])
  96. env_thirdparty.add_source_files(thirdparty_obj, thirdparty_zlib_sources)
  97. # Minizip library, could be unbundled in theory
  98. # However, our version has some custom modifications, so it won't compile with the system one
  99. thirdparty_minizip_dir = "#thirdparty/minizip/"
  100. thirdparty_minizip_sources = ["ioapi.c", "unzip.c", "zip.c"]
  101. thirdparty_minizip_sources = [thirdparty_minizip_dir + file for file in thirdparty_minizip_sources]
  102. env_thirdparty.add_source_files(thirdparty_obj, thirdparty_minizip_sources)
  103. # Zstd library, can be unbundled in theory
  104. # though we currently use some private symbols
  105. # https://github.com/godotengine/godot/issues/17374
  106. if env["builtin_zstd"]:
  107. thirdparty_zstd_dir = "#thirdparty/zstd/"
  108. thirdparty_zstd_sources = [
  109. "common/debug.c",
  110. "common/entropy_common.c",
  111. "common/error_private.c",
  112. "common/fse_decompress.c",
  113. "common/pool.c",
  114. "common/threading.c",
  115. "common/xxhash.c",
  116. "common/zstd_common.c",
  117. "compress/fse_compress.c",
  118. "compress/hist.c",
  119. "compress/huf_compress.c",
  120. "compress/zstd_compress.c",
  121. "compress/zstd_double_fast.c",
  122. "compress/zstd_fast.c",
  123. "compress/zstd_lazy.c",
  124. "compress/zstd_ldm.c",
  125. "compress/zstd_opt.c",
  126. "compress/zstdmt_compress.c",
  127. "compress/zstd_compress_literals.c",
  128. "compress/zstd_compress_sequences.c",
  129. "compress/zstd_compress_superblock.c",
  130. "decompress/huf_decompress.c",
  131. "decompress/zstd_ddict.c",
  132. "decompress/zstd_decompress_block.c",
  133. "decompress/zstd_decompress.c",
  134. ]
  135. if env["platform"] in ["android", "ios", "linuxbsd", "macos"]:
  136. # Match platforms with ZSTD_ASM_SUPPORTED in common/portability_macros.h
  137. thirdparty_zstd_sources.append("decompress/huf_decompress_amd64.S")
  138. thirdparty_zstd_sources = [thirdparty_zstd_dir + file for file in thirdparty_zstd_sources]
  139. env_thirdparty.Prepend(CPPPATH=[thirdparty_zstd_dir, thirdparty_zstd_dir + "common"])
  140. env_thirdparty.Append(CPPDEFINES=["ZSTD_STATIC_LINKING_ONLY"])
  141. env.Prepend(CPPPATH=thirdparty_zstd_dir)
  142. # Also needed in main env includes will trigger warnings
  143. env.Append(CPPDEFINES=["ZSTD_STATIC_LINKING_ONLY"])
  144. env_thirdparty.add_source_files(thirdparty_obj, thirdparty_zstd_sources)
  145. env.core_sources += thirdparty_obj
  146. # Godot source files
  147. env.add_source_files(env.core_sources, "*.cpp")
  148. env.add_source_files(env.core_sources, "script_encryption_key.gen.cpp")
  149. env.add_source_files(env.core_sources, "version_hash.gen.cpp")
  150. # Certificates
  151. env.Depends(
  152. "#core/io/certs_compressed.gen.h",
  153. ["#thirdparty/certs/ca-certificates.crt", env.Value(env["builtin_certs"]), env.Value(env["system_certs_path"])],
  154. )
  155. env.CommandNoCache(
  156. "#core/io/certs_compressed.gen.h",
  157. "#thirdparty/certs/ca-certificates.crt",
  158. env.Run(core_builders.make_certs_header, "Building ca-certificates header."),
  159. )
  160. # Authors
  161. env.Depends("#core/authors.gen.h", "../AUTHORS.md")
  162. env.CommandNoCache(
  163. "#core/authors.gen.h", "../AUTHORS.md", env.Run(core_builders.make_authors_header, "Generating authors header.")
  164. )
  165. # Donors
  166. env.Depends("#core/donors.gen.h", "../DONORS.md")
  167. env.CommandNoCache(
  168. "#core/donors.gen.h", "../DONORS.md", env.Run(core_builders.make_donors_header, "Generating donors header.")
  169. )
  170. # License
  171. env.Depends("#core/license.gen.h", ["../COPYRIGHT.txt", "../LICENSE.txt"])
  172. env.CommandNoCache(
  173. "#core/license.gen.h",
  174. ["../COPYRIGHT.txt", "../LICENSE.txt"],
  175. env.Run(core_builders.make_license_header, "Generating license header."),
  176. )
  177. # Chain load SCsubs
  178. SConscript("os/SCsub")
  179. SConscript("math/SCsub")
  180. SConscript("crypto/SCsub")
  181. SConscript("io/SCsub")
  182. SConscript("debugger/SCsub")
  183. SConscript("input/SCsub")
  184. SConscript("variant/SCsub")
  185. SConscript("extension/SCsub")
  186. SConscript("object/SCsub")
  187. SConscript("templates/SCsub")
  188. SConscript("string/SCsub")
  189. SConscript("config/SCsub")
  190. SConscript("error/SCsub")
  191. # Build it all as a library
  192. lib = env.add_library("core", env.core_sources)
  193. env.Prepend(LIBS=[lib])
  194. # Needed to force rebuilding the core files when the thirdparty code is updated.
  195. env.Depends(lib, thirdparty_obj)