13

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?

Matt Kleinsmith
  • 1,017
  • 3
  • 13
  • 24

3 Answers3

18

Use the --output_user_root flag.

Example:

bazel --output_user_root=/path/to/directory build //foo:bar
wgumenyuk
  • 420
  • 5
  • 16
László
  • 3,973
  • 1
  • 13
  • 26
  • 1
    When trying this solution on an AWS instance, I met the warning like WARNING: Output base '/workspace/bazel/.cache/0d1ff2dcdcd5fe715305037694b909f9' is on NFS. This may lead to surprising failures and undetermined behavior. – Leo5188 May 28 '19 at 20:16
  • eh, the link now returns 404 page not found :( – Smankusors Aug 04 '20 at 20:44
5

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

Matt Kleinsmith
  • 1,017
  • 3
  • 13
  • 24
2

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.

crizCraig
  • 8,487
  • 6
  • 54
  • 53