Ccache: Difference between revisions

From miki
Jump to navigation Jump to search
Line 29: Line 29:
<source lang="bash">
<source lang="bash">
ccache -M 2G
ccache -M 2G
</source>

== Troubleshoot ==
=== Get ccache logging ===
Enabling ccache logging may help troubleshooting issues. Just add to {{file|~/.ccache/ccache.conf}}:
log_file = ccache.log

From now on, ccache will produce a detailed log in the current directory.

=== ccache ignore .include directive in assembly file ===
ccache ignores <code>.include</code> directives in assembly file ({{file|*.s}} or {{file|*.S}}).
As a result, if the included file changes, ccache does not detect it and still provides the old object.

Workaround:
* Use <code>.incbin</code> directive instead [https://github.com/ccache/ccache/issues/136]. The problem is that clang ignores <code>.incbin</code> directive. The fix is to use a conditional compilation like:
<source lang="asm">
# Pretend we use .incbin directive to prevent ccache to cache this file (clang ignores ;incbin, and ccache ignores .include)
.if 1
.include "file.s"
.else
.incbin "file.s"
.endif
</source>
* Better yet, use {{file|*.S}} file that enables preprocessor, and use a standard <code>#include directive</code>, which will be correctly catched by ccache:
<source lang="asm">
#include "file.S"
</source>
</source>

Revision as of 09:48, 27 January 2020

According to the manpage, ccache is a fast C/C++ compiler cache. It works with the gcc and clang compilers (or alike).

Reference

Install

On Debian / Ubuntu, ccache is available as a standard package:

sudo apt install ccache

To use ccache for compiling, just create a few symlinks. For instance, to use ccache with gcc and clang-3.6:

sudo ln -sf /usr/bin/ccache /usr/local/bin/gcc
sudo ln -sf /usr/bin/ccache /usr/local/bin/clang-3.6

This will work as long as the directory with symlinks comes before the path to the compiler (which is usually in /usr/bin).

Usage

  • Collect ccache usage statistics:
ccache -s
  • Set cache size:
ccache -M 2G

Troubleshoot

Get ccache logging

Enabling ccache logging may help troubleshooting issues. Just add to ~/.ccache/ccache.conf:

log_file = ccache.log

From now on, ccache will produce a detailed log in the current directory.

ccache ignore .include directive in assembly file

ccache ignores .include directives in assembly file (*.s or *.S). As a result, if the included file changes, ccache does not detect it and still provides the old object.

Workaround:

  • Use .incbin directive instead [1]. The problem is that clang ignores .incbin directive. The fix is to use a conditional compilation like:
# Pretend we use .incbin directive to prevent ccache to cache this file (clang ignores ;incbin, and ccache ignores .include)
.if 1
.include "file.s"
.else
.incbin "file.s"
.endif
  • Better yet, use *.S file that enables preprocessor, and use a standard #include directive, which will be correctly catched by ccache:
#include "file.S"