Matt Kleinsmith
Matt Kleinsmith

Reputation: 1139

How can I make bazel use external storage when building?

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?

Upvotes: 15

Views: 13519

Answers (3)

crizCraig
crizCraig

Reputation: 8897

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.

Upvotes: 5

László
László

Reputation: 4271

Use the --output_user_root flag.

Example:

bazel --output_user_root=/path/to/directory build //foo:bar

Upvotes: 21

Matt Kleinsmith
Matt Kleinsmith

Reputation: 1139

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

Upvotes: 6

Related Questions