Bazel中的CC_PROTO_LIBRARY`实现在哪里?

发布于 2025-02-13 05:41:26 字数 372 浏览 0 评论 0 原文

我读了 bazel 的源代码 > cc_library 在 src/main/starlark/incoreins_bzl/common/common/cc 中。

另外,我在 src/main/starlark/nelidins_bzl/common/proto 中找到了 proto_library 。但是我找不到 cc_proto_library 的实现在哪里。

谁能告诉我它是如何工作的?

I read the source code of bazel, and I found cc_binary and cc_library in src/main/starlark/builtins_bzl/common/cc.

Also I found proto_library in src/main/starlark/builtins_bzl/common/proto. But I can't find where is the cc_proto_library's implementation.

Can anyone tell me how it works?

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

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

发布评论

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

评论(1

傲鸠 2025-02-20 05:41:26

提示:在

您可以使用查询快速找到任何内置规则的实现:

language:java "implements RuleDefinition" "\"cc_proto_library\")"

这将使您带入 ccprotolibraryrule.java 定义:

public class CcProtoLibraryRule implements RuleDefinition {

  private final CcProtoAspect ccProtoAspect;

  public CcProtoLibraryRule(CcProtoAspect ccProtoAspect) {
    this.ccProtoAspect = ccProtoAspect;
  }

  @Override
  public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment environment) {
    return builder
        .requiresConfigurationFragments(CppConfiguration.class)
        /* <!-- #BLAZE_RULE(cc_proto_library).ATTRIBUTE(deps) -->
        The list of <a href="protocol-buffer.html#proto_library"><code>proto_library</code></a>
        rules to generate C++ code for.
        <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
        .override(
            attr("deps", LABEL_LIST)
                .allowedRuleClasses("proto_library")
                .allowedFileTypes()
                .aspect(ccProtoAspect))
        .build();
  }

  @Override
  public Metadata getMetadata() {
    return RuleDefinition.Metadata.builder()
        .name("cc_proto_library")
        .factoryClass(CcProtoLibrary.class)
        .ancestors(BaseRuleClasses.NativeActionCreatingRule.class)
        .build();
  }
}

实现是用 .factoryClass(ccprotolibrary.class)

对于您问题的第二部分,“内置”是Bazel内部概念,可以透明地将Java实现Bazel规则换成其starlark等效,而无需在构建中添加任何 load> load 语句文件。这对于将现有用户迁移到恒星实现而不会引起用户影响是必要的。

Tip: use the Bazel codesearch at https://source.bazel.build to navigate its source code.

You can quickly find the implementation of any built-in rule using a query like:

language:java "implements RuleDefinition" "\"cc_proto_library\")"

This will bring you to the CcProtoLibraryRule.java definition:

public class CcProtoLibraryRule implements RuleDefinition {

  private final CcProtoAspect ccProtoAspect;

  public CcProtoLibraryRule(CcProtoAspect ccProtoAspect) {
    this.ccProtoAspect = ccProtoAspect;
  }

  @Override
  public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment environment) {
    return builder
        .requiresConfigurationFragments(CppConfiguration.class)
        /* <!-- #BLAZE_RULE(cc_proto_library).ATTRIBUTE(deps) -->
        The list of <a href="protocol-buffer.html#proto_library"><code>proto_library</code></a>
        rules to generate C++ code for.
        <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
        .override(
            attr("deps", LABEL_LIST)
                .allowedRuleClasses("proto_library")
                .allowedFileTypes()
                .aspect(ccProtoAspect))
        .build();
  }

  @Override
  public Metadata getMetadata() {
    return RuleDefinition.Metadata.builder()
        .name("cc_proto_library")
        .factoryClass(CcProtoLibrary.class)
        .ancestors(BaseRuleClasses.NativeActionCreatingRule.class)
        .build();
  }
}

The implementation is defined with .factoryClass(CcProtoLibrary.class).

For the second part of your question, "builtins" are a Bazel-internal concept to transparently swap out the Java implementation of a Bazel rule to its Starlark equivalent, without needing to add any load statements in the BUILD file. This is necessary to migrate existing users to Starlark implementations without causing user impact.

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