Bazel:如果配置设置为真,如何排除某些目标

发布于 2025-01-19 17:18:54 字数 760 浏览 1 评论 0原文

假设我在不同的文件夹中有 3 个库:

a_library(
  name = "a",
)
b_library(
  name = "b",
)
c_library(
  name = "c",
)

我想使用 bazel build ... 来构建所有库,而 bazel build ... -c dbg 仅构建>a_library 和 b_library。我想知道我应该改变什么?

我尝试过的:

我尝试遵循 https://bazel.build/docs/configurable-attributes,我为 dbg 进行了配置设置,并在传入 -c dbg 时选择了 tag=['default'],但是显然标签是不可配置的。

我还尝试修改我的 .bazelrc 文件以将标签添加到 c_library。例如: build --build_tag_filters="disable_for_dbg",但我不确定如何让它仅在我通过 -c dbg 时运行

感谢任何帮助,谢谢!

Let's say I have 3 libraries in different folders:

a_library(
  name = "a",
)
b_library(
  name = "b",
)
c_library(
  name = "c",
)

I want to bazel build ... to build all libraries, while bazel build ... -c dbg only builds a_library and b_library. I'm wondering what I should change?

What i've tried:

I tried following https://bazel.build/docs/configurable-attributes, where I made a config setting for dbg and selected tag=['default'] when you passed in -c dbg, but apparently tags aren't configurable.

I've also tried modifying my .bazelrc file to add a tag to c_library. Eg: build --build_tag_filters="disable_for_dbg", but I'm not sure how to get this to only run when I pass -c dbg

Any help is appreciated, thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

书间行客 2025-01-26 17:18:54

不兼容的目标跳过是此类的功能。它将将库排除在通配符之外,任何(传统)取决于它们的任何东西。如果您在命令行(bazel build -c dbg c)上明确列出了其中一个,则会遇到一个错误。像这样:

config_setting(
    name = "debug_build",
    values = {
        "compilation_mode": "dbg",
    },
)

c_library(
    name = "c",
    target_compatible_with = select({
        ":debug_build": ["@platforms//:incompatible"],
        "//conditions:default": [],
    }),
)

@platforms //:Inmbatible不是任何平台的一部分,因此任何具有targe> target_compatible_with包含在内的目标将始终跳过。 target_compatible_with是可配置的,因此您可以通过select有条件地添加该平台约束。

Incompatible target skipping is the feature for this. It'll exclude the libraries from wildcards, and anything which (transitively) depends on them. If you explicitly list one of them on the command line (bazel build -c dbg c), you'll get an error. Like this:

config_setting(
    name = "debug_build",
    values = {
        "compilation_mode": "dbg",
    },
)

c_library(
    name = "c",
    target_compatible_with = select({
        ":debug_build": ["@platforms//:incompatible"],
        "//conditions:default": [],
    }),
)

@platforms//:incompatible is not part of any platform, so any target with target_compatible_with that includes it will always be skipped. target_compatible_with is configurable, so you can add that platform constraint conditionally via select.

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