August 03, 2019

Bazel sandboxing and ccache

I was trying to build a random project cloned from github that uses bazel for the build system. While trying to build the source code, bazel aborted the build with the following error :


Turns out this is a known issue, Bazel runs builds in a sandbox (which is effectively a user namespace) and this sandbox does not have write access to the cache dir used by ccache. Unfortunately for me, Fedora defaults to use ccache.

The suggested fix is to whitelist the ccache cache directory, however the caveat is that the corresponding configuration option is not a valid startup option, it is only valid for the build action. So adding the following to ~/.bazelrc (creating one if it does not exist) should fix this error :


For the curious, you can see the cache directory that ccache uses by running "ccache --print-config" (~/.ccache is usually the default).