Ccache: Difference between revisions

From miki
Jump to navigation Jump to search
(Created page with "According to the manpage, ccache is a fast C/C++ compiler cache. It works with the gcc and clang compilers (or alike). == Reference == * [https://ccache.samba.org/manual....")
 
 
(2 intermediate revisions by the same user not shown)
Line 2: Line 2:


== Reference ==
== Reference ==
* https://ccache.dev/
* [https://github.com/ccache/ccache ccache on GitHub]
* [https://ccache.samba.org/manual.html ccache manual].
* [https://ccache.samba.org/manual.html ccache manual].
* https://software.intel.com/en-us/articles/accelerating-compilation-part-1-ccache
* https://software.intel.com/en-us/articles/accelerating-compilation-part-1-ccache

;Related
* [https://www.distcc.org/ distcc], to spread compilation over several computers.
* [https://github.com/mozilla/sccache sccache, a compiler-cache for Rust].


== Install ==
== Install ==
Line 28: Line 34:
<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>

Latest revision as of 17:28, 24 November 2022

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

Reference

Related

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"