Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make bazel use external storage when building?

Tags:

linux

bazel

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?

like image 394
Matt Kleinsmith Avatar asked Nov 23 '16 23:11

Matt Kleinsmith


People also ask

Where does Bazel build output?

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.

How do I run a Bazel build file?

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.

How does bazel caching work?

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.

What is Bazelrc file?

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.


3 Answers

Use the --output_user_root flag.

Example:

bazel --output_user_root=/path/to/directory build //foo:bar
like image 141
László Avatar answered Oct 10 '22 23:10

László


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.)

like image 45
Matt Kleinsmith Avatar answered Oct 11 '22 00:10

Matt Kleinsmith


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.

like image 38
crizCraig Avatar answered Oct 10 '22 23:10

crizCraig