Skip to content

Change where bazelrcs are read from, and make it easier to control which ones are read. #4502

Closed

Description

@drigz

Description of the feature request:

Check for bazel/bazel.rc in addition to tools/bazel.rc. This could also be done for tools/bazel and any other special files that can be in tools/.

Feature requests: what underlying problem are you trying to solve with this feature?

Projects that support multiple build systems prefer to keep the files separated as far as possible. However, Bazel forces you to add a tools/ top-level directory to use certain functionality. See this comment from cartographer-project/cartographer#834 which prompted this issue.

The bazel/ subdirectory is fairly common for builds that support multiple systems, eg gRPC, glog, Google Cartographer, Ceres Solver. Exceptions (ie projects with no bazel/ subdir) include TensorFlow and gRPC Java, although IMHO the latter is good example of where it would help clean things up.

What operating system are you running Bazel on?

Ubuntu 14.04

What's the output of bazel info release?

release 0.9.0

Activity

  1. added
    P2
    on Jan 23, 2018
  2. self-assigned this
    on Jan 23, 2018
  3. ixdy commented on Jan 23, 2018

    @ixdy
    Contributor

    Kubernetes is another project which would benefit from something like this. We currently have a .bazelrc in the repo root, which is overriding users' $HOME/.bazelrc, so we should fix this.

    We don't have a tools/ directory (though we do have a build/), and I'm not super excited about creating tools/ solely for one file.

  4. added
    P1
    and removed
    P2
    on Jan 24, 2018
  5. helenalt commented on Jan 24, 2018

    @helenalt
    Contributor

    @jhfield @lberki please help prioritize an owner as this affects multiple users

  6. assigned and unassigned on Jan 25, 2018
  7. lberki commented on Jan 25, 2018

    @lberki
    Contributor

    (assigning to @cvcal since she worked with option parsing more recently than both @lfpino and @iirina)

    I think this is a good idea; tools/bazel.rc is mostly a heritage from our internal repository. I think using $WORKSPACE/bazel.rc is more reasonable than tools. I'm not thrilled about $WORKSPACE/bazel/bazel.rc, though -- why create a directory just for one file?

    Migration will also need to be given some thought; we could either just change in a Bazel release since projects can simply symlink one location to the other to support building with Bazels both before and after the flag flip or have a release that supports both, then remove the old location in the subsequent release. I think the first plan is simpler and the migration costs are not too onerous.

    WDY'allT?

  8. iirina commented on Jan 25, 2018

    @iirina
    Contributor

    I'm not thrilled about $WORKSPACE/bazel/bazel.rc, though -- why create a directory just for one file?

    Seems like the reasoning is that a lot of projects already have the bazel directory.

    Is it possible to specify in the WORKSPACE file the location of the bazel.rc file? So that every project could put bazel.rc wherever they want.

  9. lberki commented on Jan 25, 2018

    @lberki
    Contributor

    Specifying it in the WORKSPACE file doesn't work; the rcfile is parsed from the launcher, which doesn't speak Skylark.

  10. drigz commented on Jan 25, 2018

    @drigz
    ContributorAuthor

    I'm not thrilled about $WORKSPACE/bazel/bazel.rc, though -- why create a directory just for one file?

    Seems like the reasoning is that a lot of projects already have the bazel directory.

    Yes, and specifically that bazel/ is desirable name for projects that support other build systems. Also, $WORKSPACE/bazel.rc and $WORKSPACE/.bazelrc would be (even more) easily confused.

  11. cvcal commented on Jan 25, 2018

    @cvcal
    Contributor

    I actually was just talking to Luis and Klaus about this (context b/70843852 & b/36168162, for Bazel team members).
    Bazel currently loads 3 master bazelrcs, or none, if --nomaster_bazelrc is passed. I find this horrible, there is no way for users to pick which of these files should be loaded, no way for one of these to be ignored while others kept. I'd rather we not add a 4th location from which we look for a master rc without improving this with a more granular switch.

    On the question of which files should be in that list, Klaus had written a proposal for what the bazelrc world should look like a few years ago, hidden in https://www.bazel.build/designs/2016/06/21/environment.html. It doesn't contain exactly this suggestion, but might be a good starting point. I think it would be great if we can work something that is similar to the standards in other open source projects, but I don't know much about those standards so I can't speak to the WORKSPACE/bazel directory in particular.

  12. 76 remaining items

  13. cvcal commented on Sep 20, 2018

    @cvcal
    Contributor

    Yes, --ignore_all_rc_files will do what it says for any Bazel where it exists. There weren't any release notes because this flag was mostly intended as an internal tool - it ignores everything, regardless of the other flags, so --ignore_all_rc_files --master_bazelrc (in bazel 17 or earlier) or --ignore_all_rc_files --home_rc <etc> (in bazel 18 or later) does not read any file, last flag does not win, in this case. These semantics are intentional, but not very user-friendly; this flag was mostly intended to allow different versions of Bazel (including google's Blaze) to have a single no-rc configuration, which is useful for tests.

  14. ittaiz commented on Sep 20, 2018

    @ittaiz
    Member

    ended up bumping to 0.15.2 as minimal version and using ignore_all_rc_files

  15. cvcal commented on Sep 20, 2018

    @cvcal
    Contributor

    15 is the first version with the flag? That sounds right

  16. ittaiz commented on Sep 20, 2018

    @ittaiz
    Member
  17. ensonic commented on Oct 11, 2018

    @ensonic
    Contributor

    Using `$HOME/.bazelrc' will clutter the home-dir. Shouldn't this be $HOME/.config/.bazelrc ? Is this supported? For details check out https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
    $HOME/.config is the fallback fro $XDG_CONFIG_HOME. This inderection lets the user/admin decide where to have configuration files (important for backups too).

  18. cvcal commented on Oct 11, 2018

    @cvcal
    Contributor

    This is not supported - we need a place that can make sense in different platforms and setups, and I'm not sure that .config is a standard location. If you care about backups in .config/, you should be able to create a thin bazelrc in HOME that imports the one in .config, which gets backed up, but that doesn't solve the clutter issue.

  19. ensonic commented on Oct 11, 2018

    @ensonic
    Contributor

    He seriously, you are compliant with the basedir spec for other files. Eg the cached resource are under ~/.cache/bazel/bazel_$USER/. The standard I pointed to is a quite established solution.
    If you are looking for a java-impl: https://github.com/omajid/xdg-java

  20. cvcal commented on Oct 11, 2018

    @cvcal
    Contributor

    If it really is the standard as you say, then I don't know why it didn't come up earlier in the discussion about this change, we looked for standard config file locations earlier in this thread (see #4502 (comment)). Maybe we were wrong, but no one pointed it out, and so we stuck with the file location that a number of our users were already used to using.

    I don't believe there's much appetite to change this list a second time, makes the release break a lot of people.

  21. perfinion commented on Oct 12, 2018

    @perfinion

    I definitely agree with no more changes to the list at this point. Also basically everything I've seen that supports ~/.config/foorc also reads ~/.foorc. So lets get this change out the door as-is then in a later release we can revisit adding ~/.config/bazel/config to the list not removing ~/.bazelrc.

  22. gibfahn commented on Sep 12, 2019

    @gibfahn
    Contributor

    If it really is the standard as you say, then I don't know why it didn't come up earlier in the discussion about this change, we looked for standard config file locations earlier in this thread (see #4502 (comment)). Maybe we were wrong, but no one pointed it out, and so we stuck with the file location that a number of our users were already used to using.

    FWIW the above tools mostly allow the user's bazel config to easily be moved to $XDG_CONFIG_HOME (~/.config) by reading an env var that can be set to point to the relevant directory.

    # Cargo, mixes data and global config
    export CARGO_HOME="$XDG_DATA_HOME/cargo"
    # Npm allows customising
    export npm_config_userconfig="$XDG_CONFIG_HOME/npm/config"
    # Gradle puts the cache and config together.
    export GRADLE_USER_HOME="$XDG_CACHE_HOME/gradle"
    
    # Pip supports $XDG_CONFIG_HOME by default: ~/.config/pip/pip.conf
    
    # maven and gem can't use the XDG spec.

    Lots of other tools like git also have support for this, see the Arch Wiki Page for a list.

    I don't believe there's much appetite to change this list a second time, makes the release break a lot of people.

    That's reasonable, but is there a way to change this in a semver-minor fashion?

    Ideally by adding a couple of options at the top of the per-user list, e.g.

    • $XDG_CONFIG_HOME/bazelrc
    • ~/.config/bazelrc
    • ~/.bazelrc

    Alternatively by keeping the current defaults but also reading an env var, allowing users to do export BAZEL_CONFIG=${XDG_CONFIG_HOME:-~/.config}/bazelrc.

    Right now the best workaround I've found for this is alias bazel="bazel --bazelrc $XDG_CONFIG_HOME/bazel/bazelrc", but that doesn't always work.

  23. added a commit that references this issue on May 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1category: misc > misctype: feature request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions