如何为Bazel的不同操作系统指定便携式构建配置?
我在这里发布了这个问题,因为我已经找不到具体答案。通过建议另一个用户的建议,我在另一篇文章中移动答案,该帖子专门回答此处,以使其更清楚其答案。
内容:我的应用程序的部署是在Linux和Windows上。构建结果和整体特征(即优先考虑速度与内存,警告等)应在操作系统和存储库的用户之间是标准配置。
原因:开发人员应专注于开发,而不是调整构建配置或在大多数情况下对其进行战斗。在不同系统上构建的功能应该与指定单个标志或自动(优选),集中式和标准化的能力一样简单。
I am posting this question here because I could not find the specific answer already. By suggestion of another user, I am moving my answer in another post that answers this specifically to here to make it more clear as to what it answers.
What: The deployment of my application is on Linux and Windows. Build results and overall characteristics (i.e. prioritizing speed vs. memory, warnings, etc.) should be standard across operating systems and users of the repository.
Why: A developer should be focused on development, not tweaking build configurations or fighting it to work in the majority of cases. The capability to build on different systems should be as simple as specifying a single flag or automatic (preferably), centralized, and standardized for the entire repository.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
.bazelrc
文件可以用于提供用于指定特定于操作系统和构建目标的构建配置的集中式源。在
.bazelrc
文件中,构建
的规范按遵循
:[name]
允许您在同一行上指定以下任何构建选项。这个名字可以是任何东西。就我而言,我指定了与操作系统相对应的编译器。考虑以下内容:
-cxxopt =
是Bazel的标志,要指定构建选项。-c
是使用Google预先设置的一组标志的标志,在这种情况下,opt
是最佳的速度。所有这些都可以在文档中找到。现在,要使用相同的标志进行测试而不会引起完整的重建,请使用以下内容:
在这方面有细微差别,因为Bazel不喜欢第二次指定标志时,即使它是同一标志。我不能完全记住我在
-c opt
之上自定义的实验,因此您必须测试订购是否对自己很重要。我不认为这样做。结合在一起,看起来如下:
在命令行,您将做以下选择之一:
使用上述名称:
并测试用“ test”来交换“ build”一词:
来自 “ test”:我自己的项目:
注意
GCC
和MSVC
规格之间的细微差异。指定的标志是特定于所使用的编译器的特定的,而不是Bazel的通用规格。另外,巴泽尔(Bazel)拉动了它在操作系统上找到的第一个编译器。我尝试了在同一台操作机上使用clang
构建的一些实验,但是它需要大量其他规格,等等才能使其正常工作。GCC
是我安装并由Bazel使用的第一个编译器,它将其保留为默认编译器。The
.bazelrc
file can be utilized to offer a centralized source for specifying build configurations specific to operating system and build objectives.In the
.bazelrc
file, the specification ofbuild
follow by:[name]
allows you to specify any build options following thereafter on the same line. The name can be anything. In my case, I specified the compiler used that corresponds to the operating system.Consider the following:
--cxxopt=
is Bazel's flag to specify build options.-c
is the flag to utilize a set of flags pre-set by Google withopt
being optimal for speed in this case. All of this can be found in the documentation.Now to use the same flags for testing without causing a complete rebuild, use the following:
There are nuances in this regard because Bazel does not like when flags are specified for a second time, even if it is the same flag. I cannot entirely remember my experiments with customizing on top of the
-c opt
, so you will have to test if ordering matters for yourself. I do not think it does though.Combined, it will look like the following:
On the command line, you would do the following to choose one of the options:
with the names used above:
and to test swap out the word "build" with "test":
A snippet from my own own project:
Notice the subtle differences between the
gcc
andmsvc
specifications. The flags specified are specific to the compiler used, not generic specifications by Bazel. Also, Bazel pulls the first compiler it finds on your operating system. I tried some experiments of building withclang
on the same operating machine, but it requires a whole host of other specifications and so forth to make it work.gcc
was the first compiler installed by me and used by Bazel, and it kept it as the default compiler.