-->

Default, platform specific, Bazel flags in bazel.r

2019-08-19 04:38发布

问题:

I was wondering if its possible for platform-specific default Bazel build flags.

For example, we want to use --workspace_status_command but this must be a shell script on Linux and must point towards a batch script for Windows.

Is there a way we can write in the tools/bazel.rc file something like...

if platform=WINDOWS build: --workspace_status_command=status_command.bat if platform=LINUX build: --workspace_status_command=status_command.sh

We could generate a .bazelrc file by having the users run a script before building, but it would be cleaner/nicer if this was not neccessary.

Thanks

回答1:

Yes, kind of. You can specify config-specific bazelrc entries, which you can select by passing --config=<configname>.

For example your bazelrc could look like:

build:linux --cpu=k8
build:linux --workspace_status_command=/path/to/command.sh
build:windows --cpu=x64_windows
build:windows --workspace_status_command=c:/path/to/command.bat

And you'd build like so:

bazel build --config=linux //path/to:target

or:

bazel build --config=windows //path/to:target

You have to be careful not to mix semantically conflicting --config flags (Bazel doesn't prevent you from that). Though it will work, the results may be unpredictable when the configs tinker with the same flags.



回答2:

Passing --config to all commands is tricky, it depends on developers remembering to do this, or controlling the places where Bazel is called.

I think a better answer would be to teach the version control system how to produce the values, like by putting a git-bazel-stamp script on the $PATH/%PATH% so that git bazel-stamp works.

Then we need workspace_status_command to allow commands from the PATH rather than a path on disk.



标签: bazel