Introduction to the buildsystem
SCons
SCons to build. We love it, we are not changing it for anything else. We are not even sure other build systems are up to the task of building Godot. We constantly get requests to move the build system to CMake, or Visual Studio, but this is not going to happen. There are many reasons why we have chosen SCons over other alternatives, for example:
- Godot can be compiled for a dozen different platforms: all PC platforms, all mobile platforms, many consoles, and WebAssembly.
- at the same time, or even different targets of the same platform. They can’t afford reconfiguring and rebuilding the project each time. SCons can do this with no sweat, without breaking the builds.
- never break a build no matter how many changes, configurations, additions, removals etc. You have more chances to die struck by lightning than needing to clean and rebuild in SCons.
- Godot build process is not simple. Several files are generated by code (binders), others are parsed (shaders), and others need to offer customization (plugins). This requires complex logic which is easier to write in an actual programming language (like Python) rather than using a mostly macro-based language only meant for building.
- Godot build process makes heavy use of cross-compiling tools. Each platform has a specific detection process, and all these must be handled as specific cases with special code written for each.
So, please try to keep an open mind and get at least a little familiar with it if you are planning to build Godot yourself.
Setup
Compiling for Android, Compiling for iOS, Compiling for macOS, Compiling for Universal Windows Platform, Compiling for the Web, Compiling for Windows and Compiling for X11 (Linux, BSD). *Windows/Visual Studio, you need to usex86_x64 Cross Tools Command Prompt for VS 2017or similar, depending on your install, instead of the standard Windows command prompt to enter the commands below.Platform selection
Godot’s build system will begin by detecting the platforms it can build for. If not detected, the platform will simply not appear on the list of available platforms. The build requirements for each platform are described in the rest of this tutorial section.scons. If no platform is specified, SCons will detect the target platform automatically based on the host platform. It will then start building for the target platform right away.scons platform=list:scons platform=listscons: Reading SConscript files ...The following platforms are available: android javascript server windows x11Please run SCons again and select a valid platform: platform=<string>
platform=(orp=to make it short) argument:scons platform=x11
-j <cores>parameter to specify how many cores will be used for the build. Or leave it using one core, so you can use your computer for something else :) Example for using 4 cores:scons platform=x11 -j 4
Resulting binary
bin/subdirectory, generally with this naming convention:
For the previous build attempt, the result would look like this:godot.<platform>.[opt].[tools/debug].<architecture>[extension]
This means that the binary is for X11, is not optimized, has tools (the whole editor) compiled in, and is meant for 64 bits. A Windows binary with the same configuration will look like this:ls binbin/godot.x11.tools.64
godotengine.org, or you can build them yourself). Aside from that, there are a few standard options that can be set in all build targets, and which will be explained below.C:\godot> dir bin/godot.windows.tools.64.exe
Tools
Tools are enabled by default in all PC targets (Linux, Windows, macOS), disabled for everything else. Disabling tools produces a binary that can run projects but that does not include the editor or the project manager.scons platform=<platform> tools=yes/no
Target
Target controls optimization and debug flags. Each mode means: - debug: Build with C++ debugging symbols, runtime checks (performs checks and reports error) and none to little optimization.
- release_debug: Build without C++ debugging symbols and optimization, but keep the runtime checks (performs checks and reports errors). Official editor binaries use this configuration.
- release: Build without symbols, with optimization and with little to no runtime checks. This target can’t be used together with
tools=yes, as the editor requires some debug functionality and run-time checks to run.scons platform=<platform> target=debug/release_debug/release
.debugsuffix (for debug), or.tools(for debug with tools enabled). When optimization is enabled (release), it appends the.optsuffix.Bits
Bits is meant to control the CPU or OS version intended to run the binaries. It is focused mostly on desktop platforms and ignored everywhere else. - 32: Build binaries for 32-bit platforms.
- 64: Build binaries for 64-bit platforms.
- default: Build for the architecture that matches the host platform.
scons platform=<platform> bits=default/32/64
.32or.64suffixes to resulting binaries when relevant. Ifbits=defaultis used, the suffix will match the detected architecture.Custom modules
It’s possible to compile modules residing outside of Godot’s directory tree, along with the built-in modules.custom_modulesbuild option can be passed to the command line before compiling. The option represents a comma-separated list of directory paths containing a collection of independent C++ modules that can be seen as C++ packages, just like the built-inmodules/directory. For instance, it’s possible to provide both relative, absolute, and user directory paths containing such modules:
Note If there’s any custom module with the exact directory name as a built-in module, the engine will only compile the custom one. This logic can be used to override built-in module implementations. See also Custom modules in C++scons custom_modules="../modules,/abs/path/to/modules,~/src/godot_modules"
Cleaning generated files
scons --clean <options>, where<options>is the list of build options you’ve used to build Godot previously.git clean -fixdwhich will clean build artifacts for all platforms and configurations. Beware, as this will remove all untracked and ignored files in the repository. Don’t run this command if you have uncommitted work!Other build options
There are several other build options that you can use to configure the way Godot should be built (compiler, debug options, etc.) as well as the features to include/disable.scons --helpfor details about each option for the version you are willing to compile.Overriding the build options
Using a file
custom.pyfile can be created at the root of the Godot Engine source to initialize any SCons build options passed via the command line:
Optimizing a build for size page for more details. See also Godot build options generator to generate a# custom.pyoptimize = "size"module_mono_enabled = "yes"use_llvm = "yes"extra_suffix = "game_title"
custom.pyfile containing SCons options. You can then save this file and place it at the root of your Godot source directory.profilecommand line option, both overriding the default build configuration:
Note Build options set from the file can be overridden by the command line options. It’s also possible to override the options conditionally:scons profile=path/to/custom.py
# custom.pyimport version# Override options specific for Godot 3.x and 4.x versions.if version.major == 3: passelif version.major == 4: pass
Using the SCONSFLAGS
SCONSFLAGSis an environment variable which is used by the SCons to set the options automatically without having to supply them via the command line.-joption for all the future builds: Linux/macOSWindows (cmd)Windows (powershell)export SCONSFLAGS="-j4"
set SCONSFLAGS=-j4
$env:SCONSFLAGS="-j4"
Export templates
godotengine.org. However, you might want to build them yourself (in case you want newer ones, you are using custom modules, or simply don’t trust your own shadow). If you download the official export templates package and unzip it, you will notice that most files are optimized binaries or packages for each platform:
To create those yourself, follow the instructions detailed for each platform in this same tutorial section. Each platform explains how to create its own template.android_debug.apkandroid_release.apkwebassembly_debug.zipwebassembly_release.ziplinux_server_32linux_server_64linux_x11_32_debuglinux_x11_32_releaselinux_x11_64_debuglinux_x11_64_releaseosx.zipversion.txtwindows_32_debug.exewindows_32_release.exewindows_64_debug.exewindows_64_release.exe
version.txtfile should contain the corresponding Godot version identifier. This file is used to install export templates in a version-specific directory to avoid conflicts. For instance, if you are building export templates for Godot 3.1.1,version.txtshould contain3.1.1.stableon the first line (and nothing else). This version identifier is based on themajor,minor,patch(if present) andstatuslines of the version.py file in the Godot Git repository. If you are developing for multiple platforms, macOS is definitely the most convenient host platform for cross-compilation, since you can cross-compile for almost every target (except for UWP). Linux and Windows come in second place, but Linux has the advantage of being the easier platform to set this up.
