SConstruct 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034
  1. #!/usr/bin/env python
  2. EnsureSConsVersion(3, 0, 0)
  3. EnsurePythonVersion(3, 6)
  4. # System
  5. import atexit
  6. import glob
  7. import os
  8. import pickle
  9. import sys
  10. import time
  11. from types import ModuleType
  12. from collections import OrderedDict
  13. from importlib.util import spec_from_file_location, module_from_spec
  14. # Explicitly resolve the helper modules, this is done to avoid clash with
  15. # modules of the same name that might be randomly added (e.g. someone adding
  16. # an `editor.py` file at the root of the module creates a clash with the editor
  17. # folder when doing `import editor.template_builder`)
  18. def _helper_module(name, path):
  19. spec = spec_from_file_location(name, path)
  20. module = module_from_spec(spec)
  21. spec.loader.exec_module(module)
  22. sys.modules[name] = module
  23. # Ensure the module's parents are in loaded to avoid loading the wrong parent
  24. # when doing "import foo.bar" while only "foo.bar" as declared as helper module
  25. child_module = module
  26. parent_name = name
  27. while True:
  28. try:
  29. parent_name, child_name = parent_name.rsplit(".", 1)
  30. except ValueError:
  31. break
  32. try:
  33. parent_module = sys.modules[parent_name]
  34. except KeyError:
  35. parent_module = ModuleType(parent_name)
  36. sys.modules[parent_name] = parent_module
  37. setattr(parent_module, child_name, child_module)
  38. _helper_module("gles3_builders", "gles3_builders.py")
  39. _helper_module("glsl_builders", "glsl_builders.py")
  40. _helper_module("methods", "methods.py")
  41. _helper_module("platform_methods", "platform_methods.py")
  42. _helper_module("version", "version.py")
  43. _helper_module("core.core_builders", "core/core_builders.py")
  44. _helper_module("main.main_builders", "main/main_builders.py")
  45. _helper_module("modules.modules_builders", "modules/modules_builders.py")
  46. # Local
  47. import methods
  48. import glsl_builders
  49. import gles3_builders
  50. import scu_builders
  51. from platform_methods import architectures, architecture_aliases, generate_export_icons
  52. if ARGUMENTS.get("target", "editor") == "editor":
  53. _helper_module("editor.editor_builders", "editor/editor_builders.py")
  54. _helper_module("editor.template_builders", "editor/template_builders.py")
  55. # Scan possible build platforms
  56. platform_list = [] # list of platforms
  57. platform_opts = {} # options for each platform
  58. platform_flags = {} # flags for each platform
  59. platform_doc_class_path = {}
  60. platform_exporters = []
  61. platform_apis = []
  62. time_at_start = time.time()
  63. for x in sorted(glob.glob("platform/*")):
  64. if not os.path.isdir(x) or not os.path.exists(x + "/detect.py"):
  65. continue
  66. tmppath = "./" + x
  67. sys.path.insert(0, tmppath)
  68. import detect
  69. # Get doc classes paths (if present)
  70. try:
  71. doc_classes = detect.get_doc_classes()
  72. doc_path = detect.get_doc_path()
  73. for c in doc_classes:
  74. platform_doc_class_path[c] = x.replace("\\", "/") + "/" + doc_path
  75. except Exception:
  76. pass
  77. platform_name = x[9:]
  78. if os.path.exists(x + "/export/export.cpp"):
  79. platform_exporters.append(platform_name)
  80. generate_export_icons(x, platform_name)
  81. if os.path.exists(x + "/api/api.cpp"):
  82. platform_apis.append(platform_name)
  83. if detect.can_build():
  84. x = x.replace("platform/", "") # rest of world
  85. x = x.replace("platform\\", "") # win32
  86. platform_list += [x]
  87. platform_opts[x] = detect.get_opts()
  88. platform_flags[x] = detect.get_flags()
  89. sys.path.remove(tmppath)
  90. sys.modules.pop("detect")
  91. custom_tools = ["default"]
  92. platform_arg = ARGUMENTS.get("platform", ARGUMENTS.get("p", False))
  93. if platform_arg == "android":
  94. custom_tools = ["clang", "clang++", "as", "ar", "link"]
  95. elif platform_arg == "web":
  96. # Use generic POSIX build toolchain for Emscripten.
  97. custom_tools = ["cc", "c++", "ar", "link", "textfile", "zip"]
  98. elif os.name == "nt" and methods.get_cmdline_bool("use_mingw", False):
  99. custom_tools = ["mingw"]
  100. # We let SCons build its default ENV as it includes OS-specific things which we don't
  101. # want to have to pull in manually.
  102. # Then we prepend PATH to make it take precedence, while preserving SCons' own entries.
  103. env_base = Environment(tools=custom_tools)
  104. env_base.PrependENVPath("PATH", os.getenv("PATH"))
  105. env_base.PrependENVPath("PKG_CONFIG_PATH", os.getenv("PKG_CONFIG_PATH"))
  106. if "TERM" in os.environ: # Used for colored output.
  107. env_base["ENV"]["TERM"] = os.environ["TERM"]
  108. env_base.disabled_modules = []
  109. env_base.module_version_string = ""
  110. env_base.msvc = False
  111. env_base.__class__.disable_module = methods.disable_module
  112. env_base.__class__.add_module_version_string = methods.add_module_version_string
  113. env_base.__class__.add_source_files = methods.add_source_files
  114. env_base.__class__.use_windows_spawn_fix = methods.use_windows_spawn_fix
  115. env_base.__class__.add_shared_library = methods.add_shared_library
  116. env_base.__class__.add_library = methods.add_library
  117. env_base.__class__.add_program = methods.add_program
  118. env_base.__class__.CommandNoCache = methods.CommandNoCache
  119. env_base.__class__.Run = methods.Run
  120. env_base.__class__.disable_warnings = methods.disable_warnings
  121. env_base.__class__.force_optimization_on_debug = methods.force_optimization_on_debug
  122. env_base.__class__.module_add_dependencies = methods.module_add_dependencies
  123. env_base.__class__.module_check_dependencies = methods.module_check_dependencies
  124. env_base["x86_libtheora_opt_gcc"] = False
  125. env_base["x86_libtheora_opt_vc"] = False
  126. # avoid issues when building with different versions of python out of the same directory
  127. env_base.SConsignFile(File("#.sconsign{0}.dblite".format(pickle.HIGHEST_PROTOCOL)).abspath)
  128. # Build options
  129. customs = ["custom.py"]
  130. profile = ARGUMENTS.get("profile", "")
  131. if profile:
  132. if os.path.isfile(profile):
  133. customs.append(profile)
  134. elif os.path.isfile(profile + ".py"):
  135. customs.append(profile + ".py")
  136. opts = Variables(customs, ARGUMENTS)
  137. # Target build options
  138. opts.Add("platform", "Target platform (%s)" % ("|".join(platform_list),), "")
  139. opts.Add("p", "Platform (alias for 'platform')", "")
  140. opts.Add(EnumVariable("target", "Compilation target", "editor", ("editor", "template_release", "template_debug")))
  141. opts.Add(EnumVariable("arch", "CPU architecture", "auto", ["auto"] + architectures, architecture_aliases))
  142. opts.Add(BoolVariable("dev_build", "Developer build with dev-only debugging code (DEV_ENABLED)", False))
  143. opts.Add(
  144. EnumVariable(
  145. "optimize", "Optimization level", "speed_trace", ("none", "custom", "debug", "speed", "speed_trace", "size")
  146. )
  147. )
  148. opts.Add(BoolVariable("debug_symbols", "Build with debugging symbols", False))
  149. opts.Add(BoolVariable("separate_debug_symbols", "Extract debugging symbols to a separate file", False))
  150. opts.Add(EnumVariable("lto", "Link-time optimization (production builds)", "none", ("none", "auto", "thin", "full")))
  151. opts.Add(BoolVariable("production", "Set defaults to build Godot for use in production", False))
  152. # Components
  153. opts.Add(BoolVariable("deprecated", "Enable compatibility code for deprecated and removed features", True))
  154. opts.Add(EnumVariable("precision", "Set the floating-point precision level", "single", ("single", "double")))
  155. opts.Add(BoolVariable("minizip", "Enable ZIP archive support using minizip", True))
  156. opts.Add(BoolVariable("brotli", "Enable Brotli for decompresson and WOFF2 fonts support", True))
  157. opts.Add(BoolVariable("xaudio2", "Enable the XAudio2 audio driver", False))
  158. opts.Add(BoolVariable("vulkan", "Enable the vulkan rendering driver", True))
  159. opts.Add(BoolVariable("opengl3", "Enable the OpenGL/GLES3 rendering driver", True))
  160. opts.Add(BoolVariable("openxr", "Enable the OpenXR driver", True))
  161. opts.Add(BoolVariable("use_volk", "Use the volk library to load the Vulkan loader dynamically", True))
  162. opts.Add(BoolVariable("disable_exceptions", "Force disabling exception handling code", True))
  163. opts.Add("custom_modules", "A list of comma-separated directory paths containing custom modules to build.", "")
  164. opts.Add(BoolVariable("custom_modules_recursive", "Detect custom modules recursively for each specified path.", True))
  165. # Advanced options
  166. opts.Add(BoolVariable("dev_mode", "Alias for dev options: verbose=yes warnings=extra werror=yes tests=yes", False))
  167. opts.Add(BoolVariable("tests", "Build the unit tests", False))
  168. opts.Add(BoolVariable("fast_unsafe", "Enable unsafe options for faster rebuilds", False))
  169. opts.Add(BoolVariable("compiledb", "Generate compilation DB (`compile_commands.json`) for external tools", False))
  170. opts.Add(BoolVariable("verbose", "Enable verbose output for the compilation", False))
  171. opts.Add(BoolVariable("progress", "Show a progress indicator during compilation", True))
  172. opts.Add(EnumVariable("warnings", "Level of compilation warnings", "all", ("extra", "all", "moderate", "no")))
  173. opts.Add(BoolVariable("werror", "Treat compiler warnings as errors", False))
  174. opts.Add("extra_suffix", "Custom extra suffix added to the base filename of all generated binary files", "")
  175. opts.Add("object_prefix", "Custom prefix added to the base filename of all generated object files", "")
  176. opts.Add(BoolVariable("vsproj", "Generate a Visual Studio solution", False))
  177. opts.Add("vsproj_name", "Name of the Visual Studio solution", "godot")
  178. opts.Add(BoolVariable("disable_3d", "Disable 3D nodes for a smaller executable", False))
  179. opts.Add(BoolVariable("disable_advanced_gui", "Disable advanced GUI nodes and behaviors", False))
  180. opts.Add("build_profile", "Path to a file containing a feature build profile", "")
  181. opts.Add(BoolVariable("modules_enabled_by_default", "If no, disable all modules except ones explicitly enabled", True))
  182. opts.Add(BoolVariable("no_editor_splash", "Don't use the custom splash screen for the editor", True))
  183. opts.Add(
  184. "system_certs_path",
  185. "Use this path as TLS certificates default for editor and Linux/BSD export templates (for package maintainers)",
  186. "",
  187. )
  188. opts.Add(BoolVariable("use_precise_math_checks", "Math checks use very precise epsilon (debug option)", False))
  189. opts.Add(BoolVariable("scu_build", "Use single compilation unit build", False))
  190. opts.Add("scu_limit", "Max includes per SCU file when using scu_build (determines RAM use)", "0")
  191. # Thirdparty libraries
  192. opts.Add(BoolVariable("builtin_brotli", "Use the built-in Brotli library", True))
  193. opts.Add(BoolVariable("builtin_certs", "Use the built-in SSL certificates bundles", True))
  194. opts.Add(BoolVariable("builtin_clipper2", "Use the built-in Clipper2 library", True))
  195. opts.Add(BoolVariable("builtin_embree", "Use the built-in Embree library", True))
  196. opts.Add(BoolVariable("builtin_enet", "Use the built-in ENet library", True))
  197. opts.Add(BoolVariable("builtin_freetype", "Use the built-in FreeType library", True))
  198. opts.Add(BoolVariable("builtin_msdfgen", "Use the built-in MSDFgen library", True))
  199. opts.Add(BoolVariable("builtin_glslang", "Use the built-in glslang library", True))
  200. opts.Add(BoolVariable("builtin_graphite", "Use the built-in Graphite library", True))
  201. opts.Add(BoolVariable("builtin_harfbuzz", "Use the built-in HarfBuzz library", True))
  202. opts.Add(BoolVariable("builtin_icu4c", "Use the built-in ICU library", True))
  203. opts.Add(BoolVariable("builtin_libogg", "Use the built-in libogg library", True))
  204. opts.Add(BoolVariable("builtin_libpng", "Use the built-in libpng library", True))
  205. opts.Add(BoolVariable("builtin_libtheora", "Use the built-in libtheora library", True))
  206. opts.Add(BoolVariable("builtin_libvorbis", "Use the built-in libvorbis library", True))
  207. opts.Add(BoolVariable("builtin_libwebp", "Use the built-in libwebp library", True))
  208. opts.Add(BoolVariable("builtin_wslay", "Use the built-in wslay library", True))
  209. opts.Add(BoolVariable("builtin_mbedtls", "Use the built-in mbedTLS library", True))
  210. opts.Add(BoolVariable("builtin_miniupnpc", "Use the built-in miniupnpc library", True))
  211. opts.Add(BoolVariable("builtin_openxr", "Use the built-in OpenXR library", True))
  212. opts.Add(BoolVariable("builtin_pcre2", "Use the built-in PCRE2 library", True))
  213. opts.Add(BoolVariable("builtin_pcre2_with_jit", "Use JIT compiler for the built-in PCRE2 library", True))
  214. opts.Add(BoolVariable("builtin_recastnavigation", "Use the built-in Recast navigation library", True))
  215. opts.Add(BoolVariable("builtin_rvo2_2d", "Use the built-in RVO2 2D library", True))
  216. opts.Add(BoolVariable("builtin_rvo2_3d", "Use the built-in RVO2 3D library", True))
  217. opts.Add(BoolVariable("builtin_squish", "Use the built-in squish library", True))
  218. opts.Add(BoolVariable("builtin_xatlas", "Use the built-in xatlas library", True))
  219. opts.Add(BoolVariable("builtin_zlib", "Use the built-in zlib library", True))
  220. opts.Add(BoolVariable("builtin_zstd", "Use the built-in Zstd library", True))
  221. # Compilation environment setup
  222. opts.Add("CXX", "C++ compiler")
  223. opts.Add("CC", "C compiler")
  224. opts.Add("LINK", "Linker")
  225. opts.Add("CCFLAGS", "Custom flags for both the C and C++ compilers")
  226. opts.Add("CFLAGS", "Custom flags for the C compiler")
  227. opts.Add("CXXFLAGS", "Custom flags for the C++ compiler")
  228. opts.Add("LINKFLAGS", "Custom flags for the linker")
  229. # Update the environment to have all above options defined
  230. # in following code (especially platform and custom_modules).
  231. opts.Update(env_base)
  232. # Platform selection: validate input, and add options.
  233. selected_platform = ""
  234. if env_base["platform"] != "":
  235. selected_platform = env_base["platform"]
  236. elif env_base["p"] != "":
  237. selected_platform = env_base["p"]
  238. else:
  239. # Missing `platform` argument, try to detect platform automatically
  240. if (
  241. sys.platform.startswith("linux")
  242. or sys.platform.startswith("dragonfly")
  243. or sys.platform.startswith("freebsd")
  244. or sys.platform.startswith("netbsd")
  245. or sys.platform.startswith("openbsd")
  246. ):
  247. selected_platform = "linuxbsd"
  248. elif sys.platform == "darwin":
  249. selected_platform = "macos"
  250. elif sys.platform == "win32":
  251. selected_platform = "windows"
  252. else:
  253. print("Could not detect platform automatically. Supported platforms:")
  254. for x in platform_list:
  255. print("\t" + x)
  256. print("\nPlease run SCons again and select a valid platform: platform=<string>")
  257. if selected_platform != "":
  258. print("Automatically detected platform: " + selected_platform)
  259. if selected_platform in ["macos", "osx"]:
  260. if selected_platform == "osx":
  261. # Deprecated alias kept for compatibility.
  262. print('Platform "osx" has been renamed to "macos" in Godot 4. Building for platform "macos".')
  263. # Alias for convenience.
  264. selected_platform = "macos"
  265. if selected_platform in ["ios", "iphone"]:
  266. if selected_platform == "iphone":
  267. # Deprecated alias kept for compatibility.
  268. print('Platform "iphone" has been renamed to "ios" in Godot 4. Building for platform "ios".')
  269. # Alias for convenience.
  270. selected_platform = "ios"
  271. if selected_platform in ["linux", "bsd", "x11"]:
  272. if selected_platform == "x11":
  273. # Deprecated alias kept for compatibility.
  274. print('Platform "x11" has been renamed to "linuxbsd" in Godot 4. Building for platform "linuxbsd".')
  275. # Alias for convenience.
  276. selected_platform = "linuxbsd"
  277. # Make sure to update this to the found, valid platform as it's used through the buildsystem as the reference.
  278. # It should always be re-set after calling `opts.Update()` otherwise it uses the original input value.
  279. env_base["platform"] = selected_platform
  280. # Add platform-specific options.
  281. if selected_platform in platform_opts:
  282. for opt in platform_opts[selected_platform]:
  283. opts.Add(opt)
  284. # Update the environment to take platform-specific options into account.
  285. opts.Update(env_base)
  286. env_base["platform"] = selected_platform # Must always be re-set after calling opts.Update().
  287. # Detect modules.
  288. modules_detected = OrderedDict()
  289. module_search_paths = ["modules"] # Built-in path.
  290. if env_base["custom_modules"]:
  291. paths = env_base["custom_modules"].split(",")
  292. for p in paths:
  293. try:
  294. module_search_paths.append(methods.convert_custom_modules_path(p))
  295. except ValueError as e:
  296. print(e)
  297. Exit(255)
  298. for path in module_search_paths:
  299. if path == "modules":
  300. # Built-in modules don't have nested modules,
  301. # so save the time it takes to parse directories.
  302. modules = methods.detect_modules(path, recursive=False)
  303. else: # Custom.
  304. modules = methods.detect_modules(path, env_base["custom_modules_recursive"])
  305. # Provide default include path for both the custom module search `path`
  306. # and the base directory containing custom modules, as it may be different
  307. # from the built-in "modules" name (e.g. "custom_modules/summator/summator.h"),
  308. # so it can be referenced simply as `#include "summator/summator.h"`
  309. # independently of where a module is located on user's filesystem.
  310. env_base.Prepend(CPPPATH=[path, os.path.dirname(path)])
  311. # Note: custom modules can override built-in ones.
  312. modules_detected.update(modules)
  313. # Add module options.
  314. for name, path in modules_detected.items():
  315. sys.path.insert(0, path)
  316. import config
  317. if env_base["modules_enabled_by_default"]:
  318. enabled = True
  319. try:
  320. enabled = config.is_enabled()
  321. except AttributeError:
  322. pass
  323. else:
  324. enabled = False
  325. opts.Add(BoolVariable("module_" + name + "_enabled", "Enable module '%s'" % (name,), enabled))
  326. # Add module-specific options.
  327. try:
  328. for opt in config.get_opts(selected_platform):
  329. opts.Add(opt)
  330. except AttributeError:
  331. pass
  332. sys.path.remove(path)
  333. sys.modules.pop("config")
  334. methods.write_modules(modules_detected)
  335. # Update the environment again after all the module options are added.
  336. opts.Update(env_base)
  337. env_base["platform"] = selected_platform # Must always be re-set after calling opts.Update().
  338. Help(opts.GenerateHelpText(env_base))
  339. # add default include paths
  340. env_base.Prepend(CPPPATH=["#"])
  341. # configure ENV for platform
  342. env_base.platform_exporters = platform_exporters
  343. env_base.platform_apis = platform_apis
  344. # Configuration of build targets:
  345. # - Editor or template
  346. # - Debug features (DEBUG_ENABLED code)
  347. # - Dev only code (DEV_ENABLED code)
  348. # - Optimization level
  349. # - Debug symbols for crash traces / debuggers
  350. env_base.editor_build = env_base["target"] == "editor"
  351. env_base.dev_build = env_base["dev_build"]
  352. env_base.debug_features = env_base["target"] in ["editor", "template_debug"]
  353. if env_base.dev_build:
  354. opt_level = "none"
  355. elif env_base.debug_features:
  356. opt_level = "speed_trace"
  357. else: # Release
  358. opt_level = "speed"
  359. env_base["optimize"] = ARGUMENTS.get("optimize", opt_level)
  360. env_base["debug_symbols"] = methods.get_cmdline_bool("debug_symbols", env_base.dev_build)
  361. if env_base.editor_build:
  362. env_base.Append(CPPDEFINES=["TOOLS_ENABLED"])
  363. if env_base.debug_features:
  364. # DEBUG_ENABLED enables debugging *features* and debug-only code, which is intended
  365. # to give *users* extra debugging information for their game development.
  366. env_base.Append(CPPDEFINES=["DEBUG_ENABLED"])
  367. if env_base.dev_build:
  368. # DEV_ENABLED enables *engine developer* code which should only be compiled for those
  369. # working on the engine itself.
  370. env_base.Append(CPPDEFINES=["DEV_ENABLED"])
  371. else:
  372. # Disable assert() for production targets (only used in thirdparty code).
  373. env_base.Append(CPPDEFINES=["NDEBUG"])
  374. # SCons speed optimization controlled by the `fast_unsafe` option, which provide
  375. # more than 10 s speed up for incremental rebuilds.
  376. # Unsafe as they reduce the certainty of rebuilding all changed files, so it's
  377. # enabled by default for `debug` builds, and can be overridden from command line.
  378. # Ref: https://github.com/SCons/scons/wiki/GoFastButton
  379. if methods.get_cmdline_bool("fast_unsafe", env_base.dev_build):
  380. # Renamed to `content-timestamp` in SCons >= 4.2, keeping MD5 for compat.
  381. env_base.Decider("MD5-timestamp")
  382. env_base.SetOption("implicit_cache", 1)
  383. env_base.SetOption("max_drift", 60)
  384. if env_base["use_precise_math_checks"]:
  385. env_base.Append(CPPDEFINES=["PRECISE_MATH_CHECKS"])
  386. if not env_base.File("#main/splash_editor.png").exists():
  387. # Force disabling editor splash if missing.
  388. env_base["no_editor_splash"] = True
  389. if env_base["no_editor_splash"]:
  390. env_base.Append(CPPDEFINES=["NO_EDITOR_SPLASH"])
  391. if not env_base["deprecated"]:
  392. env_base.Append(CPPDEFINES=["DISABLE_DEPRECATED"])
  393. if env_base["precision"] == "double":
  394. env_base.Append(CPPDEFINES=["REAL_T_IS_DOUBLE"])
  395. if selected_platform in platform_list:
  396. tmppath = "./platform/" + selected_platform
  397. sys.path.insert(0, tmppath)
  398. import detect
  399. env = env_base.Clone()
  400. # Default num_jobs to local cpu count if not user specified.
  401. # SCons has a peculiarity where user-specified options won't be overridden
  402. # by SetOption, so we can rely on this to know if we should use our default.
  403. initial_num_jobs = env.GetOption("num_jobs")
  404. altered_num_jobs = initial_num_jobs + 1
  405. env.SetOption("num_jobs", altered_num_jobs)
  406. if env.GetOption("num_jobs") == altered_num_jobs:
  407. cpu_count = os.cpu_count()
  408. if cpu_count is None:
  409. print("Couldn't auto-detect CPU count to configure build parallelism. Specify it with the -j argument.")
  410. else:
  411. safer_cpu_count = cpu_count if cpu_count <= 4 else cpu_count - 1
  412. print(
  413. "Auto-detected %d CPU cores available for build parallelism. Using %d cores by default. You can override it with the -j argument."
  414. % (cpu_count, safer_cpu_count)
  415. )
  416. env.SetOption("num_jobs", safer_cpu_count)
  417. env.extra_suffix = ""
  418. if env["extra_suffix"] != "":
  419. env.extra_suffix += "." + env["extra_suffix"]
  420. # Environment flags
  421. CCFLAGS = env.get("CCFLAGS", "")
  422. env["CCFLAGS"] = ""
  423. env.Append(CCFLAGS=str(CCFLAGS).split())
  424. CFLAGS = env.get("CFLAGS", "")
  425. env["CFLAGS"] = ""
  426. env.Append(CFLAGS=str(CFLAGS).split())
  427. CXXFLAGS = env.get("CXXFLAGS", "")
  428. env["CXXFLAGS"] = ""
  429. env.Append(CXXFLAGS=str(CXXFLAGS).split())
  430. LINKFLAGS = env.get("LINKFLAGS", "")
  431. env["LINKFLAGS"] = ""
  432. env.Append(LINKFLAGS=str(LINKFLAGS).split())
  433. # Feature build profile
  434. disabled_classes = []
  435. if env["build_profile"] != "":
  436. print("Using feature build profile: " + env["build_profile"])
  437. import json
  438. try:
  439. ft = json.load(open(env["build_profile"]))
  440. if "disabled_classes" in ft:
  441. disabled_classes = ft["disabled_classes"]
  442. if "disabled_build_options" in ft:
  443. dbo = ft["disabled_build_options"]
  444. for c in dbo:
  445. env[c] = dbo[c]
  446. except:
  447. print("Error opening feature build profile: " + env["build_profile"])
  448. Exit(255)
  449. methods.write_disabled_classes(disabled_classes)
  450. # Platform specific flags.
  451. # These can sometimes override default options.
  452. flag_list = platform_flags[selected_platform]
  453. for f in flag_list:
  454. if not (f[0] in ARGUMENTS) or ARGUMENTS[f[0]] == "auto": # Allow command line to override platform flags
  455. env[f[0]] = f[1]
  456. # 'dev_mode' and 'production' are aliases to set default options if they haven't been
  457. # set manually by the user.
  458. # These need to be checked *after* platform specific flags so that different
  459. # default values can be set (e.g. to keep LTO off for `production` on some platforms).
  460. if env["dev_mode"]:
  461. env["verbose"] = methods.get_cmdline_bool("verbose", True)
  462. env["warnings"] = ARGUMENTS.get("warnings", "extra")
  463. env["werror"] = methods.get_cmdline_bool("werror", True)
  464. env["tests"] = methods.get_cmdline_bool("tests", True)
  465. if env["production"]:
  466. env["use_static_cpp"] = methods.get_cmdline_bool("use_static_cpp", True)
  467. env["debug_symbols"] = methods.get_cmdline_bool("debug_symbols", False)
  468. # LTO "auto" means we handle the preferred option in each platform detect.py.
  469. env["lto"] = ARGUMENTS.get("lto", "auto")
  470. # Run SCU file generation script if in a SCU build.
  471. if env["scu_build"]:
  472. max_includes_per_scu = 8
  473. if env_base.dev_build == True:
  474. max_includes_per_scu = 1024
  475. read_scu_limit = int(env["scu_limit"])
  476. read_scu_limit = max(0, min(read_scu_limit, 1024))
  477. if read_scu_limit != 0:
  478. max_includes_per_scu = read_scu_limit
  479. methods.set_scu_folders(scu_builders.generate_scu_files(max_includes_per_scu))
  480. # Must happen after the flags' definition, as configure is when most flags
  481. # are actually handled to change compile options, etc.
  482. detect.configure(env)
  483. print(f'Building for platform "{selected_platform}", architecture "{env["arch"]}", target "{env["target"]}".')
  484. if env.dev_build:
  485. print("NOTE: Developer build, with debug optimization level and debug symbols (unless overridden).")
  486. # Set optimize and debug_symbols flags.
  487. # "custom" means do nothing and let users set their own optimization flags.
  488. # Needs to happen after configure to have `env.msvc` defined.
  489. if env.msvc:
  490. if env["debug_symbols"]:
  491. env.Append(CCFLAGS=["/Zi", "/FS"])
  492. env.Append(LINKFLAGS=["/DEBUG:FULL"])
  493. else:
  494. env.Append(LINKFLAGS=["/DEBUG:NONE"])
  495. if env["optimize"] == "speed":
  496. env.Append(CCFLAGS=["/O2"])
  497. env.Append(LINKFLAGS=["/OPT:REF"])
  498. elif env["optimize"] == "speed_trace":
  499. env.Append(CCFLAGS=["/O2"])
  500. env.Append(LINKFLAGS=["/OPT:REF", "/OPT:NOICF"])
  501. elif env["optimize"] == "size":
  502. env.Append(CCFLAGS=["/O1"])
  503. env.Append(LINKFLAGS=["/OPT:REF"])
  504. elif env["optimize"] == "debug" or env["optimize"] == "none":
  505. env.Append(CCFLAGS=["/Od"])
  506. else:
  507. if env["debug_symbols"]:
  508. # Adding dwarf-4 explicitly makes stacktraces work with clang builds,
  509. # otherwise addr2line doesn't understand them
  510. env.Append(CCFLAGS=["-gdwarf-4"])
  511. if env.dev_build:
  512. env.Append(CCFLAGS=["-g3"])
  513. else:
  514. env.Append(CCFLAGS=["-g2"])
  515. else:
  516. if methods.using_clang(env) and not methods.is_vanilla_clang(env):
  517. # Apple Clang, its linker doesn't like -s.
  518. env.Append(LINKFLAGS=["-Wl,-S", "-Wl,-x", "-Wl,-dead_strip"])
  519. else:
  520. env.Append(LINKFLAGS=["-s"])
  521. if env["optimize"] == "speed":
  522. env.Append(CCFLAGS=["-O3"])
  523. # `-O2` is friendlier to debuggers than `-O3`, leading to better crash backtraces.
  524. elif env["optimize"] == "speed_trace":
  525. env.Append(CCFLAGS=["-O2"])
  526. elif env["optimize"] == "size":
  527. env.Append(CCFLAGS=["-Os"])
  528. elif env["optimize"] == "debug":
  529. env.Append(CCFLAGS=["-Og"])
  530. elif env["optimize"] == "none":
  531. env.Append(CCFLAGS=["-O0"])
  532. # Needs to happen after configure to handle "auto".
  533. if env["lto"] != "none":
  534. print("Using LTO: " + env["lto"])
  535. # Set our C and C++ standard requirements.
  536. # C++17 is required as we need guaranteed copy elision as per GH-36436.
  537. # Prepending to make it possible to override.
  538. # This needs to come after `configure`, otherwise we don't have env.msvc.
  539. if not env.msvc:
  540. # Specifying GNU extensions support explicitly, which are supported by
  541. # both GCC and Clang. Both currently default to gnu11 and gnu++14.
  542. env.Prepend(CFLAGS=["-std=gnu11"])
  543. env.Prepend(CXXFLAGS=["-std=gnu++17"])
  544. else:
  545. # MSVC doesn't have clear C standard support, /std only covers C++.
  546. # We apply it to CCFLAGS (both C and C++ code) in case it impacts C features.
  547. env.Prepend(CCFLAGS=["/std:c++17"])
  548. # Enforce our minimal compiler version requirements
  549. cc_version = methods.get_compiler_version(env) or {
  550. "major": None,
  551. "minor": None,
  552. "patch": None,
  553. "metadata1": None,
  554. "metadata2": None,
  555. "date": None,
  556. }
  557. cc_version_major = int(cc_version["major"] or -1)
  558. cc_version_minor = int(cc_version["minor"] or -1)
  559. cc_version_metadata1 = cc_version["metadata1"] or ""
  560. if methods.using_gcc(env):
  561. if cc_version_major == -1:
  562. print(
  563. "Couldn't detect compiler version, skipping version checks. "
  564. "Build may fail if the compiler doesn't support C++17 fully."
  565. )
  566. # GCC 8 before 8.4 has a regression in the support of guaranteed copy elision
  567. # which causes a build failure: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86521
  568. elif cc_version_major == 8 and cc_version_minor < 4:
  569. print(
  570. "Detected GCC 8 version < 8.4, which is not supported due to a "
  571. "regression in its C++17 guaranteed copy elision support. Use a "
  572. 'newer GCC version, or Clang 6 or later by passing "use_llvm=yes" '
  573. "to the SCons command line."
  574. )
  575. Exit(255)
  576. elif cc_version_major < 7:
  577. print(
  578. "Detected GCC version older than 7, which does not fully support "
  579. "C++17. Supported versions are GCC 7, 9 and later. Use a newer GCC "
  580. 'version, or Clang 6 or later by passing "use_llvm=yes" to the '
  581. "SCons command line."
  582. )
  583. Exit(255)
  584. elif cc_version_metadata1 == "win32":
  585. print(
  586. "Detected mingw version is not using posix threads. Only posix "
  587. "version of mingw is supported. "
  588. 'Use "update-alternatives --config x86_64-w64-mingw32-g++" '
  589. "to switch to posix threads."
  590. )
  591. Exit(255)
  592. elif methods.using_clang(env):
  593. if cc_version_major == -1:
  594. print(
  595. "Couldn't detect compiler version, skipping version checks. "
  596. "Build may fail if the compiler doesn't support C++17 fully."
  597. )
  598. # Apple LLVM versions differ from upstream LLVM version \o/, compare
  599. # in https://en.wikipedia.org/wiki/Xcode#Toolchain_versions
  600. elif env["platform"] == "macos" or env["platform"] == "ios":
  601. vanilla = methods.is_vanilla_clang(env)
  602. if vanilla and cc_version_major < 6:
  603. print(
  604. "Detected Clang version older than 6, which does not fully support "
  605. "C++17. Supported versions are Clang 6 and later."
  606. )
  607. Exit(255)
  608. elif not vanilla and cc_version_major < 10:
  609. print(
  610. "Detected Apple Clang version older than 10, which does not fully "
  611. "support C++17. Supported versions are Apple Clang 10 and later."
  612. )
  613. Exit(255)
  614. elif cc_version_major < 6:
  615. print(
  616. "Detected Clang version older than 6, which does not fully support "
  617. "C++17. Supported versions are Clang 6 and later."
  618. )
  619. Exit(255)
  620. # Disable exception handling. Godot doesn't use exceptions anywhere, and this
  621. # saves around 20% of binary size and very significant build time (GH-80513).
  622. if env["disable_exceptions"]:
  623. if env.msvc:
  624. env.Append(CPPDEFINES=[("_HAS_EXCEPTIONS", 0)])
  625. else:
  626. env.Append(CXXFLAGS=["-fno-exceptions"])
  627. elif env.msvc:
  628. env.Append(CXXFLAGS=["/EHsc"])
  629. # Configure compiler warnings
  630. if env.msvc: # MSVC
  631. if env["warnings"] == "no":
  632. env.Append(CCFLAGS=["/w"])
  633. else:
  634. if env["warnings"] == "extra":
  635. env.Append(CCFLAGS=["/W4"])
  636. elif env["warnings"] == "all":
  637. # C4458 is like -Wshadow. Part of /W4 but let's apply it for the default /W3 too.
  638. env.Append(CCFLAGS=["/W3", "/w34458"])
  639. elif env["warnings"] == "moderate":
  640. env.Append(CCFLAGS=["/W2"])
  641. # Disable warnings which we don't plan to fix.
  642. env.Append(
  643. CCFLAGS=[
  644. "/wd4100", # C4100 (unreferenced formal parameter): Doesn't play nice with polymorphism.
  645. "/wd4127", # C4127 (conditional expression is constant)
  646. "/wd4201", # C4201 (non-standard nameless struct/union): Only relevant for C89.
  647. "/wd4244", # C4244 C4245 C4267 (narrowing conversions): Unavoidable at this scale.
  648. "/wd4245",
  649. "/wd4267",
  650. "/wd4305", # C4305 (truncation): double to float or real_t, too hard to avoid.
  651. "/wd4514", # C4514 (unreferenced inline function has been removed)
  652. "/wd4714", # C4714 (function marked as __forceinline not inlined)
  653. "/wd4820", # C4820 (padding added after construct)
  654. ]
  655. )
  656. if env["werror"]:
  657. env.Append(CCFLAGS=["/WX"])
  658. env.Append(LINKFLAGS=["/WX"])
  659. else: # GCC, Clang
  660. common_warnings = []
  661. if methods.using_gcc(env):
  662. common_warnings += ["-Wshadow", "-Wno-misleading-indentation"]
  663. if cc_version_major == 7: # Bogus warning fixed in 8+.
  664. common_warnings += ["-Wno-strict-overflow"]
  665. if cc_version_major < 11:
  666. # Regression in GCC 9/10, spams so much in our variadic templates
  667. # that we need to outright disable it.
  668. common_warnings += ["-Wno-type-limits"]
  669. if cc_version_major >= 12: # False positives in our error macros, see GH-58747.
  670. common_warnings += ["-Wno-return-type"]
  671. elif methods.using_clang(env) or methods.using_emcc(env):
  672. common_warnings += ["-Wshadow-field-in-constructor", "-Wshadow-uncaptured-local"]
  673. # We often implement `operator<` for structs of pointers as a requirement
  674. # for putting them in `Set` or `Map`. We don't mind about unreliable ordering.
  675. common_warnings += ["-Wno-ordered-compare-function-pointers"]
  676. if env["warnings"] == "extra":
  677. env.Append(CCFLAGS=["-Wall", "-Wextra", "-Wwrite-strings", "-Wno-unused-parameter"] + common_warnings)
  678. env.Append(CXXFLAGS=["-Wctor-dtor-privacy", "-Wnon-virtual-dtor"])
  679. if methods.using_gcc(env):
  680. env.Append(
  681. CCFLAGS=[
  682. "-Walloc-zero",
  683. "-Wduplicated-branches",
  684. "-Wduplicated-cond",
  685. "-Wstringop-overflow=4",
  686. ]
  687. )
  688. env.Append(CXXFLAGS=["-Wplacement-new=1"])
  689. # Need to fix a warning with AudioServer lambdas before enabling.
  690. # if cc_version_major != 9: # GCC 9 had a regression (GH-36325).
  691. # env.Append(CXXFLAGS=["-Wnoexcept"])
  692. if cc_version_major >= 9:
  693. env.Append(CCFLAGS=["-Wattribute-alias=2"])
  694. if cc_version_major >= 11: # Broke on MethodBind templates before GCC 11.
  695. env.Append(CCFLAGS=["-Wlogical-op"])
  696. elif methods.using_clang(env) or methods.using_emcc(env):
  697. env.Append(CCFLAGS=["-Wimplicit-fallthrough"])
  698. elif env["warnings"] == "all":
  699. env.Append(CCFLAGS=["-Wall"] + common_warnings)
  700. elif env["warnings"] == "moderate":
  701. env.Append(CCFLAGS=["-Wall", "-Wno-unused"] + common_warnings)
  702. else: # 'no'
  703. env.Append(CCFLAGS=["-w"])
  704. if env["werror"]:
  705. env.Append(CCFLAGS=["-Werror"])
  706. if hasattr(detect, "get_program_suffix"):
  707. suffix = "." + detect.get_program_suffix()
  708. else:
  709. suffix = "." + selected_platform
  710. suffix += "." + env["target"]
  711. if env.dev_build:
  712. suffix += ".dev"
  713. if env_base["precision"] == "double":
  714. suffix += ".double"
  715. suffix += "." + env["arch"]
  716. suffix += env.extra_suffix
  717. sys.path.remove(tmppath)
  718. sys.modules.pop("detect")
  719. modules_enabled = OrderedDict()
  720. env.module_dependencies = {}
  721. env.module_icons_paths = []
  722. env.doc_class_path = platform_doc_class_path
  723. for name, path in modules_detected.items():
  724. if not env["module_" + name + "_enabled"]:
  725. continue
  726. sys.path.insert(0, path)
  727. env.current_module = name
  728. import config
  729. if config.can_build(env, selected_platform):
  730. # Disable it if a required dependency is missing.
  731. if not env.module_check_dependencies(name):
  732. continue
  733. config.configure(env)
  734. # Get doc classes paths (if present)
  735. try:
  736. doc_classes = config.get_doc_classes()
  737. doc_path = config.get_doc_path()
  738. for c in doc_classes:
  739. env.doc_class_path[c] = path + "/" + doc_path
  740. except Exception:
  741. pass
  742. # Get icon paths (if present)
  743. try:
  744. icons_path = config.get_icons_path()
  745. env.module_icons_paths.append(path + "/" + icons_path)
  746. except Exception:
  747. # Default path for module icons
  748. env.module_icons_paths.append(path + "/" + "icons")
  749. modules_enabled[name] = path
  750. sys.path.remove(path)
  751. sys.modules.pop("config")
  752. env.module_list = modules_enabled
  753. methods.sort_module_list(env)
  754. if env.editor_build:
  755. # Add editor-specific dependencies to the dependency graph.
  756. env.module_add_dependencies("editor", ["freetype", "svg"])
  757. # And check if they are met.
  758. if not env.module_check_dependencies("editor"):
  759. print("Not all modules required by editor builds are enabled.")
  760. Exit(255)
  761. methods.generate_version_header(env.module_version_string)
  762. env["PROGSUFFIX_WRAP"] = suffix + env.module_version_string + ".console" + env["PROGSUFFIX"]
  763. env["PROGSUFFIX"] = suffix + env.module_version_string + env["PROGSUFFIX"]
  764. env["OBJSUFFIX"] = suffix + env["OBJSUFFIX"]
  765. # (SH)LIBSUFFIX will be used for our own built libraries
  766. # LIBSUFFIXES contains LIBSUFFIX and SHLIBSUFFIX by default,
  767. # so we need to append the default suffixes to keep the ability
  768. # to link against thirdparty libraries (.a, .so, .lib, etc.).
  769. if os.name == "nt":
  770. # On Windows, only static libraries and import libraries can be
  771. # statically linked - both using .lib extension
  772. env["LIBSUFFIXES"] += [env["LIBSUFFIX"]]
  773. else:
  774. env["LIBSUFFIXES"] += [env["LIBSUFFIX"], env["SHLIBSUFFIX"]]
  775. env["LIBSUFFIX"] = suffix + env["LIBSUFFIX"]
  776. env["SHLIBSUFFIX"] = suffix + env["SHLIBSUFFIX"]
  777. env["OBJPREFIX"] = env["object_prefix"]
  778. env["SHOBJPREFIX"] = env["object_prefix"]
  779. if env["disable_3d"]:
  780. if env.editor_build:
  781. print("Build option 'disable_3d=yes' cannot be used for editor builds, only for export template builds.")
  782. Exit(255)
  783. else:
  784. env.Append(CPPDEFINES=["_3D_DISABLED"])
  785. if env["disable_advanced_gui"]:
  786. if env.editor_build:
  787. print(
  788. "Build option 'disable_advanced_gui=yes' cannot be used for editor builds, "
  789. "only for export template builds."
  790. )
  791. Exit(255)
  792. else:
  793. env.Append(CPPDEFINES=["ADVANCED_GUI_DISABLED"])
  794. if env["minizip"]:
  795. env.Append(CPPDEFINES=["MINIZIP_ENABLED"])
  796. if env["brotli"]:
  797. env.Append(CPPDEFINES=["BROTLI_ENABLED"])
  798. if not env["verbose"]:
  799. methods.no_verbose(sys, env)
  800. GLSL_BUILDERS = {
  801. "RD_GLSL": env.Builder(
  802. action=env.Run(glsl_builders.build_rd_headers, 'Building RD_GLSL header: "$TARGET"'),
  803. suffix="glsl.gen.h",
  804. src_suffix=".glsl",
  805. ),
  806. "GLSL_HEADER": env.Builder(
  807. action=env.Run(glsl_builders.build_raw_headers, 'Building GLSL header: "$TARGET"'),
  808. suffix="glsl.gen.h",
  809. src_suffix=".glsl",
  810. ),
  811. "GLES3_GLSL": env.Builder(
  812. action=env.Run(gles3_builders.build_gles3_headers, 'Building GLES3 GLSL header: "$TARGET"'),
  813. suffix="glsl.gen.h",
  814. src_suffix=".glsl",
  815. ),
  816. }
  817. env.Append(BUILDERS=GLSL_BUILDERS)
  818. scons_cache_path = os.environ.get("SCONS_CACHE")
  819. if scons_cache_path != None:
  820. CacheDir(scons_cache_path)
  821. print("Scons cache enabled... (path: '" + scons_cache_path + "')")
  822. if env["vsproj"]:
  823. env.vs_incs = []
  824. env.vs_srcs = []
  825. if env["compiledb"]:
  826. # Generating the compilation DB (`compile_commands.json`) requires SCons 4.0.0 or later.
  827. from SCons import __version__ as scons_raw_version
  828. scons_ver = env._get_major_minor_revision(scons_raw_version)
  829. if scons_ver < (4, 0, 0):
  830. print("The `compiledb=yes` option requires SCons 4.0 or later, but your version is %s." % scons_raw_version)
  831. Exit(255)
  832. env.Tool("compilation_db")
  833. env.Alias("compiledb", env.CompilationDatabase())
  834. Export("env")
  835. # Build subdirs, the build order is dependent on link order.
  836. SConscript("core/SCsub")
  837. SConscript("servers/SCsub")
  838. SConscript("scene/SCsub")
  839. if env.editor_build:
  840. SConscript("editor/SCsub")
  841. SConscript("drivers/SCsub")
  842. SConscript("platform/SCsub")
  843. SConscript("modules/SCsub")
  844. if env["tests"]:
  845. SConscript("tests/SCsub")
  846. SConscript("main/SCsub")
  847. SConscript("platform/" + selected_platform + "/SCsub") # Build selected platform.
  848. # Microsoft Visual Studio Project Generation
  849. if env["vsproj"]:
  850. if os.name != "nt":
  851. print("Error: The `vsproj` option is only usable on Windows with Visual Studio.")
  852. Exit(255)
  853. env["CPPPATH"] = [Dir(path) for path in env["CPPPATH"]]
  854. methods.generate_vs_project(env, ARGUMENTS, env["vsproj_name"])
  855. methods.generate_cpp_hint_file("cpp.hint")
  856. # Check for the existence of headers
  857. conf = Configure(env)
  858. if "check_c_headers" in env:
  859. headers = env["check_c_headers"]
  860. for header in headers:
  861. if conf.CheckCHeader(header):
  862. env.AppendUnique(CPPDEFINES=[headers[header]])
  863. elif selected_platform != "":
  864. if selected_platform == "list":
  865. print("The following platforms are available:\n")
  866. else:
  867. print('Invalid target platform "' + selected_platform + '".')
  868. print("The following platforms were detected:\n")
  869. for x in platform_list:
  870. print("\t" + x)
  871. print("\nPlease run SCons again and select a valid platform: platform=<string>")
  872. if selected_platform == "list":
  873. # Exit early to suppress the rest of the built-in SCons messages
  874. Exit()
  875. else:
  876. Exit(255)
  877. # The following only makes sense when the 'env' is defined, and assumes it is.
  878. if "env" in locals():
  879. # FIXME: This method mixes both cosmetic progress stuff and cache handling...
  880. methods.show_progress(env)
  881. # TODO: replace this with `env.Dump(format="json")`
  882. # once we start requiring SCons 4.0 as min version.
  883. methods.dump(env)
  884. def print_elapsed_time():
  885. elapsed_time_sec = round(time.time() - time_at_start, 3)
  886. time_ms = round((elapsed_time_sec % 1) * 1000)
  887. print("[Time elapsed: {}.{:03}]".format(time.strftime("%H:%M:%S", time.gmtime(elapsed_time_sec)), time_ms))
  888. atexit.register(print_elapsed_time)