How to get Bazel, ccache, and sandboxing to work together (ccache read only filesystem)

6.3k views Asked by At

I'm attempting to build a C++ application on Fedora 28 using Bazel 0.16.1 installed via copr and ccache 3.4.2 installed via DNF. I'm using the default cc_binary and cc_library rules. When I run the bazel build command, ccache errors out with:

ccache: error: Failed to create temporary file for /home/mwalker/.ccache/tmp/time.stdout: Read-only file system

I can see when I build with --verbose_failures --sandbox_debug that we're not mounting the ccache tmp directory r/w.

So, how do I get bazel to mount my ccache directory r/w, or how do I tell ccache through bazel where the correct cache directory for my workspace resides?

When I run the same command on Ubuntu 18.04 it succeeds, so this leads me to believe that ccache is supported in some way.

It looks like part of my problem is that ccache installed its compiler driver as gcc. E.g. which gcc -> /usr/lib64/ccache/gcc. Where on Ubuntu ccache must be explicitly invoked, and the default toolchain is not calling it.

2

There are 2 answers

2
László On
1
GurstTavo On

Had the same problem in Fedora 29, in my case was solved by exporting the next environment variables:

export CC="/usr/bin/gcc"
export CXX="/usr/bin/g++"

https://github.com/bazelbuild/bazel/issues/1322#issuecomment-226919588