Default, platform specific, Bazel flags in bazel.rc

…衆ロ難τιáo~ 提交于 2019-12-11 14:16:51

问题


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.



来源:https://stackoverflow.com/questions/48159516/default-platform-specific-bazel-flags-in-bazel-rc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!