Using ccache to speed up builds
Note: With the switch to Bazel, ccache is much less valuable. You should not need to have it installed and installing it is likely to impact your build in other ways. Finally, we have fewer C/C++ dependencies than we used to (e.g. no more RocksDB), and there are pre-built versions of the C dependencies so you do not need to compile them yourself. The information on this page is presented as written for reference.
Tired of recompiling our C++ libprotobuf and RocksDB every time you switch branches across commits to the vendor
submodule? ccache is for you!
ccache is a "compiler cache". It's a wrapper on top of all the C compilers that caches compiler output and speeds up subsequent invocations for compiling inputs it's seen before (by file hash). By God, it works! After you've compiled a RocksDB version once, future compilations of that version will be much faster.
On OSX, brew install ccache
and the prepend the path it tells you to your $PATH
. This is not the output of which ccache
. The pre-pending is important because the ccache wrappers need to be found in the PATH before the real compilers.
After installation, do a make clean; make build
to populate the cache. Then, to check its magic, do make clean; make build
again - this time it should be a lot quicker.
Some ccache FYIs:
By default, ccache will use up to 5GB of disk space to store compilation artifacts. You can see the current usage with
ccache -s
or force an immediate cleanup withccache -c
. There' alsos a config file you can use to adjust the cache size to your liking.There are a few environment variables (
MACOSX_DEPLOYMENT_TARGET
comes to mind) that affect compilation but are not include in ccache's cache key. On the whole, though, it's quite good at keeping track of everything (env vars, compiler flags, compiler versions, os versions) that might affect the compiled output.If you do see a weird build failure that seems like it should be fixed by setting some env var or upgrading Xcode, it's probably
ccache
caching the broken build. You can bite the bullet and drop the entire cache withccache -C
.
Copyright (C) Cockroach Labs.
Attention: This documentation is provided on an "as is" basis, without warranties or conditions of any kind, either express or implied, including, without limitation, any warranties or conditions of title, non-infringement, merchantability, or fitness for a particular purpose.