Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

bazel

ccache

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.

like image 715
Matthew Walker Avatar asked Sep 17 '18 14:09

Matthew Walker


2 Answers

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

like image 85
László Avatar answered Nov 05 '22 16:11

László


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

like image 20
GurstTavo Avatar answered Nov 05 '22 17:11

GurstTavo