Default, platform specific, Bazel flags in bazel.r

2019-08-19 04:41发布

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

标签: bazel
2条回答
时光不老,我们不散
2楼-- · 2019-08-19 04:41

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.

查看更多
家丑人穷心不美
3楼-- · 2019-08-19 04:56

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.

查看更多
登录 后发表回答