SCsub 6.1 KB

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