Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoiding unneccessry recompilations using "branchy" development model

Tags:

c++

mercurial

I'm using Mercurial for development of quite a large C++ project which takes about 30 minutes to get built from the scratch(while incremental builds are very quick).

I'm usually trying to implement each new feature in the new branch(using "hg clone") and I may have several new features developed during the day and it's quickly getting very boring to wait for the new feature branch to get built.

Are there any recipes to somehow re-use object files from other already built branches?

P.S. in git there are named branches within the same repository which make re-usage of the existing object files possible for the build system, however I prefer the simpler Mercurial separate branches model...

like image 392
pachanga Avatar asked Dec 17 '22 08:12

pachanga


1 Answers

I suggest using ccache as a way to speed up compilation of (mostly) the same code tree. The way it works is as following:

  • You define a place to be used as the cache (and the maximum cache size) by using the CCACHE_DIR environment variable
  • Your compiler should be set to ccache ${CC} or ccache ${CXX}

ccache takes the output of ${CC} -E and the compilation flags and uses that as a base for its hash. As long as the compiler flags, source file and the headers are all unchanged, the object file will be taken from cache, saving valuable compilation time.

Note that this method speeds up compilation of any source file that eventually produces the same hash. If you share source files across projects, ccache will handle them as well.

If you already use distcc and wish to use it with ccache, set the CCACHE_PREFIX environment variable to distcc.

Using ccache sped up our source tree compilation around tenfold.

like image 129
ASk Avatar answered Feb 16 '23 00:02

ASk