Difference between revisions of "Ccache"

From ArchWiki
Jump to: navigation, search
(Change the cache directory)
(Enable for command line: Note: setting the according PATH will inevitably enable ccache for makepkg)
 
(27 intermediate revisions by 13 users not shown)
Line 1: Line 1:
 
[[Category:Package development]]
 
[[Category:Package development]]
 +
[[ja:Ccache]]
 
[[zh-CN:Ccache]]
 
[[zh-CN:Ccache]]
There's a wonderful tool for {{Ic|gcc}} called {{Ic|ccache}}. You can read about it at their [http://ccache.samba.org home page].
+
{{Related articles start}}
 +
{{Related|Makepkg}}
 +
{{Related|Distcc}}
 +
{{Related articles end}}
  
If you're always compiling the same programs over and over again — such as trying out several kernel patches, or testing your own development — then {{Ic|ccache}} is perfect. While it may take a few seconds longer to compile a program the first time with {{Ic|ccache}}, subsequent compiles will be much, much faster.
+
[http://ccache.samba.org/ ccache] is a tool for the gcc compiler used to compile the same program over and over again with little downtime. While it may take a few seconds longer to compile a program the first time with {{Ic|ccache}}, subsequent compiles will be much, much faster.
  
 
== Installation ==
 
== Installation ==
  
[[pacman|Install]] {{pkg|ccache}}, available from the [[official repositories]]
+
[[Install]] the {{pkg|ccache}} package.
 +
 
 +
==Configuration==
  
 
=== Enable ccache for makepkg ===
 
=== Enable ccache for makepkg ===
To enable ccache when using makepkg edit {{ic|/etc/makepkg.conf}}. In {{Ic|BUILDENV}} remove exclamation mark before ccache and it will enabled. For example:
 
  BUILDENV=(fakeroot !distcc color ccache !xdelta)
 
  
{{Note|If you are compiling for KDE example you have to disable export CPP and export CXX — it prevents from some errors.''}}
+
To enable ccache when using [[makepkg]] edit {{ic|/etc/makepkg.conf}}. In {{Ic|BUILDENV}} uncomment {{ic|ccache}} (remove the exclamation mark) to enable caching. For example:
 +
{{hc|1=/etc/makepkg.conf|
 +
2=BUILDENV=(fakeroot !distcc color '''ccache''' check !sign)}}
  
 
=== Enable for command line ===
 
=== Enable for command line ===
If you're compiling your code from the command line, and not building packages, then you'll still want to use {{Ic|ccache}} to help speed things up.
+
If you are compiling your code from the command line, and not building packages, then you will still want to use {{Ic|ccache}} to help speed things up.
  
For that, you need to change your {{Ic|$PATH}} to include {{Ic|ccache}}'s binaries before the path to your compiler.
+
For that, you need to change your {{Ic|$PATH}} to include {{Ic|ccache}}'s binaries before the path to your compiler:
  
  export PATH="/usr/lib/ccache/bin/:$PATH"
+
  $ export PATH="/usr/lib/ccache/bin/:$PATH"
  
 
You may want to add this line to your {{ic|~/.bashrc}} file for regular usage.
 
You may want to add this line to your {{ic|~/.bashrc}} file for regular usage.
 +
 +
{{Note|This will inevitably enable ccache for makepkg as well if invoked with this PATH.}}
  
 
=== Enable with colorgcc ===
 
=== Enable with colorgcc ===
Line 34: Line 42:
 
gcc: /usr/lib/ccache/bin/gcc
 
gcc: /usr/lib/ccache/bin/gcc
 
c++: /usr/lib/ccache/bin/g++
 
c++: /usr/lib/ccache/bin/g++
cc: /usr/lib/ccache/bin/gcc
+
cc: /usr/lib/ccache/bin/cc
 
g77:/usr/bin/g77
 
g77:/usr/bin/g77
 
f77:/usr/bin/g77
 
f77:/usr/bin/g77
Line 41: Line 49:
 
== Misc ==
 
== Misc ==
 
=== Change the cache directory ===
 
=== Change the cache directory ===
You may want to move the cache directory to a faster location than the default "~/.ccache" directory, like an SSD or a ramdisk.
+
You may want to move the cache directory to a faster location than the default {{ic|~/.ccache}} directory, like an SSD or a [[ramdisk]].
  
To do change the cache location:
+
To change the cache location:
  export CCACHE_DIR=/ramdisk/ccache             # Tell ccache to use this path to store its cache
+
  $ export CCACHE_DIR=/ramdisk/ccache
  
=== CLI ===
+
=== Disable the cache via environment ===
You can use the command line utility ccache to...
+
  
Show statistics summary:
+
If you wish to disable CCache only in the current shell you can set:
 +
$ export CCACHE_DISABLE=1
 +
 
 +
=== CLI ===
 +
You can use the command-line utility {{ic|ccache}} to show a statistics summary:
 
  $ ccache -s
 
  $ ccache -s
  
Clear the cache completely:
+
or clear the cache completely:
 
  $ ccache -C
 
  $ ccache -C
 +
 +
=== makechrootpkg ===
 +
It is also possible to use ccache with makechrootpkg. To retain the cache when the chroot is cleaned the makechrootpkg option {{ic|-d}} can be used to bind the cache directory from the regular system into the chroot, eg.:
 +
$ mkdir /path/of/chroot/ccache
 +
$ makechrootpkg -d /path/to/cache/:/ccache -r /path/of/chroot -- CCACHE_DIR=/ccache
 +
Then ccache can be configured for the chroot in the same way as explained above for the regular system.
  
 
== See also ==
 
== See also ==
  
*[http://ccache.samba.org/ ccache homepage]
 
 
*[http://ccache.samba.org/manual.html ccache manual]
 
*[http://ccache.samba.org/manual.html ccache manual]

Latest revision as of 19:22, 15 September 2016

Related articles

ccache is a tool for the gcc compiler used to compile the same program over and over again with little downtime. While it may take a few seconds longer to compile a program the first time with ccache, subsequent compiles will be much, much faster.

Installation

Install the ccache package.

Configuration

Enable ccache for makepkg

To enable ccache when using makepkg edit /etc/makepkg.conf. In BUILDENV uncomment ccache (remove the exclamation mark) to enable caching. For example:

/etc/makepkg.conf
BUILDENV=(fakeroot !distcc color ccache check !sign)

Enable for command line

If you are compiling your code from the command line, and not building packages, then you will still want to use ccache to help speed things up.

For that, you need to change your $PATH to include ccache's binaries before the path to your compiler:

$ export PATH="/usr/lib/ccache/bin/:$PATH"

You may want to add this line to your ~/.bashrc file for regular usage.

Note: This will inevitably enable ccache for makepkg as well if invoked with this PATH.

Enable with colorgcc

Since colorgcc is also a compiler wrapper, some care needs to be taken to ensure each wrapper is called in the correct sequence.

export PATH="/usr/lib/colorgcc/bin/:$PATH"    # As per usual colorgcc installation, leave unchanged (don't add ccache)
export CCACHE_PATH="/usr/bin"                 # Tell ccache to only use compilers here

Then colorgcc needs to be told to call ccache instead of the real compiler. Edit /etc/colorgcc/colorgccrc and change the /usr/bin paths to /usr/lib/ccache/bin for all the compilers in /usr/lib/ccache/bin:

/etc/colorgcc/colorgccrc
g++: /usr/lib/ccache/bin/g++
gcc: /usr/lib/ccache/bin/gcc
c++: /usr/lib/ccache/bin/g++
cc: /usr/lib/ccache/bin/cc
g77:/usr/bin/g77
f77:/usr/bin/g77
gcj:/usr/bin/gcj

Misc

Change the cache directory

You may want to move the cache directory to a faster location than the default ~/.ccache directory, like an SSD or a ramdisk.

To change the cache location:

$ export CCACHE_DIR=/ramdisk/ccache

Disable the cache via environment

If you wish to disable CCache only in the current shell you can set:

$ export CCACHE_DISABLE=1

CLI

You can use the command-line utility ccache to show a statistics summary:

$ ccache -s

or clear the cache completely:

$ ccache -C

makechrootpkg

It is also possible to use ccache with makechrootpkg. To retain the cache when the chroot is cleaned the makechrootpkg option -d can be used to bind the cache directory from the regular system into the chroot, eg.:

$ mkdir /path/of/chroot/ccache
$ makechrootpkg -d /path/to/cache/:/ccache -r /path/of/chroot -- CCACHE_DIR=/ccache

Then ccache can be configured for the chroot in the same way as explained above for the regular system.

See also