SCsub 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. #!/usr/bin/env python
  2. Import("env")
  3. import core_builders
  4. import make_binders
  5. from platform_methods import run_in_subprocess
  6. env.core_sources = []
  7. # Generate AES256 script encryption key
  8. import os
  9. 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"
  10. if "SCRIPT_AES256_ENCRYPTION_KEY" in os.environ:
  11. key = os.environ["SCRIPT_AES256_ENCRYPTION_KEY"]
  12. ec_valid = True
  13. if len(key) != 64:
  14. ec_valid = False
  15. else:
  16. txt = ""
  17. for i in range(len(key) >> 1):
  18. if i > 0:
  19. txt += ","
  20. txts = "0x" + key[i * 2 : i * 2 + 2]
  21. try:
  22. int(txts, 16)
  23. except Exception:
  24. ec_valid = False
  25. txt += txts
  26. if not ec_valid:
  27. print("Error: Invalid AES256 encryption key, not 64 hexadecimal characters: '" + key + "'.")
  28. print(
  29. "Unset 'SCRIPT_AES256_ENCRYPTION_KEY' in your environment "
  30. "or make sure that it contains exactly 64 hexadecimal characters."
  31. )
  32. Exit(255)
  33. # NOTE: It is safe to generate this file here, since this is still executed serially
  34. with open("script_encryption_key.gen.cpp", "w") as f:
  35. f.write('#include "core/project_settings.h"\nuint8_t script_encryption_key[32]={' + txt + "};\n")
  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. "smaz.c",
  47. # C++ sources
  48. "hq2x.cpp",
  49. "pcg.cpp",
  50. "triangulator.cpp",
  51. "clipper.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. # Zlib library, can be unbundled
  56. if env["builtin_zlib"]:
  57. thirdparty_zlib_dir = "#thirdparty/zlib/"
  58. thirdparty_zlib_sources = [
  59. "adler32.c",
  60. "compress.c",
  61. "crc32.c",
  62. "deflate.c",
  63. "inffast.c",
  64. "inflate.c",
  65. "inftrees.c",
  66. "trees.c",
  67. "uncompr.c",
  68. "zutil.c",
  69. ]
  70. thirdparty_zlib_sources = [thirdparty_zlib_dir + file for file in thirdparty_zlib_sources]
  71. env_thirdparty.Prepend(CPPPATH=[thirdparty_zlib_dir])
  72. # Needs to be available in main env too
  73. env.Prepend(CPPPATH=[thirdparty_zlib_dir])
  74. if env["target"] == "debug":
  75. env_thirdparty.Append(CPPDEFINES=["ZLIB_DEBUG"])
  76. env_thirdparty.add_source_files(thirdparty_obj, thirdparty_zlib_sources)
  77. # Minizip library, could be unbundled in theory
  78. # However, our version has some custom modifications, so it won't compile with the system one
  79. thirdparty_minizip_dir = "#thirdparty/minizip/"
  80. thirdparty_minizip_sources = [
  81. "ioapi.c",
  82. "unzip.c",
  83. "zip.c",
  84. ]
  85. thirdparty_minizip_sources = [thirdparty_minizip_dir + file for file in thirdparty_minizip_sources]
  86. env_thirdparty.add_source_files(thirdparty_obj, thirdparty_minizip_sources)
  87. # Zstd library, can be unbundled in theory
  88. # though we currently use some private symbols
  89. # https://github.com/godotengine/godot/issues/17374
  90. if env["builtin_zstd"]:
  91. thirdparty_zstd_dir = "#thirdparty/zstd/"
  92. thirdparty_zstd_sources = [
  93. "common/debug.c",
  94. "common/entropy_common.c",
  95. "common/error_private.c",
  96. "common/fse_decompress.c",
  97. "common/pool.c",
  98. "common/threading.c",
  99. "common/xxhash.c",
  100. "common/zstd_common.c",
  101. "compress/fse_compress.c",
  102. "compress/hist.c",
  103. "compress/huf_compress.c",
  104. "compress/zstd_compress.c",
  105. "compress/zstd_double_fast.c",
  106. "compress/zstd_fast.c",
  107. "compress/zstd_lazy.c",
  108. "compress/zstd_ldm.c",
  109. "compress/zstd_opt.c",
  110. "compress/zstdmt_compress.c",
  111. "compress/zstd_compress_literals.c",
  112. "compress/zstd_compress_sequences.c",
  113. "compress/zstd_compress_superblock.c",
  114. "decompress/huf_decompress.c",
  115. "decompress/zstd_ddict.c",
  116. "decompress/zstd_decompress_block.c",
  117. "decompress/zstd_decompress.c",
  118. ]
  119. if env["platform"] in ["android", "iphone", "osx", "server", "x11"]:
  120. # Match platforms with ZSTD_ASM_SUPPORTED in common/portability_macros.h
  121. thirdparty_zstd_sources.append("decompress/huf_decompress_amd64.S")
  122. thirdparty_zstd_sources = [thirdparty_zstd_dir + file for file in thirdparty_zstd_sources]
  123. env_thirdparty.Prepend(CPPPATH=[thirdparty_zstd_dir, thirdparty_zstd_dir + "common"])
  124. env_thirdparty.Append(CPPDEFINES=["ZSTD_STATIC_LINKING_ONLY"])
  125. env.Prepend(CPPPATH=thirdparty_zstd_dir)
  126. # Also needed in main env includes will trigger warnings
  127. env.Append(CPPDEFINES=["ZSTD_STATIC_LINKING_ONLY"])
  128. env_thirdparty.add_source_files(thirdparty_obj, thirdparty_zstd_sources)
  129. env.core_sources += thirdparty_obj
  130. # Godot source files
  131. env.add_source_files(env.core_sources, "*.cpp")
  132. env.add_source_files(env.core_sources, "script_encryption_key.gen.cpp")
  133. env.add_source_files(env.core_sources, "version_hash.gen.cpp")
  134. # Certificates
  135. env.Depends(
  136. "#core/io/certs_compressed.gen.h",
  137. ["#thirdparty/certs/ca-certificates.crt", env.Value(env["builtin_certs"]), env.Value(env["system_certs_path"])],
  138. )
  139. env.CommandNoCache(
  140. "#core/io/certs_compressed.gen.h",
  141. "#thirdparty/certs/ca-certificates.crt",
  142. run_in_subprocess(core_builders.make_certs_header),
  143. )
  144. # Make binders
  145. env.CommandNoCache(
  146. ["method_bind.gen.inc", "method_bind_ext.gen.inc", "method_bind_free_func.gen.inc"],
  147. "make_binders.py",
  148. run_in_subprocess(make_binders.run),
  149. )
  150. # Authors
  151. env.Depends("#core/authors.gen.h", "../AUTHORS.md")
  152. env.CommandNoCache("#core/authors.gen.h", "../AUTHORS.md", run_in_subprocess(core_builders.make_authors_header))
  153. # Donors
  154. env.Depends("#core/donors.gen.h", "../DONORS.md")
  155. env.CommandNoCache("#core/donors.gen.h", "../DONORS.md", run_in_subprocess(core_builders.make_donors_header))
  156. # License
  157. env.Depends("#core/license.gen.h", ["../COPYRIGHT.txt", "../LICENSE.txt"])
  158. env.CommandNoCache(
  159. "#core/license.gen.h", ["../COPYRIGHT.txt", "../LICENSE.txt"], run_in_subprocess(core_builders.make_license_header)
  160. )
  161. # Chain load SCsubs
  162. SConscript("os/SCsub")
  163. SConscript("math/SCsub")
  164. SConscript("crypto/SCsub")
  165. SConscript("io/SCsub")
  166. SConscript("bind/SCsub")
  167. # Build it all as a library
  168. lib = env.add_library("core", env.core_sources)
  169. env.Prepend(LIBS=[lib])
  170. # Needed to force rebuilding the core files when the thirdparty code is updated.
  171. env.Depends(lib, thirdparty_obj)