2

I was thinking about using ccache with gcc compiled code on the team wide base (same ccache's cache will be used by all developers on the same machine).

Since we're talking about commercial product, "correctness" of compilation is a top priority.

Here come questions:

  1. Is the compilation using ccache is safe/reproducible? Is there some exception situations that ccache supposes cache hit mistakenly.

    If I checkout a source code and compile it, I expect to receive the same products (exactly same libraries/binaries) each time I repeat a fresh compilation process. This is must to for commercial product.

  2. Is there're open source/commercial products using ccache an integral part of their build system? This will make it easier to convince my colleagues to use ccache.

Thanks

dimba
  • 26,717
  • 34
  • 141
  • 196
  • The only precaution regarding use of ccache in production I am aware of is that sometimes corrupted object could end up in ccache cache which leads to build failure. It happened in the project I worked in (2-3 times a year) and we had to implement back-off build with ccache disabled. And we had multiple releases per day so it made sense to use ccache even though – maoizm Nov 04 '21 at 09:05
  • from my experience it is more complex to get ccache to believe that even the identical file has already been compiled before (eg. when it exists in ccache but you build the same code in different build directories or when created time differs but content/checksum is the same). I am not aware of false positive cases when modified source files + dependencies had been treated by ccache as already compiled – maoizm Nov 04 '21 at 09:11

2 Answers2

6

According to its manual, ccache determines whether it has compiled some object before on the following:

  • the pre-processor output from running the compiler with -E
  • the command line options
  • the real compilers size and modification time
  • any stderr output generated by the compiler

If some PHB is still worried about any assumed risk you take because of ccache, only use it for development builds and build the final product using the compiler without any front-end. Or you could clear the cache before building the final product.

Update: I don't know about products using ccache as an integral part of their build system, but it is really trivial to integrate into any environment where you can set the compiler's path. I.e. for autoconf:

CC="ccache gcc" ./configure

And after looking at the author's name, I'd say it's a pretty safe assumption that it has been widely used within the Samba team.

Update in response to Ringding's comment about usage of stderr: From ccache's point of view, one interesting bit of information is the C compiler's version and configuration string. gcc outputs that to the standard error file:

$ gcc -v 2>err
$ cat err
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.3.4-2' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-targets=all --with-tune=generic --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.3.4 (Debian 4.3.4-2)

I'd bet that ccache uses this or a similar output. But, hey, you can always look at its source code. :-)

hillu
  • 9,423
  • 4
  • 26
  • 30
  • It cannot make a decision based on the compiler's stderr output because it would have to call the compiler first. But the other 3 are correct, IIRC. – Ringding Sep 15 '09 at 07:41
  • Guys, do you know answer to 2nd item of my question? @hillu +1 for "safety" advises. A nice part of your answer is that also developer can perform a "safe" build if cleaning cache beforehand – dimba Sep 15 '09 at 08:54
0

I am personally familiar only with ccache which is very simple to use, and I find it extremely useful for my large scale private projects. However, as for a team wide base, I have no experience yet. You may be interested also in AO (audited objects):

In general:

  • it provides a more robust mechanism, can use distributed environment for caching
  • ccache speed up only compilation time, while AO speed up link time too.
  • not limited only to c/c++

Not long after my posted answer (1.5 years ago...), I managed to convince our build and R&D managers, to integrate ccache into the automatic build system, and they are grateful to me on that. The company employs more than 200 developers, so it is really working. As for the linking phase, it is still an issue.

Daniel Heilper
  • 1,182
  • 2
  • 17
  • 34