Unity Builds
   HOME

TheInfoList



OR:

In
software engineering Software engineering is a branch of both computer science and engineering focused on designing, developing, testing, and maintaining Application software, software applications. It involves applying engineering design process, engineering principl ...
, a unity build (also known as unified build, jumbo build or blob build) is a method used in C and C++
software development Software development is the process of designing and Implementation, implementing a software solution to Computer user satisfaction, satisfy a User (computing), user. The process is more encompassing than Computer programming, programming, wri ...
to speed up the compilation of projects by combining multiple translation units into a single one, usually achieved by using
include directive An include directive instructs a text file processor to replace the directive text with the content of a specified file. The act of including may be logical in nature. The processor may simply process the include file content at the location of ...
s to bundle multiple source files into one larger file.


Implementation

If two different translation units file_a.cc #include "header.h" // content of source file A ... and file_b.cc #include "header.h" // content of source file B ... in the same project both include the header header.h, that header will be processed twice by the compiler chain, once for each build task. If the two translation units are merged into a single source file jumbo_file.cc #include "file_a.cc" #include "file_b.cc" then header.h will be processed only once (thanks to
include guard In the C and C++ programming languages, an #include guard, sometimes called a macro guard, header guard or file guard, is a way to avoid the problem of ''double inclusion'' when dealing with the include directive. The C preprocessor processe ...
s) when compiling jumbo_file.cc.


Effects

The main benefit of unity builds is a reduction of duplicated effort in parsing and compiling the content of headers that are included in more than one source file. The content of headers usually accounts for the majority of code in a source file after preprocessing. Unity builds also mitigate the overhead caused by having a large number of small source files by reducing the number of object files created and processed by the compilation chain, and allows interprocedural analysis and optimisation across the files that form the unity build task (similar to the effects of link-time optimisation). They make it also easier to detect violations of the
One Definition Rule The One Definition Rule (ODR) is an important rule of the C++ programming language that prescribes that classes/structs and non-inline functions cannot have more than one definition in the entire program and templates and types cannot have more th ...
, because if a symbol is defined twice in different source files in the same unity build, the compiler will be able to identify the redefinition and emit a warning or error. One of the drawbacks of unity builds is a larger
memory footprint Memory footprint refers to the amount of main memory that a program uses or references while running. The word footprint generally refers to the extent of physical dimensions that an object occupies, giving a sense of its size. In computing, t ...
due to larger translation units. Larger translation units can also negatively affect parallel builds, since a small number of large compile jobs is generally harder or impossible to schedule to saturate all available
parallel computing Parallel computing is a type of computing, computation in which many calculations or Process (computing), processes are carried out simultaneously. Large problems can often be divided into smaller ones, which can then be solved at the same time. ...
resources effectively. Unity builds can also deny part of the benefits of incremental builds, that rely on rebuilding as little code as possible, i.e. only the translation units affected by changes since the last build. These disadvantages can be offset by a great increase in the speed of the application linker stage, which no longer has to load and eliminate duplicate template codegen blocks in each translation unit. The linker stage memory use will also decrease. Unity builds have also potentially dangerous effects on the
semantics Semantics is the study of linguistic Meaning (philosophy), meaning. It examines what meaning is, how words get their meaning, and how the meaning of a complex expression depends on its parts. Part of this process involves the distinction betwee ...
of programs. Some valid C++ constructs that rely on internal linkage may fail under a unity build, for instance clashes of static symbols and symbols defined in anonymous namespaces with the same identifier in different files. If different C++ files define different functions with the same name, the compiler may unexpectedly resolve the overloading by selecting the wrong function, in a way that was not possible when designing the software with the files as different translation units. Another adverse effect is the possible leakage of macro definitions across different source files.


Build system support

Some build systems provide built-in support for automated unity builds, including
Visual Studio Visual Studio is an integrated development environment (IDE) developed by Microsoft. It is used to develop computer programs including web site, websites, web apps, web services and mobile apps. Visual Studio uses Microsoft software development ...
,
Meson In particle physics, a meson () is a type of hadronic subatomic particle composed of an equal number of quarks and antiquarks, usually one of each, bound together by the strong interaction. Because mesons are composed of quark subparticles, the ...
,
CMake CMake is a free, cross-platform, software development tool for building applications via compiler-independent instructions. It also can automate testing, packaging and installation. It runs on a variety of platforms and supports many program ...
. and xmake.


References

* {{cite conference , last1=Kubota , first1=Takafumi , last2=Yusuke , first2=Suzuki , last3=and , first3=Kenji Kono , title=To unify or not to unify: a case study on unified builds (in WebKit). , conference=Proceedings of the 28th International Conference on Compiler Construction , doi=10.1145/3302516.3307347 , doi-access=free , year=2019 Build automation C++ compilers C++ programming language family C++ software