SCsub 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. #!/usr/bin/env python
  2. Import("env")
  3. import core_builders
  4. env.core_sources = []
  5. # Generate AES256 script encryption key
  6. import os
  7. 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"
  8. if "SCRIPT_AES256_ENCRYPTION_KEY" in os.environ:
  9. e = os.environ["SCRIPT_AES256_ENCRYPTION_KEY"]
  10. txt = ""
  11. ec_valid = True
  12. if len(e) != 64:
  13. ec_valid = False
  14. else:
  15. for i in range(len(e) >> 1):
  16. if i > 0:
  17. txt += ","
  18. txts = "0x" + e[i * 2 : i * 2 + 2]
  19. try:
  20. int(txts, 16)
  21. except:
  22. ec_valid = False
  23. txt += txts
  24. if not ec_valid:
  25. 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"
  26. print("Invalid AES256 encryption key, not 64 bits hex: " + e)
  27. # NOTE: It is safe to generate this file here, since this is still executed serially
  28. with open("script_encryption_key.gen.cpp", "w") as f:
  29. f.write('#include "core/config/project_settings.h"\nuint8_t script_encryption_key[32]={' + txt + "};\n")
  30. # Add required thirdparty code.
  31. env_thirdparty = env.Clone()
  32. env_thirdparty.disable_warnings()
  33. # Misc thirdparty code: header paths are hardcoded, we don't need to append
  34. # to the include path (saves a few chars on the compiler invocation for touchy MSVC...)
  35. thirdparty_misc_dir = "#thirdparty/misc/"
  36. thirdparty_misc_sources = [
  37. # C sources
  38. "fastlz.c",
  39. "r128.c",
  40. "smaz.c",
  41. # C++ sources
  42. "pcg.cpp",
  43. "triangulator.cpp",
  44. "clipper.cpp",
  45. ]
  46. thirdparty_misc_sources = [thirdparty_misc_dir + file for file in thirdparty_misc_sources]
  47. env_thirdparty.add_source_files(env.core_sources, thirdparty_misc_sources)
  48. # Zlib library, can be unbundled
  49. if env["builtin_zlib"]:
  50. thirdparty_zlib_dir = "#thirdparty/zlib/"
  51. thirdparty_zlib_sources = [
  52. "adler32.c",
  53. "compress.c",
  54. "crc32.c",
  55. "deflate.c",
  56. "infback.c",
  57. "inffast.c",
  58. "inflate.c",
  59. "inftrees.c",
  60. "trees.c",
  61. "uncompr.c",
  62. "zutil.c",
  63. ]
  64. thirdparty_zlib_sources = [thirdparty_zlib_dir + file for file in thirdparty_zlib_sources]
  65. env_thirdparty.Prepend(CPPPATH=[thirdparty_zlib_dir])
  66. # Needs to be available in main env too
  67. env.Prepend(CPPPATH=[thirdparty_zlib_dir])
  68. if env["target"] == "debug":
  69. env_thirdparty.Append(CPPDEFINES=["ZLIB_DEBUG"])
  70. env_thirdparty.add_source_files(env.core_sources, thirdparty_zlib_sources)
  71. # Minizip library, could be unbundled in theory
  72. # However, our version has some custom modifications, so it won't compile with the system one
  73. thirdparty_minizip_dir = "#thirdparty/minizip/"
  74. thirdparty_minizip_sources = ["ioapi.c", "unzip.c", "zip.c"]
  75. thirdparty_minizip_sources = [thirdparty_minizip_dir + file for file in thirdparty_minizip_sources]
  76. env_thirdparty.add_source_files(env.core_sources, thirdparty_minizip_sources)
  77. # Zstd library, can be unbundled in theory
  78. # though we currently use some private symbols
  79. # https://github.com/godotengine/godot/issues/17374
  80. if env["builtin_zstd"]:
  81. thirdparty_zstd_dir = "#thirdparty/zstd/"
  82. thirdparty_zstd_sources = [
  83. "common/debug.c",
  84. "common/entropy_common.c",
  85. "common/error_private.c",
  86. "common/fse_decompress.c",
  87. "common/pool.c",
  88. "common/threading.c",
  89. "common/xxhash.c",
  90. "common/zstd_common.c",
  91. "compress/fse_compress.c",
  92. "compress/hist.c",
  93. "compress/huf_compress.c",
  94. "compress/zstd_compress.c",
  95. "compress/zstd_double_fast.c",
  96. "compress/zstd_fast.c",
  97. "compress/zstd_lazy.c",
  98. "compress/zstd_ldm.c",
  99. "compress/zstd_opt.c",
  100. "compress/zstdmt_compress.c",
  101. "compress/zstd_compress_literals.c",
  102. "compress/zstd_compress_sequences.c",
  103. "compress/zstd_compress_superblock.c",
  104. "decompress/huf_decompress.c",
  105. "decompress/zstd_ddict.c",
  106. "decompress/zstd_decompress_block.c",
  107. "decompress/zstd_decompress.c",
  108. ]
  109. thirdparty_zstd_sources = [thirdparty_zstd_dir + file for file in thirdparty_zstd_sources]
  110. env_thirdparty.Prepend(CPPPATH=[thirdparty_zstd_dir, thirdparty_zstd_dir + "common"])
  111. env_thirdparty.Append(CPPDEFINES=["ZSTD_STATIC_LINKING_ONLY"])
  112. env.Prepend(CPPPATH=thirdparty_zstd_dir)
  113. # Also needed in main env includes will trigger warnings
  114. env.Append(CPPDEFINES=["ZSTD_STATIC_LINKING_ONLY"])
  115. env_thirdparty.add_source_files(env.core_sources, thirdparty_zstd_sources)
  116. # Godot's own sources
  117. env.add_source_files(env.core_sources, "*.cpp")
  118. # Certificates
  119. env.Depends(
  120. "#core/io/certs_compressed.gen.h",
  121. ["#thirdparty/certs/ca-certificates.crt", env.Value(env["builtin_certs"]), env.Value(env["system_certs_path"])],
  122. )
  123. env.CommandNoCache(
  124. "#core/io/certs_compressed.gen.h",
  125. "#thirdparty/certs/ca-certificates.crt",
  126. env.Run(core_builders.make_certs_header, "Building ca-certificates header."),
  127. )
  128. # Authors
  129. env.Depends("#core/authors.gen.h", "../AUTHORS.md")
  130. env.CommandNoCache(
  131. "#core/authors.gen.h", "../AUTHORS.md", env.Run(core_builders.make_authors_header, "Generating authors header.")
  132. )
  133. # Donors
  134. env.Depends("#core/donors.gen.h", "../DONORS.md")
  135. env.CommandNoCache(
  136. "#core/donors.gen.h", "../DONORS.md", env.Run(core_builders.make_donors_header, "Generating donors header.")
  137. )
  138. # License
  139. env.Depends("#core/license.gen.h", ["../COPYRIGHT.txt", "../LICENSE.txt"])
  140. env.CommandNoCache(
  141. "#core/license.gen.h",
  142. ["../COPYRIGHT.txt", "../LICENSE.txt"],
  143. env.Run(core_builders.make_license_header, "Generating license header."),
  144. )
  145. # Chain load SCsubs
  146. SConscript("os/SCsub")
  147. SConscript("math/SCsub")
  148. SConscript("crypto/SCsub")
  149. SConscript("io/SCsub")
  150. SConscript("debugger/SCsub")
  151. SConscript("input/SCsub")
  152. SConscript("variant/SCsub")
  153. SConscript("object/SCsub")
  154. SConscript("templates/SCsub")
  155. SConscript("string/SCsub")
  156. SConscript("config/SCsub")
  157. SConscript("error/SCsub")
  158. # Build it all as a library
  159. lib = env.add_library("core", env.core_sources)
  160. env.Prepend(LIBS=[lib])