SCsub 8.1 KB

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