• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Protocol Buffers - Google's data interchange format
2# Copyright 2024 Google Inc.  All rights reserved.
3#
4# Use of this source code is governed by a BSD-style
5# license that can be found in the LICENSE file or at
6# https://developers.google.com/open-source/licenses/bsd
7#
8"""A Starlark implementation of the proto_toolchain rule."""
9
10load("//bazel/common:proto_common.bzl", "proto_common")
11load("//bazel/common:proto_lang_toolchain_info.bzl", "ProtoLangToolchainInfo")
12load("//bazel/private:toolchain_helpers.bzl", "toolchains")
13
14def _impl(ctx):
15    return [
16        DefaultInfo(
17            files = depset(),
18            runfiles = ctx.runfiles(),
19        ),
20        platform_common.ToolchainInfo(
21            proto = ProtoLangToolchainInfo(
22                out_replacement_format_flag = ctx.attr.command_line,
23                output_files = ctx.attr.output_files,
24                plugin = None,
25                runtime = None,
26                proto_compiler = ctx.attr.proto_compiler.files_to_run,
27                protoc_opts = ctx.fragments.proto.experimental_protoc_opts,
28                progress_message = ctx.attr.progress_message,
29                mnemonic = ctx.attr.mnemonic,
30                **(dict(toolchain_type = toolchains.PROTO_TOOLCHAIN) if proto_common.INCOMPATIBLE_PASS_TOOLCHAIN_TYPE else {})
31            ),
32        ),
33    ]
34
35proto_toolchain = rule(
36    _impl,
37    attrs =
38        {
39            "progress_message": attr.string(default = "Generating Descriptor Set proto_library %{label}"),
40            "mnemonic": attr.string(default = "GenProtoDescriptorSet"),
41            "command_line": attr.string(default = "--descriptor_set_out=%s"),
42            "output_files": attr.string(values = ["single", "multiple", "legacy"], default = "single"),
43            "proto_compiler": attr.label(
44                cfg = "exec",
45                executable = True,
46                allow_files = True,  # Used by mocks in tests. Consider fixing tests and removing it.
47            ),
48        },
49    provides = [platform_common.ToolchainInfo],
50    fragments = ["proto"],
51)
52