Dealing with many versions of bazel

1,480 views
Skip to first unread message

David Sofo

unread,
Mar 14, 2017, 4:52:36 AM3/14/17
to bazel-discuss

Hi,

I use bazel for different tools. Each tool needs sometimes specific versions of bazel. So what I am doing now for a given tool is to remove my current version of bazel installed on the machine and install the required version for the new tool. Can I can multiple versions on the machine so that when I need a specific version I have only to switch. Or is there a simpler way to solve my problem. I am new to bazel. Thank you.

Regards
David

Damien Martin-Guillerez

unread,
Mar 14, 2017, 4:54:33 AM3/14/17
to David Sofo, bazel-discuss
Hi David,

The installed wrapper script is trying to find out bazel at tools/bazel by default in your workspace and fallback on the one installed on the system. You could use that either to check in the version of bazel you want or to call the good Bazel binary on your machine.

--
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/a48abd53-500a-4249-9122-ecab4c7801af%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David Sofo

unread,
Mar 14, 2017, 5:32:55 AM3/14/17
to bazel-discuss, sofod...@gmail.com
Hi Damien,

Thank your for reply. I have looked at the file tool/bazel.rc at the workspace. The file ends with:


build --spawn_strategy=standalone --genrule_strategy=standalone
test --spawn_strategy=standalone --genrule_strategy=standalone
run --spawn_strategy=standalone --genrule_strategy=standalone

I didn't figure out how to call  here a specific binary of bazel. Should I add a command in this file? Thanks.

Regards
David

Damien Martin-Guillerez

unread,
Mar 14, 2017, 5:37:56 AM3/14/17
to David Sofo, bazel-discuss
Sorry David,

My explanation were not clear, the installed binary by bazel when you run "bazel" is actually a wrapper script (https://github.com/bazelbuild/bazel/blob/master/scripts/packages/bazel.sh) that looks for bazel at `tools/bazel` (not .rc) if present then fall back on the actual bazel binary.

You can either check in the version of Bazel you want to use in that script or add another redirection layer there that calls out the good bazel binary version. With that you will always type "bazel" but calls different version of bazel.

Klaus Aehlig

unread,
Mar 14, 2017, 5:43:39 AM3/14/17
to David Sofo, bazel-discuss
the bazel binary itself not not insist on having a specific name. So
you can install the various binaries under different names somewhere
in the search path and then call whatever you need of 'bazel044 build
...', 'bazel045rc6 build ...' etc. That's what I do. If you want a
central point to switch, install the various versions into separate
directories and change the PATH environment variable as needed.

In both those ways, the switching is local to your machine and you do
not have to touch the source code.

Regards,
Klaus

--
Klaus Aehlig
Google Germany GmbH, Erika-Mann-Str. 33, 80636 Muenchen
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschaeftsfuehrer: Matthew Scott Sucherman, Paul Terence Manicle

David Sofo

unread,
Mar 14, 2017, 8:03:28 AM3/14/17
to bazel-discuss, sofod...@gmail.com
Hi @Klaus, @Damien,

As Klaus suggested I end up by rename bazel binaries and set variables environment for them. This is easy for me. Thank you to all of you.

Regards
David

Ian O'Connell

unread,
Mar 14, 2017, 11:07:56 AM3/14/17
to David Sofo, bazel-discuss
I hacked together a script we use at some point that might be useful here:


You have to set the Bazel version you want + sha1 of that package in your WORKSPACE and add a default_bazel_rc under tools (bazel doesn't stack bazelrc's usually so we do it in the script).

Our usual path is to check this in at the root of a repo, then add a symlink under tools/bazel back to that bazel.

Users are told to use ./bazel rather than install a system bazel. (Though any bazel > 0.3 will pickup the tools/bazel, some folks can have lingering old ones). On first usage of a version for a user it'll build that copy and stick them under ~/.bazel

With that all users of a repo will use the same bazel version (makes upgrades much cleaner), and you can have any number of bazel versions in flight. Works on OS X and Linux at least pretty seamlessly. 

--
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-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/df6e4c22-61d1-4d2f-8ea9-bb160a88ea61%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages