Per Project Per User bazelrc

367 views
Skip to first unread message

James Judd

unread,
Aug 7, 2018, 3:12:49 AM8/7/18
to bazel-discuss
Hi everyone,

With https://github.com/bazelbuild/bazel/issues/4502 merged is it still possible to have a per-user, per-project .bazelrc? If not, how do users specify configs that exist in one project, but not every Bazel project they interact with?

I ask because this removal is causing us some issues that I haven't found a good workaround for. We set defaults in our project in tools/bazel.rc around things like strategies, remote caching, etc. Some users prefer use a different set of settings. We have some configs for those users in tools/bazel.rc. They enable those configs using a version control ignored .bazelrc file in the root of their clone.

Unless I'm misunderstanding #4502, it is no longer possible to do this. Users must specify a .bazelrc in their home folder and it will apply to every project they interact with. How is everyone else getting around Bazel settings for one project not being applicable for every Bazel project they interact with?

Best,
James

Dmitry Lomov

unread,
Aug 7, 2018, 3:47:37 AM8/7/18
to ja...@lucidchart.com, Chloe Calvarin, bazel-discuss

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/104fb6cc-a8dc-4ea3-8091-8d0a505395f9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Google Germany GmbH
Erika-Mann-Straße 33, 80636 München, Germany

rodr...@google.com

unread,
Aug 7, 2018, 4:41:02 AM8/7/18
to bazel-discuss
I haven't rolled it out yet, but I described my plan on the issue:

We use both tools/bazel.rc and .bazelrc. My idea is to move it to %workspace%/.bazelrc and add import %workspace%/.bazelrc.user, then tell devs to mv .bazelrc .bazelrc.user before pulling that change.

An alternative would be to run echo "import %workspace%/tools/bazel.rc" >> .bazelrc when you see the warning about tools/bazel.rc not being loaded, but I'd expect people to miss the warning.

Has anyone tried something like this?

Chloé Calvarin

unread,
Aug 7, 2018, 9:43:31 AM8/7/18
to rodr...@google.com, bazel-...@googlegroups.com
Hey James,

I'm not sure I fully understand your use case, but if I understand correctly, the canonical way to do what you describe is to have a user define configs in the home rc file, and then use those configs elsewhere. Otherwise, importing and additional rc file makes sense, as Rodrigo describes. You should also be able to import %workspace%-relative files from your home rc, so that will import a different file depending on your workspace.

Hope that helps,
Chloe

tha...@lucidchart.com

unread,
Aug 7, 2018, 11:31:26 AM8/7/18
to bazel-discuss
On Tuesday, August 7, 2018 at 2:41:02 AM UTC-6, rodr...@google.com wrote:
> I haven't rolled it out yet, but I described my plan on the issue:
>
> We use both tools/bazel.rc and .bazelrc. My idea is to move it to %workspace%/.bazelrc and add import %workspace%/.bazelrc.user, then tell devs to mv .bazelrc .bazelrc.user before pulling that change.
>

Is there a way to conditionally import a file in bazel. That is something that imoprts a file if it exists, but doesn't fail if it doesn't.

Chloé Calvarin

unread,
Aug 7, 2018, 11:38:04 AM8/7/18
to tha...@lucidchart.com, bazel-...@googlegroups.com
https://github.com/bazelbuild/bazel/issues/5765 was filed with just that request

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.

James Judd

unread,
Aug 7, 2018, 1:22:08 PM8/7/18
to bazel-discuss
Hi Chloe,

Let me give an example to describe our use case.

I have two projects: Project A and Project B. Project A has a tools/bazel.rc file with 'build:foo <some option>'. Project B has a tools/bazel.rc with 'build:bar <some option>'. As a user, I prefer to use --config=foo for Project A and --config=bar for Project B. 

Before, I would put 'build --config=foo' in Project A's .bazelrc file and 'build --config=bar' in Project B's .bazelrc file. Things work as expected - when I invoke Bazel in Project A and B it uses the foo and bar configs, respectively.

Now that tools/bazel.rc no longer exists, both 'build:foo <some option> and 'build:bar <some option>' have moved to their project's .bazelrc file. As a I user, I put both 'build --config=foo' and 'build --config=bar' in $HOME/.bazelrc. Things are broken. Every time I invoke Bazel it applies both the foo and bar configs. Because both projects do not have a foo and bar config I get an error. It would look something like this when I run Bazel in Project B.

'ERROR: Config value foo is not defined in any .rc file'

https://github.com/bazelbuild/bazel/issues/5765 will enable a workaround by not failing imports for missing files. Each project can specify a location and name for a .bazelrc.user file. However, it would be nice to have support in Bazel for per user, per project .bazelrc files again.

We tried a few other workaround, but they did not work:
* You can't set --bazelrc in a .bazelrc file.You get this error '[bazel FATAL src/main/cpp/blaze.cc:1282] Can't specify --bazelrc in the .bazelrc file.'
* If you set --bazelrc using tools/bazel, then it doesn't load the project's .bazelrc because >If this option is not present, no additional [bazelrc] file is loaded
* You can't currently import a file in .bazelrc that doesn't exist, which is what 5765 is all about. I don't want to force everyone to create a version control ignored file in their clone. The ergonomics for that are poor.

Best,
James
Reply all
Reply to author
Forward
0 new messages