When building certain code with bazel I'm running out of storage space. I'd like bazel to store its things on a USB drive instead of in my ~/.cache
folder. How can I tell bazel to do this?
The Bazel user's build state is located beneath outputRoot/_bazel_$USER . This is called the outputUserRoot directory. Beneath the outputUserRoot directory there is an install directory, and in it is an installBase directory whose name is the MD5 hash of the Bazel installation manifest.
To run Bazel, go to your base workspace directory or any of its subdirectories and type bazel . % bazel help [Bazel release bazel-<version>] Usage: bazel <command> <options> ... Available commands: analyze-profile Analyzes build profile data. aquery Executes a query on the post-analysis action graph.
Bazel checks your local machine for existing build outputs and reuses any that it finds. Bazel checks the cache for existing build outputs. If the output is found, Bazel retrieves the output. This is a cache hit.
Bazel builds software from source code organized in a directory called a workspace. Source files in the workspace are organized in a nested hierarchy of packages, where each package is a directory that contains a set of related source files and one BUILD file.
Use the --output_user_root
flag.
Example:
bazel --output_user_root=/path/to/directory build //foo:bar
You can change the outputRoot directory by changing the $TEST_TMPDIR
variable.
export TEST_TMPDIR=/path/to/directory
From the bazel docs:
The outputRoot directory is
~/.cache/bazel
. (Unless $TEST_TMPDIR is set, as in a test of bazel itself, in which case this directory is used instead.)
I symlinked ~/.cache/bazel
to a directory on my other drive. Looks to be working so far. i.e.
ln -s /mnt/otherdrive/bazel_cache ~/.cache/bazel
I thought to move the old cache to avoid rebuilding, but I noticed symlinks to directories within the cache and didn't want to deal with transferring those so they pointed to the new directory as well. So I just deleted the old cache, symlinked, and rebuilt.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With