SCsub 9.6 KB

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