Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 804690

Summary: bazel.eclass: dev-util/bazel builds fail when CCACHE enabled
Product: Gentoo Linux Reporter: Susan Wilson <susanw>
Component: EclassesAssignee: Jason Zaman <perfinion>
Status: UNCONFIRMED ---    
Severity: normal CC: chn, dan, jstein, kfm
Priority: Normal    
Version: unspecified   
Hardware: All   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---

Description Susan Wilson 2021-07-27 23:53:19 UTC
Currently, bazel based ebuilds fail when FEATURES=ccache is enabled due to a sandbox violation.

The issue can be roughly summarized as follows. Bazel clears the environment variable CCACHE_DIR. When CCACHE_DIR is unset, ccache defaults to using "${HOME}/.ccache" as the cache directory. For portage, "${HOME}/.ccache" expands to "/var/lib/portage/home/.ccache".

Therefore, when ccache is enabled, it tries to cache files in "/var/lib/portage/home/.ccache" that results in the sandbox violation. Example of the ebuild that triggers this issue is `tensorflow`. So, the steps to reproduce are:
1. Install and configure ccache.
2. FEATURES=ccache emerge tensorflow

Unfortunately, I am no longer using bazel nor tensorflow, so I cannot provide the exact logs, but I think this bug might be helpful to other users.

This issue can be solved by modifying the `bazel.eclass` eclass and adding the following lines
```
build --action_env CCACHE_DIR
build --host_action_env CCACHE_DIR
```
right below the line containing `build --action_env HOME` of `bazel_setup_bazelrc` function.
Comment 1 Haonan Chen 2022-03-30 09:23:22 UTC
I have found a solution: set `cache_dir` in `/etc/ccache.conf`, like this:

```
cache_dir=/var/cache/ccache
max_size=300G
umask=002
compiler_check=%compiler% -v
compress=false
```

I am not familiar with bazel too and I have tried to pass `CCACHE_DIR` and `-d $CCACHE_DIR` into bazel but all get failed, only this method works.