Skip to content

Unity build

Robert Doczi edited this page Oct 29, 2015 · 1 revision

Unity build for C++

The main idea behind unity build is to create several unity files that include multiple .cc files. The build then consists of compiling these unity files (instead of the original .cc files) and linking them together.

Advantages/Disadvantages

Pros Cons
Faster compilation limited incrementality
Faster linking
Better code optimalization
Smaller output size

Realization

Unity build requires the following components to be generated:

  • for each uml component a unity build file containing includes to every class inside the component
  • a unity build file for the external components including every .cc for external classes
  • a unity build file for the runtime including every .cc file inside the runtime
  • a unity build file including main.cc

To avoid interference with regular build, the unity build files either have to have different extensions (so rules.mk files don't try to include them in normal build), this requires a separate makefile, or collecting the unity build files in a separate directory, this way the original makefile can be extended with the additional make rule unity which allows specifying build type via a parameter to the make call.

Further reading

  1. Reducing Compilation Time: Unity Builds
  2. The magic of unity builds (missing images)
Clone this wiki locally