How do I use ccache in my builds?

I'd like to be able to run make cleans between builds, and ccache would make this much simpler since I wouldn't need to recompile everything every time

I haven't found any information about it being used at all, the wiki mentions that some systems might need it as a requirement for compilation, but I've been checking the output of ccache -s and no new files are put into the cache directory during builds.

Thank you for your time

since make clean explicitly deletes the compiled binaries, ccache isn't going to
avoid recompiling things if you do a make clean.

I haven't setup ccache, but to do it, you would have to set it up inside the
toolchain. sorry I cna't help beyond that.

David Lang

That's the solution I'm looking for, I'd like the toolchain's compilers to use ccache.

I've already got ccache set up if I were to compile programs native to my current cpu, but it looks like the toolchain isn't using ccache at all.

If anyone could help me out we could contribute this information to the wiki since it speeds up repeat builds a TON

You can utilize git to check in the build tree to your own local branch and use "git commit" to create snapshots for the different build phases. Then use "git checkout <commit-id>" to revert a particular stage.

Another possible way is to create a snapshot volume for the build tree and then take a snapshot whenever you are happy with a particular part in the build process which you then can revert back to.

The above requires that you make a temporary change in a build script in order to pause at a suitable point where you want to make a snapshot or commit changes to your local git branch.

The toolchain has it's own version of gcc, it's own libraries, etc. You need to
go into that copy of gcc and do all the things that you did in your main
version, including setting up ccache slaves with the correct environment
(obviously using different ports so you don't mix the LEDE crossbuild ccache
environment with your main ccache environment.

1 Like

make menuconfig->Advanced configuration options->Use ccache

3 Likes

Anomeome, thats awesome! You never know for sure what hidden gems there are to be explored but sometimes they just pop up from nowhere! :smile:

@anomeome That's awesome, we've got progress now.

There's a compile error now. It also looks like you can manually set the CONFIG_CCACHE flag without having to set it in menuconfig.

CONFIG_CCACHE=y make -j1 V=sa
ccache: error: Could not find compiler "mips-openwrt-linux-musl-gcc" in PATH

Now i've tried to manually set the PATH when running make

PATH="/home/mesrc/lede-project/staging_dir/toolchain-mips_24kc_gcc-5.4.0_musl/bin:$PATH" CONFIG_CCACHE=y make -j1 V=sa

But it's still the same problem. From the error output I can see that the ccache binary isn't finding the compiler binaries in the PATH and manually setting the compiler path in via the PATH variable doesn't get picked up by the build system

Have any of you guys gotten a successful build while using ccache?

Trust me this will be beneficial for everyone, a fully cached build is WAY faster even when doing make cleans in between. I use ccache when compiling the linux kernel and android builds and the difference is light and day

Don't think there was anything special about setting the environment up to use ccache; i.e. I don't remember rebuilding the toolchain specifically to use the cache(but it has been a while since I set things up). If your environment can build successfully without, than with should not be any different except of course installing/configuring ccache for your OS, and turning on that attribute.

ccache need to be the first entry in PATH. It works for me when using:

$ export PATH="/usr/lib/ccache:$PATH"
$ export CONFIG_CCACHE=y

You should be able to verify it by checking the cache hits before and after make:

$ ccache -s
$ make ...
$ ccache -s

Hi! Note that it uses its own copy of ccache, with the cached files in-tree, so you need to
CCACHE_DIR=staging_dir/host/ccache ccache -s
or, to be picky,
CCACHE_DIR=staging_dir/host/ccache staging_dir/host/bin/ccache -s
to see the stats. Plain "ccache -s" will show the stats for ~/.ccache, which is not updated.
For when it's biulding the toolchain instead,
CCACHE_DIR=$(echo staging_dir/toolchain-*)/ccache ccache -s
and for compilations for the target,
CCACHE_DIR=$(echo staging_dir/target-*)/ccache ccache -s

2 Likes

The only ccache dir I could find is .ccache in root of the buildtree.
Toolchain build doesn't seem cached there.
Any thoughts?

make menuconfig->Advanced configuration options->Use ccache
make tools/ccache/compile

After compiling the ccache tool, it started working for me.

1 Like