SCsub 9.5 KB

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