Skip to content

Conversation

@aaronsky
Copy link
Contributor

Fixes #25260

Implements the request made here and moves the default output root on macOS from /private/var/tmp to $HOME/Library/Caches. May constitute an incompatible change, though on a cursory glance I didn't see any precedent for incompatible startup options in source.

@aaronsky aaronsky marked this pull request as ready for review February 12, 2025 10:33
@github-actions github-actions bot added team-Rules-CPP Issues for C++ rules awaiting-review PR is awaiting review from an assigned reviewer labels Feb 12, 2025
@aaronsky aaronsky requested a review from tetromino February 15, 2025 13:57
@tetromino tetromino added team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website team-CLI Console UI and removed team-Rules-CPP Issues for C++ rules labels Feb 18, 2025
@tetromino tetromino requested a review from meisterT February 18, 2025 17:53
@tetromino
Copy link
Contributor

This is an incompatible change, but arguably one that doesn't need to be gated by a flag. We do need to make sure that

  • the change is described in bazel 9 release notes
  • it doesn't get cherry-picked into 8.x point releases

An additional question is what to do about the documentation at https://bazel.build/remote/output-directories - I assume many bazel 8 users will check that page (even though it's for bazel-at-head). So maybe we need phrasing along the lines of "this is how things work in bazel 9, and that is how they used to work in bazel 8 and earlier".

@tetromino

This comment was marked as resolved.

@tetromino
Copy link
Contributor

Did some code searching.

Needs to be fixed:

Already fixed:

  • DarwinSandboxedSpawnRunner.java already marks ~/Library/Caches as always-writable

Copy link
Contributor

@tetromino tetromino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also update output-directories.md.

I'd suggest something like the following wording:

  • The outputRoot directory defaults to ~/.cache/bazel on Linux,
    ~/Library/Caches/bazel on macOS (when using Bazel 9 and newer), and on Windows it defaults to %HOME% if
    set, else %USERPROFILE% if set, else the result of calling
    SHGetKnownFolderPath() with the FOLDERID_Profile flag set. If the
    environment variable $XDG_CACHE_HOME is set on either Linux or
    macOS, the value ${XDG_CACHE_HOME}/bazel will override the default.
    If the environment variable $TEST_TMPDIR is set, as in a test of Bazel
    itself, then that value overrides any defaults.
    • Note that Bazel 8.x and earlier on macOS used /private/var/tmp as outputRoot, and ignored $XDG_CACHE_HOME.

@aaronsky
Copy link
Contributor Author

Thanks for the feedback @tetromino! I've addressed it in the latest commit. I'm happy to continue working with you to iterate on this as needed. I don't know if I'm the best person to work on those other identified points, since some of them are internal to Google and others seem to require some inter-repo coordination, but let me know what you want from me!

@aaronsky aaronsky requested a review from tetromino March 2, 2025 14:06
@meteorcloudy
Copy link
Member

@tetromino Can you take another look?

@aaronsky
Copy link
Contributor Author

@tetromino would you mind taking another look at this?

@aaronsky
Copy link
Contributor Author

@tetromino bumping this. would you mind taking another look at this PR?

@tetromino
Copy link
Contributor

I got feedback from Bazel users at Google asking to move the default output root to /tmp (a.k.a. /private/tmp) instead. On macOS, /tmp gets wiped on reboot by default, which keeps keeps the amount of disk space used by Bazel in check.

Apparently, running out of disk space due to Bazel is a problem that many engineers experienced - one user reported >200 GB in their output root at one point.

In light of this, I'd like to defer this PR review and first discuss what we want to do with the output root in #25260

@tetromino
Copy link
Contributor

Quoting @ashgti from internal bug report:


Some notes on folders macOS uses:

Path Permissions Cleanup
/tmp +777 reboot
/var/tmp +777 never
/Library/Caches +777 never
~/Library/Caches +700 never
getconf DARWIN_USER_CACHE_DIR 1 (like /var/folders/_0/_vrx1th904x4bsf1c0_w4bhw00g80m/C/) +700 reboot
$TEMPDIR (getconf DARWIN_USER_TEMP_DIR) 1 (like /var/folders/_0/_vrx1th904x4bsf1c0_w4bhw00g80m/T/) +700 reboot and periodic mtime >3 days

End of quote.

Since /var/tmp and ~/Library/Caches have the same cleanup behavior, the only problem with moving from one to the other is needing to adjust various scripts for CI etc.

The fix for @nglevin's issue might be to launch bazel with --user_cache_dir=$(getconf DARWIN_USER_TEMP_DIR) in google's internal launcher script - but we need to investigate whether there's a risk of the dirhelper demon deleting bazel's cache files while bazel is running.

Footnotes

  1. See man confstr on macOS or https://github.com/apple-oss-distributions/Libc/blob/af11da5ca9d527ea2f48bb7efbd0f0f2a4ea4812/gen/confstr.3 2

Copy link
Contributor

@tetromino tetromino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After thinking about this for a while, I think it's ok.

If we get complaints, we'll roll it back.

The solution for the running-out-of-space problem might be to set --user_cache_dir=$(getconf DARWIN_USER_TEMP_DIR) in the script that launches Bazel.

@aaronsky aaronsky requested a review from a team November 11, 2025 11:53
@tjgq tjgq added awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally and removed awaiting-review PR is awaiting review from an assigned reviewer labels Nov 11, 2025
@copybara-service copybara-service bot closed this in 13da9a1 Dec 5, 2025
@github-actions github-actions bot removed the awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally label Dec 5, 2025
bazel-io pushed a commit to bazel-io/bazel that referenced this pull request Dec 5, 2025
Fixes bazelbuild#25260

Implements the request made [here](bazelbuild#25205 (comment)) and moves the default output root on macOS from `/private/var/tmp` to `$HOME/Library/Caches`. May constitute an incompatible change, though on a cursory glance I didn't see any precedent for incompatible startup options in source.

Closes bazelbuild#25262.

PiperOrigin-RevId: 840604399
Change-Id: I391b805b2c8e99d3ffe44a76e916d1c9839225e5
github-merge-queue bot pushed a commit that referenced this pull request Dec 5, 2025
…27875)

Fixes #25260

Implements the request made
[here](#25205 (comment))
and moves the default output root on macOS from `/private/var/tmp` to
`$HOME/Library/Caches`. May constitute an incompatible change, though on
a cursory glance I didn't see any precedent for incompatible startup
options in source.

Closes #25262.

PiperOrigin-RevId: 840604399
Change-Id: I391b805b2c8e99d3ffe44a76e916d1c9839225e5

Commit
13da9a1

Co-authored-by: Aaron Sky <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team-CLI Console UI team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move default output root on macOS to $HOME/Library/Caches

4 participants