如何为Bazel的不同操作系统指定便携式构建配置?

发布于 2025-01-24 12:27:59 字数 250 浏览 2 评论 0原文

我在这里发布了这个问题,因为我已经找不到具体答案。通过建议另一个用户的建议,我在另一篇文章中移动答案,该帖子专门回答此处,以使其更清楚其答案。

内容:我的应用程序的部署是在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

十二 2025-01-31 12:27:59

.bazelrc文件可以用于提供用于指定特定于操作系统和构建目标的构建配置的集中式源。

.bazelrc文件中,构建的规范按遵循:[name]允许您在同一行上指定以下任何构建选项。这个名字可以是任何东西。就我而言,我指定了与操作系统相对应的编译器。

考虑以下内容:

#In the .bazelrc file
build:msvc --cxxopt='-std:c++latest' -c opt

-cxxopt =是Bazel的标志,要指定构建选项。 -c是使用Google预先设置的一组标志的标志,在这种情况下,opt是最佳的速度。所有这些都可以在文档中找到。

现在,要使用相同的标志进行测试而不会引起完整的重建,请使用以下内容:

test:msvc -c opt --test_output=all

在这方面有细微差别,因为Bazel不喜欢第二次指定标志时,即使它是同一标志。我不能完全记住我在-c opt之上自定义的实验,因此您必须测试订购是否对自己很重要。我不认为这样做。

结合在一起,看起来如下:

build:msvc --cxxopt='-std:c++latest' -c opt
test:msvc -c opt --test_output=all

在命令行,您将做以下选择之一:

bazel build --config=[name] //...

使用上述名称:

bazel build --config=msvc //...

并测试用“ test”来交换“ build”一词:

bazel test --config=msvc //...

来自 “ test”:我自己的项目:

# To build|test Windows: bazel build|test --config=msvc
# To build|test Linux: bazel build|test --config=gcc
build:msvc --cxxopt='-std:c++latest' -c opt
test:msvc -c opt --test_output=all

build:gcc --cxxopt='-std=c++2a' -c opt
test:gcc -c opt --test_output=all

build:gccProfile --cxxopt='-std=c++2a' --cxxopt='-fno-omit-frame-pointer' -c dbg

注意GCCMSVC规格之间的细微差异。指定的标志是特定于所使用的编译器的特定的,而不是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 of build 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:

#In the .bazelrc file
build:msvc --cxxopt='-std:c++latest' -c opt

--cxxopt= is Bazel's flag to specify build options. -c is the flag to utilize a set of flags pre-set by Google with opt 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:

test:msvc -c opt --test_output=all

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:

build:msvc --cxxopt='-std:c++latest' -c opt
test:msvc -c opt --test_output=all

On the command line, you would do the following to choose one of the options:

bazel build --config=[name] //...

with the names used above:

bazel build --config=msvc //...

and to test swap out the word "build" with "test":

bazel test --config=msvc //...

A snippet from my own own project:

# To build|test Windows: bazel build|test --config=msvc
# To build|test Linux: bazel build|test --config=gcc
build:msvc --cxxopt='-std:c++latest' -c opt
test:msvc -c opt --test_output=all

build:gcc --cxxopt='-std=c++2a' -c opt
test:gcc -c opt --test_output=all

build:gccProfile --cxxopt='-std=c++2a' --cxxopt='-fno-omit-frame-pointer' -c dbg

Notice the subtle differences between the gcc and msvc 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 with clang 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文