SCsub 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. #!/usr/bin/env python
  2. Import("env")
  3. import os
  4. import core_builders
  5. import methods
  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"] and env["arch"] == "x86_64":
  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(**env.version_info)
  159. )
  160. env.CommandNoCache("version_generated.gen.h", env.Value(env.version_info), env.Run(version_info_builder))
  161. # Generate version hash
  162. def version_hash_builder(target, source, env):
  163. with methods.generated_wrapper(target) as file:
  164. file.write(
  165. """\
  166. #include "core/version.h"
  167. const char *const VERSION_HASH = "{git_hash}";
  168. const uint64_t VERSION_TIMESTAMP = {git_timestamp};
  169. """.format(**env.version_info)
  170. )
  171. gen_hash = env.CommandNoCache(
  172. "version_hash.gen.cpp", env.Value(env.version_info["git_hash"]), env.Run(version_hash_builder)
  173. )
  174. env.add_source_files(env.core_sources, gen_hash)
  175. # Generate AES256 script encryption key
  176. def encryption_key_builder(target, source, env):
  177. with methods.generated_wrapper(target) as file:
  178. file.write(
  179. f"""\
  180. #include "core/config/project_settings.h"
  181. uint8_t script_encryption_key[32] = {{
  182. {source[0]}
  183. }};"""
  184. )
  185. gdkey = os.environ.get("SCRIPT_AES256_ENCRYPTION_KEY", "0" * 64)
  186. ec_valid = len(gdkey) == 64
  187. if ec_valid:
  188. try:
  189. gdkey = ", ".join([str(int(f"{a}{b}", 16)) for a, b in zip(gdkey[0::2], gdkey[1::2])])
  190. except Exception:
  191. ec_valid = False
  192. if not ec_valid:
  193. methods.print_error(
  194. f'Invalid AES256 encryption key, not 64 hexadecimal characters: "{gdkey}".\n'
  195. "Unset `SCRIPT_AES256_ENCRYPTION_KEY` in your environment "
  196. "or make sure that it contains exactly 64 hexadecimal characters."
  197. )
  198. Exit(255)
  199. gen_encrypt = env.CommandNoCache("script_encryption_key.gen.cpp", env.Value(gdkey), env.Run(encryption_key_builder))
  200. env.add_source_files(env.core_sources, gen_encrypt)
  201. # Certificates
  202. env.Depends(
  203. "#core/io/certs_compressed.gen.h",
  204. ["#thirdparty/certs/ca-certificates.crt", env.Value(env["builtin_certs"]), env.Value(env["system_certs_path"])],
  205. )
  206. env.CommandNoCache(
  207. "#core/io/certs_compressed.gen.h",
  208. "#thirdparty/certs/ca-certificates.crt",
  209. env.Run(core_builders.make_certs_header),
  210. )
  211. # Authors
  212. env.Depends("#core/authors.gen.h", "../AUTHORS.md")
  213. env.CommandNoCache("#core/authors.gen.h", "../AUTHORS.md", env.Run(core_builders.make_authors_header))
  214. # Donors
  215. env.Depends("#core/donors.gen.h", "../DONORS.md")
  216. env.CommandNoCache("#core/donors.gen.h", "../DONORS.md", env.Run(core_builders.make_donors_header))
  217. # License
  218. env.Depends("#core/license.gen.h", ["../COPYRIGHT.txt", "../LICENSE.txt"])
  219. env.CommandNoCache(
  220. "#core/license.gen.h",
  221. ["../COPYRIGHT.txt", "../LICENSE.txt"],
  222. env.Run(core_builders.make_license_header),
  223. )
  224. # Chain load SCsubs
  225. SConscript("os/SCsub")
  226. SConscript("math/SCsub")
  227. SConscript("crypto/SCsub")
  228. SConscript("io/SCsub")
  229. SConscript("debugger/SCsub")
  230. SConscript("input/SCsub")
  231. SConscript("variant/SCsub")
  232. SConscript("extension/SCsub")
  233. SConscript("object/SCsub")
  234. SConscript("templates/SCsub")
  235. SConscript("string/SCsub")
  236. SConscript("config/SCsub")
  237. SConscript("error/SCsub")
  238. # Build it all as a library
  239. lib = env.add_library("core", env.core_sources)
  240. env.Prepend(LIBS=[lib])
  241. # Needed to force rebuilding the core files when the thirdparty code is updated.
  242. env.Depends(lib, thirdparty_obj)