38.9. ccache

ccache might save you a lot of re-build when you decide to Clean the build or create a new build variant.

We have ccache enabled for everything we build by default.

However, you likely want to add the following to your .bashrc to take better advantage of ccache:

export CCACHE_DIR=~/.ccache
export CCACHE_MAXSIZE="20G"

We cannot automate this because you have to decide:

  • should I store my cache on my HD or SSD?

  • how big is my build, and how many build configurations do I need to keep around at a time?

If you don’t those variables it, the default is to use ~/.buildroot-ccache with 5G, which is a bit small for us.

To check if ccache is working, run this command while a build is running on another shell:

watch -n1 'make -C "$(./getvar buildroot_build_dir)" ccache-stats'

or if you have it installed on host and the environment variables exported simply with:

watch -n1 'ccache -s'

and then watch the miss or hit counts go up.

We have enabled ccached builds by default.

BR2_CCACHE_USE_BASEDIR=n is used for Buildroot, which means that:

  • absolute paths are used and GDB can find source files

  • but builds are not reused across separated LKMC directories

ccache can be disabled with the --no-ccache option as in:

./build-gem5 --no-ccache

This can be useful to benchmark builds.