Matt W
Matt W

Reputation: 121

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

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.

Upvotes: 12

Views: 7513

Answers (2)

GurstTavo
GurstTavo

Reputation: 334

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

Upvotes: 1

László
László

Reputation: 4271

You can add existing directories to the sandbox with --sandbox_writable_path=<path>[1].


[1] https://docs.bazel.build/versions/master/command-line-reference.html

Upvotes: 15

Related Questions