bazel: cant build with bazel and ccache
Description of the problem / feature request:
Bazel fails to build tcmalloc with message
ccache: error: Failed to create temporary file for /home/user/.ccache/tmp/string_uti.stdout: Read-only file system
Bugs: what’s the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
I guess no special steps needed. ccache works fine, I’m able to build without using sudo with CMake, for example
What operating system are you running Bazel on?
Ubuntu 20.04
What’s the output of bazel info release?
release 3.5.0
Have you found anything relevant by searching the web?
semi-related
https://github.com/bazelbuild/bazel/issues/1540
but I installed the Bazel using apt
Any other information, logs, or outputs that you want to share?
worked as expected once I ran Bazel under sudo, but I guess it is not the expected behavior
let me know if you need any additional information
About this issue
- Original URL
- State: open
- Created 6 years ago
- Comments: 24 (11 by maintainers)
It looks like this is a documentation request at this point, to clarify that users should pass --sandbox_writeable_path to enable ccache with sandboxing. Does that sound right to you?
Discovered this issue building https://github.com/ankitects/anki on my Fedora 36 system. The command I invoked was:
and ccache complains it cannot locate gcc on the path, which is somewhat amusing.
/usr/lib64/ccache/gccdoes in fact exist.The workaround for me was to explicitly define
CC=/usr/bin/gccandCXX=/usr/bin/g++to force Bazel to not use ccache at all as per https://stackoverflow.com/a/53517061. I have tried all the steps indicated in this thread (server shutdown, and even bazel cleans between runs).This feels like surprisingly brittle behaviour.
You can create config file
$HOME/.bazelrcwith the option, https://docs.bazel.build/versions/master/guide.html#bazelrc-syntax-and-semantics.@createyourpersonalaccount I have the same problem now, also on Fedora 36. Trying to build for example this target in bazel itself
I can fix this by making the cache directory accessible from sandbox, by adding the appropriate parameter (as discussed in the previous comments on this issue), covering all the paths that the build desires write access to
(If I did not create .ccache directory beforehand, I’d get IO error about the directory not existing)
in bazel.rc should work. What does not work is using env variables, such as
$HOMEin .bazel.rc. https://github.com/bazelbuild/bazel/issues/10904. And env variables there never worked, as far as I remember.worked too
In that case, what does using the sandbox writable path argument, that is
--sandbox_writable_path=$HOME/.ccachedo?Your reasoning makes sense. I just personally prefer one bold try with
chownover doing much up-front thinking about causes; I prefer to do that afterwards. That’s all. edit: and if you mix running commands with sudo and without, its easy to create temp files owned by root in various places.Sandboxing can be switched off, or you may try less powerfull sandbox, by doing either
--spawn_strategy=standaloneor--spawn_strategy=processwrapper-sandbox. This is what I’d certainly try, besides--sandbox_writable_path=$HOME/.ccacheI previously suggested.Previous instances of similar issues I was able to find were due to sandboxing
edit: in any case, you’ve attached the verbose log. That should be enough information for somebody more knowledgeable about bazel to figure things out. You could maybe add the command you use to run bazel, and how you tell it to use ccache, as further information.
My guess is that bazel sandboxing is blocking access. If that is the case, try building with
--sandbox_writable_path=$HOME/.ccacheYour workaround using
sudosuggests sandboxing may not be to blame, but the option may be worth trying anyways. If file permissions on your file system are to blame, then trysudo chown -R $USER:$USER $HOME/.ccachebefore running bazel. There may be files/directories owned by root user in your .ccache, which then cannot be written into by regular user.